mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
test specs clear
This commit is contained in:
parent
d2a43cecd7
commit
388331f5ae
@ -65,69 +65,6 @@ beforeEach(async () => {
|
||||
await cleanDatabase()
|
||||
})
|
||||
|
||||
describe('Delete a User as another user', () => {
|
||||
beforeEach(async () => {
|
||||
variables = { id: ' u343', resource: [] }
|
||||
|
||||
user = await Factory.build('user', {
|
||||
name: 'My name should be deleted',
|
||||
about: 'along with my about',
|
||||
id: 'u343',
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
anotherUser = await Factory.build(
|
||||
'user',
|
||||
{
|
||||
role: 'user',
|
||||
},
|
||||
{
|
||||
email: 'user@example.org',
|
||||
password: '1234',
|
||||
},
|
||||
)
|
||||
|
||||
authenticatedUser = await anotherUser.toJson()
|
||||
})
|
||||
|
||||
it("an ordinary user has no authorization to delete another user's account", async () => {
|
||||
const { errors } = await mutate({ mutation: deleteUserMutation, variables })
|
||||
expect(errors[0]).toHaveProperty('message', 'Not Authorised!')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Delete a User as moderator', () => {
|
||||
beforeEach(async () => {
|
||||
variables = { id: ' u343', resource: [] }
|
||||
|
||||
user = await Factory.build('user', {
|
||||
name: 'My name should be deleted',
|
||||
about: 'along with my about',
|
||||
id: 'u343',
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
moderator = await Factory.build(
|
||||
'user',
|
||||
{
|
||||
role: 'moderator',
|
||||
},
|
||||
{
|
||||
email: 'moderator@example.org',
|
||||
password: '1234',
|
||||
},
|
||||
)
|
||||
|
||||
authenticatedUser = await moderator.toJson()
|
||||
})
|
||||
|
||||
it('moderator is not allowed to delete other user accounts', async () => {
|
||||
const { errors } = await mutate({ mutation: deleteUserMutation, variables })
|
||||
expect(errors[0]).toHaveProperty('message', 'Not Authorised!')
|
||||
})
|
||||
})
|
||||
|
||||
describe('User', () => {
|
||||
describe('query by email address', () => {
|
||||
@ -135,13 +72,7 @@ describe('User', () => {
|
||||
await Factory.build('user', { name: 'Johnny' }, { email: 'any-email-address@example.org' })
|
||||
})
|
||||
|
||||
const userQuery = gql`
|
||||
query($email: String) {
|
||||
User(email: $email) {
|
||||
name
|
||||
}
|
||||
}
|
||||
`
|
||||
const userQuery = gql `query($email: String) { User(email: $email) { name } }`
|
||||
const variables = { email: 'any-email-address@example.org' }
|
||||
|
||||
it('is forbidden', async() => {
|
||||
@ -153,11 +84,9 @@ describe('User', () => {
|
||||
describe('as admin', () => {
|
||||
beforeEach(async() => {
|
||||
const admin = await Factory.build(
|
||||
'user',
|
||||
{
|
||||
'user', {
|
||||
role: 'admin',
|
||||
},
|
||||
{
|
||||
}, {
|
||||
email: 'admin@example.org',
|
||||
password: '1234',
|
||||
},
|
||||
@ -190,290 +119,7 @@ describe('User', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Delete a User as admin', () => {
|
||||
beforeEach(async () => {
|
||||
variables = { id: ' u343', resource: [] }
|
||||
|
||||
user = await Factory.build('user', {
|
||||
name: 'My name should be deleted',
|
||||
about: 'along with my about',
|
||||
id: 'u343',
|
||||
})
|
||||
})
|
||||
|
||||
describe('authenticated as Admin', () => {
|
||||
beforeEach(async () => {
|
||||
admin = await Factory.build(
|
||||
'user',
|
||||
{
|
||||
role: 'admin',
|
||||
},
|
||||
{
|
||||
email: 'admin@example.org',
|
||||
password: '1234',
|
||||
},
|
||||
)
|
||||
authenticatedUser = await admin.toJson()
|
||||
})
|
||||
|
||||
describe('deleting a user account', () => {
|
||||
beforeEach(() => {
|
||||
variables = { ...variables, id: 'u343' }
|
||||
})
|
||||
|
||||
describe('given posts and comments', () => {
|
||||
beforeEach(async () => {
|
||||
await Factory.build('category', {
|
||||
id: 'cat9',
|
||||
name: 'Democracy & Politics',
|
||||
icon: 'university',
|
||||
})
|
||||
await Factory.build(
|
||||
'post',
|
||||
{
|
||||
id: 'p139',
|
||||
content: 'Post by user u343',
|
||||
},
|
||||
{
|
||||
author: user,
|
||||
categoryIds,
|
||||
},
|
||||
)
|
||||
await Factory.build(
|
||||
'comment',
|
||||
{
|
||||
id: 'c155',
|
||||
content: 'Comment by user u343',
|
||||
},
|
||||
{
|
||||
author: user,
|
||||
},
|
||||
)
|
||||
await Factory.build(
|
||||
'comment',
|
||||
{
|
||||
id: 'c156',
|
||||
content: "A comment by someone else on user u343's post",
|
||||
},
|
||||
{
|
||||
postId: 'p139',
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
it("deletes account, but doesn't delete posts or comments by default", async () => {
|
||||
const expectedResponse = {
|
||||
data: {
|
||||
DeleteUser: {
|
||||
id: 'u343',
|
||||
name: 'UNAVAILABLE',
|
||||
about: 'UNAVAILABLE',
|
||||
deleted: true,
|
||||
contributions: [
|
||||
{
|
||||
id: 'p139',
|
||||
content: 'Post by user u343',
|
||||
contentExcerpt: 'Post by user u343',
|
||||
deleted: false,
|
||||
comments: [
|
||||
{
|
||||
id: 'c156',
|
||||
content: "A comment by someone else on user u343's post",
|
||||
contentExcerpt: "A comment by someone else on user u343's post",
|
||||
deleted: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
comments: [
|
||||
{
|
||||
id: 'c155',
|
||||
content: 'Comment by user u343',
|
||||
contentExcerpt: 'Comment by user u343',
|
||||
deleted: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
}
|
||||
await expect(mutate({ mutation: deleteUserMutation, variables })).resolves.toMatchObject(
|
||||
expectedResponse,
|
||||
)
|
||||
})
|
||||
|
||||
describe('deletion of all post requested', () => {
|
||||
beforeEach(() => {
|
||||
variables = { ...variables, resource: ['Post'] }
|
||||
})
|
||||
|
||||
it('on request', async () => {
|
||||
const expectedResponse = {
|
||||
data: {
|
||||
DeleteUser: {
|
||||
id: 'u343',
|
||||
name: 'UNAVAILABLE',
|
||||
about: 'UNAVAILABLE',
|
||||
deleted: true,
|
||||
contributions: [
|
||||
{
|
||||
id: 'p139',
|
||||
content: 'UNAVAILABLE',
|
||||
contentExcerpt: 'UNAVAILABLE',
|
||||
deleted: true,
|
||||
comments: [
|
||||
{
|
||||
id: 'c156',
|
||||
content: 'UNAVAILABLE',
|
||||
contentExcerpt: 'UNAVAILABLE',
|
||||
deleted: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
comments: [
|
||||
{
|
||||
id: 'c155',
|
||||
content: 'Comment by user u343',
|
||||
contentExcerpt: 'Comment by user u343',
|
||||
deleted: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
}
|
||||
await expect(
|
||||
mutate({ mutation: deleteUserMutation, variables }),
|
||||
).resolves.toMatchObject(expectedResponse)
|
||||
})
|
||||
|
||||
it('deletes user avatar and post hero images', async () => {
|
||||
await expect(neode.all('Image')).resolves.toHaveLength(22)
|
||||
await mutate({ mutation: deleteUserMutation, variables })
|
||||
await expect(neode.all('Image')).resolves.toHaveLength(20)
|
||||
})
|
||||
})
|
||||
|
||||
describe('deletion of all comments requested', () => {
|
||||
beforeEach(() => {
|
||||
variables = { ...variables, resource: ['Comment'] }
|
||||
})
|
||||
|
||||
it('marks comments as deleted', async () => {
|
||||
const expectedResponse = {
|
||||
data: {
|
||||
DeleteUser: {
|
||||
id: 'u343',
|
||||
name: 'UNAVAILABLE',
|
||||
about: 'UNAVAILABLE',
|
||||
deleted: true,
|
||||
contributions: [
|
||||
{
|
||||
id: 'p139',
|
||||
content: 'Post by user u343',
|
||||
contentExcerpt: 'Post by user u343',
|
||||
deleted: false,
|
||||
comments: [
|
||||
{
|
||||
id: 'c156',
|
||||
content: "A comment by someone else on user u343's post",
|
||||
contentExcerpt: "A comment by someone else on user u343's post",
|
||||
deleted: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
comments: [
|
||||
{
|
||||
id: 'c155',
|
||||
content: 'UNAVAILABLE',
|
||||
contentExcerpt: 'UNAVAILABLE',
|
||||
deleted: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
}
|
||||
await expect(
|
||||
mutate({ mutation: deleteUserMutation, variables }),
|
||||
).resolves.toMatchObject(expectedResponse)
|
||||
})
|
||||
})
|
||||
|
||||
describe('deletion of all posts and comments requested', () => {
|
||||
beforeEach(() => {
|
||||
variables = { ...variables, resource: ['Comment', 'Post'] }
|
||||
})
|
||||
|
||||
it('marks posts and comments as deleted', async () => {
|
||||
const expectedResponse = {
|
||||
data: {
|
||||
DeleteUser: {
|
||||
id: 'u343',
|
||||
name: 'UNAVAILABLE',
|
||||
about: 'UNAVAILABLE',
|
||||
deleted: true,
|
||||
contributions: [
|
||||
{
|
||||
id: 'p139',
|
||||
content: 'UNAVAILABLE',
|
||||
contentExcerpt: 'UNAVAILABLE',
|
||||
deleted: true,
|
||||
comments: [
|
||||
{
|
||||
id: 'c156',
|
||||
content: 'UNAVAILABLE',
|
||||
contentExcerpt: 'UNAVAILABLE',
|
||||
deleted: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
comments: [
|
||||
{
|
||||
id: 'c155',
|
||||
content: 'UNAVAILABLE',
|
||||
contentExcerpt: 'UNAVAILABLE',
|
||||
deleted: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
}
|
||||
await expect(
|
||||
mutate({ mutation: deleteUserMutation, variables }),
|
||||
).resolves.toMatchObject(expectedResponse)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('connected `EmailAddress` nodes', () => {
|
||||
it('will be removed completely', async () => {
|
||||
await expect(neode.all('EmailAddress')).resolves.toHaveLength(2)
|
||||
await mutate({ mutation: deleteUserMutation, variables })
|
||||
|
||||
await expect(neode.all('EmailAddress')).resolves.toHaveLength(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('connected `SocialMedia` nodes', () => {
|
||||
beforeEach(async () => {
|
||||
const socialMedia = await Factory.build('socialMedia')
|
||||
await socialMedia.relateTo(user, 'ownedBy')
|
||||
})
|
||||
|
||||
it('will be removed completely', async () => {
|
||||
await expect(neode.all('SocialMedia')).resolves.toHaveLength(1)
|
||||
await mutate({ mutation: deleteUserMutation, variables })
|
||||
await expect(neode.all('SocialMedia')).resolves.toHaveLength(0)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('UpdateUser', () => {
|
||||
let variables
|
||||
@ -506,18 +152,15 @@ describe('UpdateUser', () => {
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
beforeEach(async() => {
|
||||
user = await Factory.build(
|
||||
'user',
|
||||
{
|
||||
'user', {
|
||||
id: 'u47',
|
||||
name: 'John Doe',
|
||||
termsAndConditionsAgreedVersion: null,
|
||||
termsAndConditionsAgreedAt: null,
|
||||
allowEmbedIframes: false,
|
||||
},
|
||||
{
|
||||
}, {
|
||||
email: 'user@example.org',
|
||||
},
|
||||
)
|
||||
@ -526,11 +169,9 @@ describe('UpdateUser', () => {
|
||||
describe('as another user', () => {
|
||||
beforeEach(async() => {
|
||||
const someoneElse = await Factory.build(
|
||||
'user',
|
||||
{
|
||||
'user', {
|
||||
name: 'James Doe',
|
||||
},
|
||||
{
|
||||
}, {
|
||||
email: 'someone-else@example.org',
|
||||
},
|
||||
)
|
||||
@ -624,3 +265,300 @@ describe('UpdateUser', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Delete a user', () => {
|
||||
beforeEach(async() => {
|
||||
variables = { id: ' u343', resource: [] }
|
||||
|
||||
user = await Factory.build('user', {
|
||||
name: 'My name should be deleted',
|
||||
about: 'along with my about',
|
||||
id: 'u343',
|
||||
})
|
||||
})
|
||||
|
||||
describe('as another user', () => {
|
||||
beforeEach(async() => {
|
||||
|
||||
anotherUser = await Factory.build(
|
||||
'user', {
|
||||
role: 'user',
|
||||
}, {
|
||||
email: 'user@example.org',
|
||||
password: '1234',
|
||||
},
|
||||
)
|
||||
|
||||
authenticatedUser = await anotherUser.toJson()
|
||||
})
|
||||
|
||||
it("an ordinary user has no authorization to delete another user's account", async() => {
|
||||
const { errors } = await mutate({ mutation: deleteUserMutation, variables })
|
||||
expect(errors[0]).toHaveProperty('message', 'Not Authorised!')
|
||||
})
|
||||
})
|
||||
|
||||
describe('as moderator', () => {
|
||||
beforeEach(async() => {
|
||||
|
||||
moderator = await Factory.build(
|
||||
'user', {
|
||||
role: 'moderator',
|
||||
}, {
|
||||
email: 'moderator@example.org',
|
||||
password: '1234',
|
||||
},
|
||||
)
|
||||
|
||||
authenticatedUser = await moderator.toJson()
|
||||
})
|
||||
|
||||
it('moderator is not allowed to delete other user accounts', async() => {
|
||||
const { errors } = await mutate({ mutation: deleteUserMutation, variables })
|
||||
expect(errors[0]).toHaveProperty('message', 'Not Authorised!')
|
||||
})
|
||||
})
|
||||
|
||||
describe('as admin', () => {
|
||||
describe('authenticated as Admin', () => {
|
||||
beforeEach(async() => {
|
||||
admin = await Factory.build(
|
||||
'user', {
|
||||
role: 'admin',
|
||||
}, {
|
||||
email: 'admin@example.org',
|
||||
password: '1234',
|
||||
},
|
||||
)
|
||||
authenticatedUser = await admin.toJson()
|
||||
})
|
||||
|
||||
describe('deleting a user account', () => {
|
||||
beforeEach(() => {
|
||||
variables = {...variables, id: 'u343' }
|
||||
})
|
||||
|
||||
describe('given posts and comments', () => {
|
||||
beforeEach(async() => {
|
||||
await Factory.build('category', {
|
||||
id: 'cat9',
|
||||
name: 'Democracy & Politics',
|
||||
icon: 'university',
|
||||
})
|
||||
await Factory.build(
|
||||
'post', {
|
||||
id: 'p139',
|
||||
content: 'Post by user u343',
|
||||
}, {
|
||||
author: user,
|
||||
categoryIds,
|
||||
},
|
||||
)
|
||||
await Factory.build(
|
||||
'comment', {
|
||||
id: 'c155',
|
||||
content: 'Comment by user u343',
|
||||
}, {
|
||||
author: user,
|
||||
},
|
||||
)
|
||||
await Factory.build(
|
||||
'comment', {
|
||||
id: 'c156',
|
||||
content: "A comment by someone else on user u343's post",
|
||||
}, {
|
||||
postId: 'p139',
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
it("deletes account, but doesn't delete posts or comments by default", async() => {
|
||||
const expectedResponse = {
|
||||
data: {
|
||||
DeleteUser: {
|
||||
id: 'u343',
|
||||
name: 'UNAVAILABLE',
|
||||
about: 'UNAVAILABLE',
|
||||
deleted: true,
|
||||
contributions: [{
|
||||
id: 'p139',
|
||||
content: 'Post by user u343',
|
||||
contentExcerpt: 'Post by user u343',
|
||||
deleted: false,
|
||||
comments: [{
|
||||
id: 'c156',
|
||||
content: "A comment by someone else on user u343's post",
|
||||
contentExcerpt: "A comment by someone else on user u343's post",
|
||||
deleted: false,
|
||||
}, ],
|
||||
}, ],
|
||||
comments: [{
|
||||
id: 'c155',
|
||||
content: 'Comment by user u343',
|
||||
contentExcerpt: 'Comment by user u343',
|
||||
deleted: false,
|
||||
}, ],
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
}
|
||||
await expect(mutate({ mutation: deleteUserMutation, variables })).resolves.toMatchObject(
|
||||
expectedResponse,
|
||||
)
|
||||
})
|
||||
|
||||
describe('deletion of all post requested', () => {
|
||||
beforeEach(() => {
|
||||
variables = {...variables, resource: ['Post'] }
|
||||
})
|
||||
|
||||
it('on request', async() => {
|
||||
const expectedResponse = {
|
||||
data: {
|
||||
DeleteUser: {
|
||||
id: 'u343',
|
||||
name: 'UNAVAILABLE',
|
||||
about: 'UNAVAILABLE',
|
||||
deleted: true,
|
||||
contributions: [{
|
||||
id: 'p139',
|
||||
content: 'UNAVAILABLE',
|
||||
contentExcerpt: 'UNAVAILABLE',
|
||||
deleted: true,
|
||||
comments: [{
|
||||
id: 'c156',
|
||||
content: 'UNAVAILABLE',
|
||||
contentExcerpt: 'UNAVAILABLE',
|
||||
deleted: true,
|
||||
}, ],
|
||||
}, ],
|
||||
comments: [{
|
||||
id: 'c155',
|
||||
content: 'Comment by user u343',
|
||||
contentExcerpt: 'Comment by user u343',
|
||||
deleted: false,
|
||||
}, ],
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
}
|
||||
await expect(
|
||||
mutate({ mutation: deleteUserMutation, variables }),
|
||||
).resolves.toMatchObject(expectedResponse)
|
||||
})
|
||||
|
||||
it('deletes user avatar and post hero images', async() => {
|
||||
await expect(neode.all('Image')).resolves.toHaveLength(22)
|
||||
await mutate({ mutation: deleteUserMutation, variables })
|
||||
await expect(neode.all('Image')).resolves.toHaveLength(20)
|
||||
})
|
||||
})
|
||||
|
||||
describe('deletion of all comments requested', () => {
|
||||
beforeEach(() => {
|
||||
variables = {...variables, resource: ['Comment'] }
|
||||
})
|
||||
|
||||
it('marks comments as deleted', async() => {
|
||||
const expectedResponse = {
|
||||
data: {
|
||||
DeleteUser: {
|
||||
id: 'u343',
|
||||
name: 'UNAVAILABLE',
|
||||
about: 'UNAVAILABLE',
|
||||
deleted: true,
|
||||
contributions: [{
|
||||
id: 'p139',
|
||||
content: 'Post by user u343',
|
||||
contentExcerpt: 'Post by user u343',
|
||||
deleted: false,
|
||||
comments: [{
|
||||
id: 'c156',
|
||||
content: "A comment by someone else on user u343's post",
|
||||
contentExcerpt: "A comment by someone else on user u343's post",
|
||||
deleted: false,
|
||||
}, ],
|
||||
}, ],
|
||||
comments: [{
|
||||
id: 'c155',
|
||||
content: 'UNAVAILABLE',
|
||||
contentExcerpt: 'UNAVAILABLE',
|
||||
deleted: true,
|
||||
}, ],
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
}
|
||||
await expect(
|
||||
mutate({ mutation: deleteUserMutation, variables }),
|
||||
).resolves.toMatchObject(expectedResponse)
|
||||
})
|
||||
})
|
||||
|
||||
describe('deletion of all posts and comments requested', () => {
|
||||
beforeEach(() => {
|
||||
variables = {...variables, resource: ['Comment', 'Post'] }
|
||||
})
|
||||
|
||||
it('marks posts and comments as deleted', async() => {
|
||||
const expectedResponse = {
|
||||
data: {
|
||||
DeleteUser: {
|
||||
id: 'u343',
|
||||
name: 'UNAVAILABLE',
|
||||
about: 'UNAVAILABLE',
|
||||
deleted: true,
|
||||
contributions: [{
|
||||
id: 'p139',
|
||||
content: 'UNAVAILABLE',
|
||||
contentExcerpt: 'UNAVAILABLE',
|
||||
deleted: true,
|
||||
comments: [{
|
||||
id: 'c156',
|
||||
content: 'UNAVAILABLE',
|
||||
contentExcerpt: 'UNAVAILABLE',
|
||||
deleted: true,
|
||||
}, ],
|
||||
}, ],
|
||||
comments: [{
|
||||
id: 'c155',
|
||||
content: 'UNAVAILABLE',
|
||||
contentExcerpt: 'UNAVAILABLE',
|
||||
deleted: true,
|
||||
}, ],
|
||||
},
|
||||
},
|
||||
errors: undefined,
|
||||
}
|
||||
await expect(
|
||||
mutate({ mutation: deleteUserMutation, variables }),
|
||||
).resolves.toMatchObject(expectedResponse)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('connected `EmailAddress` nodes', () => {
|
||||
it('will be removed completely', async() => {
|
||||
await expect(neode.all('EmailAddress')).resolves.toHaveLength(2)
|
||||
await mutate({ mutation: deleteUserMutation, variables })
|
||||
|
||||
await expect(neode.all('EmailAddress')).resolves.toHaveLength(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('connected `SocialMedia` nodes', () => {
|
||||
beforeEach(async() => {
|
||||
const socialMedia = await Factory.build('socialMedia')
|
||||
await socialMedia.relateTo(user, 'ownedBy')
|
||||
})
|
||||
|
||||
it('will be removed completely', async() => {
|
||||
await expect(neode.all('SocialMedia')).resolves.toHaveLength(1)
|
||||
await mutate({ mutation: deleteUserMutation, variables })
|
||||
await expect(neode.all('SocialMedia')).resolves.toHaveLength(0)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user