DRY user.spec.js

This commit is contained in:
roschaefer 2020-03-10 18:16:09 +01:00
parent 07ded7419f
commit da165906e2
3 changed files with 505 additions and 631 deletions

View File

@ -153,7 +153,7 @@ describe('slugifyMiddleware', () => {
\`\`\`
Learn how to setup the database here:
https://docs.human-connection.org/human-connection/neo4j
https://docs.human-connection.org/human-connection/backend#database-indices-and-constraints
`)
}
})

View File

@ -46,7 +46,7 @@ describe('slug', () => {
\`\`\`
Learn how to setup the database here:
https://docs.human-connection.org/human-connection/neo4j
https://docs.human-connection.org/human-connection/backend#database-indices-and-constraints
`)
}
})

View File

@ -244,7 +244,7 @@ describe('UpdateUser', () => {
})
})
describe('DeleteUser as another user', () => {
describe('DeleteUser', () => {
const deleteUserMutation = gql`
mutation($id: ID!, $resource: [Deletable]) {
DeleteUser(id: $id, resource: $resource) {
@ -273,6 +273,7 @@ describe('DeleteUser as another user', () => {
}
}
`
describe('as another user', () => {
beforeEach(async () => {
variables = { id: ' u343', resource: [] }
@ -298,41 +299,13 @@ describe('DeleteUser as another user', () => {
authenticatedUser = await anotherUser.toJson()
})
it('a user has no authorization to delete another user accounts', async () => {
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('DeleteUser as moderator', () => {
const deleteUserMutation = gql`
mutation($id: ID!, $resource: [Deletable]) {
DeleteUser(id: $id, resource: $resource) {
id
name
about
deleted
contributions {
id
content
contentExcerpt
deleted
comments {
id
content
contentExcerpt
deleted
}
}
comments {
id
content
contentExcerpt
deleted
}
}
}
`
describe('as moderator', () => {
beforeEach(async () => {
variables = { id: ' u343', resource: [] }
@ -362,37 +335,9 @@ describe('DeleteUser as moderator', () => {
const { errors } = await mutate({ mutation: deleteUserMutation, variables })
expect(errors[0]).toHaveProperty('message', 'Not Authorised!')
})
})
})
describe('DeleteUser as Admin', () => {
const deleteUserMutation = gql`
mutation($id: ID!, $resource: [Deletable]) {
DeleteUser(id: $id, resource: $resource) {
id
name
about
deleted
contributions {
id
content
contentExcerpt
deleted
comments {
id
content
contentExcerpt
deleted
}
}
comments {
id
content
contentExcerpt
deleted
}
}
}
`
describe('as admin', () => {
beforeEach(async () => {
variables = { id: ' u343', resource: [] }
@ -499,9 +444,9 @@ describe('DeleteUser as Admin', () => {
},
errors: undefined,
}
await expect(mutate({ mutation: deleteUserMutation, variables })).resolves.toMatchObject(
expectedResponse,
)
await expect(
mutate({ mutation: deleteUserMutation, variables }),
).resolves.toMatchObject(expectedResponse)
})
describe('deletion of all post requested', () => {
@ -670,38 +615,9 @@ describe('DeleteUser as Admin', () => {
})
})
})
})
describe('User deletes his account himself', () => {
const deleteUserMutation = gql`
mutation($id: ID!, $resource: [Deletable]) {
DeleteUser(id: $id, resource: $resource) {
id
name
about
deleted
contributions {
id
content
contentExcerpt
deleted
comments {
id
content
contentExcerpt
deleted
}
}
comments {
id
content
contentExcerpt
deleted
}
}
}
`
})
describe('user deletes his own account', () => {
beforeEach(async () => {
variables = { id: 'u343', resource: [] }
@ -721,49 +637,6 @@ describe('User deletes his account himself', () => {
)
})
describe('unauthenticated anotherUser', () => {
beforeEach(async () => {
const anotherUser = await Factory.build(
'user',
{
role: 'user',
},
{
email: 'user@example.org',
password: '1234',
},
)
authenticatedUser = await anotherUser.toJson()
})
it('a another User has no authorization to delete this user accounts', async () => {
const { errors } = await mutate({ mutation: deleteUserMutation, variables })
expect(errors[0]).toHaveProperty('message', 'Not Authorised!')
})
})
describe('unauthenticated anotherModerator', () => {
beforeEach(async () => {
const anotherModerator = await Factory.build(
'user',
{
role: 'moderator',
},
{
email: 'moderator@example.org',
password: '1234',
},
)
authenticatedUser = await anotherModerator.toJson()
})
it('a Moderator has no authorization to delete this user accounts', async () => {
const { errors } = await mutate({ mutation: deleteUserMutation, variables })
expect(errors[0]).toHaveProperty('message', 'Not Authorised!')
})
})
describe('authenticated', () => {
beforeEach(async () => {
authenticatedUser = await user.toJson()
@ -861,9 +734,9 @@ describe('User deletes his account himself', () => {
},
errors: undefined,
}
await expect(mutate({ mutation: deleteUserMutation, variables })).resolves.toMatchObject(
expectedResponse,
)
await expect(
mutate({ mutation: deleteUserMutation, variables }),
).resolves.toMatchObject(expectedResponse)
})
describe('deletion of all post requested', () => {
@ -1032,4 +905,5 @@ describe('User deletes his account himself', () => {
})
})
})
})
})