mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
DRY user.spec.js
This commit is contained in:
parent
07ded7419f
commit
da165906e2
@ -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
|
||||
`)
|
||||
}
|
||||
})
|
||||
|
||||
@ -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
|
||||
`)
|
||||
}
|
||||
})
|
||||
|
||||
@ -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: [] }
|
||||
|
||||
@ -364,35 +337,7 @@ describe('DeleteUser as moderator', () => {
|
||||
})
|
||||
})
|
||||
|
||||
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', () => {
|
||||
@ -672,36 +617,7 @@ 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', () => {
|
||||
@ -1033,3 +906,4 @@ describe('User deletes his account himself', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user