mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Refactore and cleanup backend tests
- Removed double declarations. - Put assignments in 'beforeEach'.
This commit is contained in:
parent
9ff1fc5b62
commit
17a296b82e
@ -18,35 +18,6 @@ let variables
|
|||||||
const driver = getDriver()
|
const driver = getDriver()
|
||||||
const neode = getNeode()
|
const neode = getNeode()
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`
|
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
const { server } = createServer({
|
const { server } = createServer({
|
||||||
context: () => {
|
context: () => {
|
||||||
@ -67,19 +38,23 @@ beforeEach(async () => {
|
|||||||
|
|
||||||
describe('User', () => {
|
describe('User', () => {
|
||||||
describe('query by email address', () => {
|
describe('query by email address', () => {
|
||||||
|
let userQuery
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
userQuery = gql`
|
||||||
|
query($email: String) {
|
||||||
|
User(email: $email) {
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
variables = {
|
||||||
|
email: 'any-email-address@example.org',
|
||||||
|
}
|
||||||
|
|
||||||
await Factory.build('user', { name: 'Johnny' }, { email: 'any-email-address@example.org' })
|
await Factory.build('user', { name: 'Johnny' }, { email: 'any-email-address@example.org' })
|
||||||
})
|
})
|
||||||
|
|
||||||
const userQuery = gql`
|
|
||||||
query($email: String) {
|
|
||||||
User(email: $email) {
|
|
||||||
name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`
|
|
||||||
const variables = { email: 'any-email-address@example.org' }
|
|
||||||
|
|
||||||
it('is forbidden', async () => {
|
it('is forbidden', async () => {
|
||||||
await expect(query({ query: userQuery, variables })).resolves.toMatchObject({
|
await expect(query({ query: userQuery, variables })).resolves.toMatchObject({
|
||||||
errors: [{ message: 'Not Authorised!' }],
|
errors: [{ message: 'Not Authorised!' }],
|
||||||
@ -127,37 +102,35 @@ describe('User', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('UpdateUser', () => {
|
describe('UpdateUser', () => {
|
||||||
let variables
|
let updateUserMutation
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
updateUserMutation = gql`
|
||||||
|
mutation(
|
||||||
|
$id: ID!
|
||||||
|
$name: String
|
||||||
|
$termsAndConditionsAgreedVersion: String
|
||||||
|
$locationName: String
|
||||||
|
) {
|
||||||
|
UpdateUser(
|
||||||
|
id: $id
|
||||||
|
name: $name
|
||||||
|
termsAndConditionsAgreedVersion: $termsAndConditionsAgreedVersion
|
||||||
|
locationName: $locationName
|
||||||
|
) {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
termsAndConditionsAgreedVersion
|
||||||
|
termsAndConditionsAgreedAt
|
||||||
|
locationName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
variables = {
|
variables = {
|
||||||
id: 'u47',
|
id: 'u47',
|
||||||
name: 'John Doughnut',
|
name: 'John Doughnut',
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
const updateUserMutation = gql`
|
|
||||||
mutation(
|
|
||||||
$id: ID!
|
|
||||||
$name: String
|
|
||||||
$termsAndConditionsAgreedVersion: String
|
|
||||||
$locationName: String
|
|
||||||
) {
|
|
||||||
UpdateUser(
|
|
||||||
id: $id
|
|
||||||
name: $name
|
|
||||||
termsAndConditionsAgreedVersion: $termsAndConditionsAgreedVersion
|
|
||||||
locationName: $locationName
|
|
||||||
) {
|
|
||||||
id
|
|
||||||
name
|
|
||||||
termsAndConditionsAgreedVersion
|
|
||||||
termsAndConditionsAgreedAt
|
|
||||||
locationName
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`
|
|
||||||
beforeEach(async () => {
|
|
||||||
user = await Factory.build(
|
user = await Factory.build(
|
||||||
'user',
|
'user',
|
||||||
{
|
{
|
||||||
@ -276,7 +249,37 @@ describe('UpdateUser', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('Delete a user', () => {
|
describe('Delete a user', () => {
|
||||||
|
let deleteUserMutation
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
variables = { id: ' u343', resource: [] }
|
variables = { id: ' u343', resource: [] }
|
||||||
|
|
||||||
user = await Factory.build('user', {
|
user = await Factory.build('user', {
|
||||||
@ -348,7 +351,7 @@ describe('Delete a user', () => {
|
|||||||
|
|
||||||
describe('deleting a user account', () => {
|
describe('deleting a user account', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
variables = { ...variables, id: 'u343' }
|
variables = { id: 'u343' }
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('given posts and comments', () => {
|
describe('given posts and comments', () => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user