Fix as quick fix for all reminding tests

This commit is contained in:
Wolfgang Huß 2021-07-26 11:36:42 +02:00
parent c498cbc299
commit 62de9a158e
33 changed files with 242 additions and 60 deletions

View File

@ -9,4 +9,3 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -30,7 +30,9 @@ const updatePostMutation = gql`
} }
` `
beforeAll(() => { beforeAll(async () => {
await cleanDatabase()
const createServerResult = createServer({ const createServerResult = createServer({
context: () => { context: () => {
return { return {
@ -46,6 +48,10 @@ beforeAll(() => {
mutate = createTestClientResult.mutate mutate = createTestClientResult.mutate
}) })
afterAll(async () => {
await cleanDatabase()
})
beforeEach(async () => { beforeEach(async () => {
hashtagingUser = await neode.create( hashtagingUser = await neode.create(
'User', 'User',
@ -66,6 +72,7 @@ beforeEach(async () => {
}) })
}) })
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => { afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -12,6 +12,8 @@ const driver = getDriver()
const neode = getNeode() const neode = getNeode()
beforeAll(async () => { beforeAll(async () => {
await cleanDatabase()
const { server } = createServer({ const { server } = createServer({
context: () => { context: () => {
return { return {
@ -43,7 +45,6 @@ describe('languagesMiddleware', () => {
} }
beforeAll(async () => { beforeAll(async () => {
await cleanDatabase()
const user = await Factory.build('user') const user = await Factory.build('user')
authenticatedUser = await user.toJson() authenticatedUser = await user.toJson()
await Factory.build('category', { await Factory.build('category', {

View File

@ -37,6 +37,7 @@ const createCommentMutation = gql`
beforeAll(async () => { beforeAll(async () => {
await cleanDatabase() await cleanDatabase()
publishSpy = jest.spyOn(pubsub, 'publish') publishSpy = jest.spyOn(pubsub, 'publish')
const createServerResult = createServer({ const createServerResult = createServer({
context: () => { context: () => {
@ -53,6 +54,10 @@ beforeAll(async () => {
mutate = createTestClientResult.mutate mutate = createTestClientResult.mutate
}) })
afterAll(async () => {
await cleanDatabase()
})
beforeEach(async () => { beforeEach(async () => {
publishSpy.mockClear() publishSpy.mockClear()
notifiedUser = await neode.create( notifiedUser = await neode.create(
@ -74,6 +79,7 @@ beforeEach(async () => {
}) })
}) })
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => { afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -13,6 +13,7 @@ const neode = getNeode()
beforeAll(async () => { beforeAll(async () => {
await cleanDatabase() await cleanDatabase()
const { server } = createServer({ const { server } = createServer({
context: () => { context: () => {
return { return {
@ -25,6 +26,10 @@ beforeAll(async () => {
mutate = createTestClient(server).mutate mutate = createTestClient(server).mutate
}) })
afterAll(async () => {
await cleanDatabase()
})
beforeEach(async () => { beforeEach(async () => {
variables = {} variables = {}
const admin = await Factory.build('user', { const admin = await Factory.build('user', {
@ -46,6 +51,7 @@ beforeEach(async () => {
authenticatedUser = await admin.toJson() authenticatedUser = await admin.toJson()
}) })
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => { afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -15,6 +15,8 @@ const action = () => {
} }
beforeAll(async () => { beforeAll(async () => {
await cleanDatabase()
// For performance reasons we do this only once // For performance reasons we do this only once
const users = await Promise.all([ const users = await Promise.all([
Factory.build('user', { id: 'u1', role: 'user' }), Factory.build('user', { id: 'u1', role: 'user' }),

View File

@ -19,6 +19,7 @@ const postQuery = gql`
beforeAll(async () => { beforeAll(async () => {
await cleanDatabase() await cleanDatabase()
aUser = await Factory.build('user', { aUser = await Factory.build('user', {
id: 'a-user', id: 'a-user',
}) })

View File

@ -50,7 +50,6 @@ const reviewMutation = gql`
} }
} }
` `
const updateUserMutation = gql` const updateUserMutation = gql`
mutation ($id: ID!, $name: String) { mutation ($id: ID!, $name: String) {
UpdateUser(id: $id, name: $name) { UpdateUser(id: $id, name: $name) {
@ -58,7 +57,10 @@ const updateUserMutation = gql`
} }
} }
` `
beforeAll(() => {
beforeAll(async () => {
await cleanDatabase()
const { server } = createServer({ const { server } = createServer({
context: () => { context: () => {
return { return {
@ -71,6 +73,10 @@ beforeAll(() => {
mutate = createTestClient(server).mutate mutate = createTestClient(server).mutate
}) })
afterAll(async () => {
await cleanDatabase()
})
beforeEach(async () => { beforeEach(async () => {
users = await Promise.all([ users = await Promise.all([
Factory.build('user', { Factory.build('user', {
@ -120,6 +126,7 @@ beforeEach(async () => {
offensivePost = posts[0] offensivePost = posts[0]
}) })
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => { afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -3,6 +3,15 @@ import { getNeode } from '../db/neo4j'
const neode = getNeode() const neode = getNeode()
beforeAll(async () => {
await cleanDatabase()
})
afterAll(async () => {
await cleanDatabase()
})
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => { afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -11,6 +11,7 @@ let variables, mutate, authenticatedUser, commentAuthor, newlyCreatedComment
beforeAll(async () => { beforeAll(async () => {
await cleanDatabase() await cleanDatabase()
const { server } = createServer({ const { server } = createServer({
context: () => { context: () => {
return { return {
@ -22,6 +23,10 @@ beforeAll(async () => {
mutate = createTestClient(server).mutate mutate = createTestClient(server).mutate
}) })
afterAll(async () => {
await cleanDatabase()
})
beforeEach(async () => { beforeEach(async () => {
variables = {} variables = {}
await neode.create('Category', { await neode.create('Category', {
@ -31,6 +36,7 @@ beforeEach(async () => {
}) })
}) })
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => { afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -29,6 +29,14 @@ const donationsQuery = gql`
} }
` `
beforeAll(async () => {
await cleanDatabase()
})
afterAll(async () => {
await cleanDatabase()
})
describe('donations', () => { describe('donations', () => {
let currentUser, newlyCreatedDonations let currentUser, newlyCreatedDonations
beforeAll(async () => { beforeAll(async () => {
@ -52,6 +60,7 @@ describe('donations', () => {
newlyCreatedDonations = await Factory.build('donations') newlyCreatedDonations = await Factory.build('donations')
}) })
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => { afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -12,12 +12,9 @@ let user
let variables let variables
const driver = getDriver() const driver = getDriver()
beforeEach(async () => {
variables = {}
})
beforeAll(async () => { beforeAll(async () => {
await cleanDatabase() await cleanDatabase()
const { server } = createServer({ const { server } = createServer({
context: () => { context: () => {
return { return {
@ -31,6 +28,15 @@ beforeAll(async () => {
query = createTestClient(server).query query = createTestClient(server).query
}) })
afterAll(async () => {
await cleanDatabase()
})
beforeEach(async () => {
variables = {}
})
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => { afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -27,7 +27,6 @@ const mutationFollowUser = gql`
} }
} }
` `
const mutationUnfollowUser = gql` const mutationUnfollowUser = gql`
mutation ($id: ID!) { mutation ($id: ID!) {
unfollowUser(id: $id) { unfollowUser(id: $id) {
@ -40,7 +39,6 @@ const mutationUnfollowUser = gql`
} }
} }
` `
const userQuery = gql` const userQuery = gql`
query ($id: ID) { query ($id: ID) {
User(id: $id) { User(id: $id) {
@ -54,6 +52,7 @@ const userQuery = gql`
beforeAll(async () => { beforeAll(async () => {
await cleanDatabase() await cleanDatabase()
const { server } = createServer({ const { server } = createServer({
context: () => ({ context: () => ({
driver, driver,
@ -70,6 +69,10 @@ beforeAll(async () => {
mutate = testClient.mutate mutate = testClient.mutate
}) })
afterAll(async () => {
await cleanDatabase()
})
beforeEach(async () => { beforeEach(async () => {
user1 = await Factory.build( user1 = await Factory.build(
'user', 'user',
@ -98,6 +101,7 @@ beforeEach(async () => {
variables = { id: user2.id } variables = { id: user2.id }
}) })
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => { afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -9,12 +9,24 @@ const uuid = '[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-
let uploadCallback let uploadCallback
let deleteCallback let deleteCallback
beforeEach(async () => { beforeAll(async () => {
await cleanDatabase() await cleanDatabase()
})
afterAll(async () => {
await cleanDatabase()
})
beforeEach(async () => {
uploadCallback = jest.fn(({ uniqueFilename }) => `/uploads/${uniqueFilename}`) uploadCallback = jest.fn(({ uniqueFilename }) => `/uploads/${uniqueFilename}`)
deleteCallback = jest.fn() deleteCallback = jest.fn()
}) })
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => {
await cleanDatabase()
})
describe('deleteImage', () => { describe('deleteImage', () => {
describe('given a resource with an image', () => { describe('given a resource with an image', () => {
let user let user

View File

@ -19,7 +19,6 @@ const generateInviteCodeMutation = gql`
} }
} }
` `
const myInviteCodesQuery = gql` const myInviteCodesQuery = gql`
query { query {
MyInviteCodes { MyInviteCodes {
@ -29,7 +28,6 @@ const myInviteCodesQuery = gql`
} }
} }
` `
const isValidInviteCodeQuery = gql` const isValidInviteCodeQuery = gql`
query ($code: ID!) { query ($code: ID!) {
isValidInviteCode(code: $code) isValidInviteCode(code: $code)
@ -38,6 +36,7 @@ const isValidInviteCodeQuery = gql`
beforeAll(async () => { beforeAll(async () => {
await cleanDatabase() await cleanDatabase()
const { server } = createServer({ const { server } = createServer({
context: () => { context: () => {
return { return {

View File

@ -9,7 +9,9 @@ let mutate, authenticatedUser
const driver = getDriver() const driver = getDriver()
const neode = getNeode() const neode = getNeode()
beforeAll(() => { beforeAll(async () => {
await cleanDatabase()
const { server } = createServer({ const { server } = createServer({
context: () => { context: () => {
return { return {
@ -22,6 +24,11 @@ beforeAll(() => {
mutate = createTestClient(server).mutate mutate = createTestClient(server).mutate
}) })
afterAll(async () => {
await cleanDatabase()
})
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => { afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -54,6 +54,7 @@ const reviewMutation = gql`
describe('moderate resources', () => { describe('moderate resources', () => {
beforeAll(async () => { beforeAll(async () => {
await cleanDatabase() await cleanDatabase()
authenticatedUser = undefined authenticatedUser = undefined
const { server } = createServer({ const { server } = createServer({
context: () => { context: () => {
@ -67,6 +68,10 @@ describe('moderate resources', () => {
mutate = createTestClient(server).mutate mutate = createTestClient(server).mutate
}) })
afterAll(async () => {
await cleanDatabase()
})
beforeEach(async () => { beforeEach(async () => {
disableVariables = { disableVariables = {
resourceId: 'undefined-resource', resourceId: 'undefined-resource',
@ -104,6 +109,7 @@ describe('moderate resources', () => {
) )
}) })
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => { afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -12,7 +12,9 @@ let variables
let query let query
let mutate let mutate
beforeAll(() => { beforeAll(async () => {
await cleanDatabase()
const { server } = createServer({ const { server } = createServer({
context: () => { context: () => {
return { return {
@ -25,11 +27,16 @@ beforeAll(() => {
mutate = createTestClient(server).mutate mutate = createTestClient(server).mutate
}) })
afterAll(async () => {
await cleanDatabase()
})
beforeEach(async () => { beforeEach(async () => {
authenticatedUser = null authenticatedUser = null
variables = { orderBy: 'createdAt_asc' } variables = { orderBy: 'createdAt_asc' }
}) })
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => { afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -20,11 +20,9 @@ const getAllPasswordResets = async () => {
return resets return resets
} }
beforeEach(() => { beforeAll(async () => {
variables = {} await cleanDatabase()
})
beforeAll(() => {
const { server } = createServer({ const { server } = createServer({
context: () => { context: () => {
return { return {
@ -37,6 +35,15 @@ beforeAll(() => {
mutate = createTestClient(server).mutate mutate = createTestClient(server).mutate
}) })
afterAll(async () => {
await cleanDatabase()
})
beforeEach(() => {
variables = {}
})
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => { afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -40,6 +40,7 @@ const createPostMutation = gql`
beforeAll(async () => { beforeAll(async () => {
await cleanDatabase() await cleanDatabase()
const { server } = createServer({ const { server } = createServer({
context: () => { context: () => {
return { return {
@ -53,6 +54,10 @@ beforeAll(async () => {
mutate = createTestClient(server).mutate mutate = createTestClient(server).mutate
}) })
afterAll(async () => {
await cleanDatabase()
})
beforeEach(async () => { beforeEach(async () => {
variables = {} variables = {}
user = await Factory.build( user = await Factory.build(
@ -91,6 +96,7 @@ beforeEach(async () => {
authenticatedUser = null authenticatedUser = null
}) })
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => { afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -12,12 +12,9 @@ let authenticatedUser
let variables let variables
const driver = getDriver() const driver = getDriver()
beforeEach(async () => {
variables = {}
})
beforeAll(async () => { beforeAll(async () => {
await cleanDatabase() await cleanDatabase()
const { server } = createServer({ const { server } = createServer({
context: () => { context: () => {
return { return {
@ -30,6 +27,15 @@ beforeAll(async () => {
mutate = createTestClient(server).mutate mutate = createTestClient(server).mutate
}) })
afterAll(async () => {
await cleanDatabase()
})
beforeEach(async () => {
variables = {}
})
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => { afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -101,6 +101,7 @@ describe('file a report on a resource', () => {
beforeAll(async () => { beforeAll(async () => {
await cleanDatabase() await cleanDatabase()
const { server } = createServer({ const { server } = createServer({
context: () => { context: () => {
return { return {
@ -114,6 +115,11 @@ describe('file a report on a resource', () => {
query = createTestClient(server).query query = createTestClient(server).query
}) })
afterAll(async () => {
await cleanDatabase()
})
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => { afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -17,6 +17,7 @@ describe('rewards', () => {
beforeAll(async () => { beforeAll(async () => {
await cleanDatabase() await cleanDatabase()
const { server } = createServer({ const { server } = createServer({
context: () => { context: () => {
return { return {
@ -30,6 +31,10 @@ describe('rewards', () => {
mutate = createTestClient(server).mutate mutate = createTestClient(server).mutate
}) })
afterAll(async () => {
await cleanDatabase()
})
beforeEach(async () => { beforeEach(async () => {
regularUser = await Factory.build( regularUser = await Factory.build(
'user', 'user',
@ -70,6 +75,7 @@ describe('rewards', () => {
}) })
}) })
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => { afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -11,6 +11,7 @@ const neode = getNeode()
beforeAll(async () => { beforeAll(async () => {
await cleanDatabase() await cleanDatabase()
const { server } = createServer({ const { server } = createServer({
context: () => { context: () => {
return { return {

View File

@ -31,7 +31,10 @@ const queryPost = gql`
describe('shout and unshout posts', () => { describe('shout and unshout posts', () => {
let currentUser, postAuthor let currentUser, postAuthor
beforeAll(() => {
beforeAll(async () => {
await cleanDatabase()
authenticatedUser = undefined authenticatedUser = undefined
const { server } = createServer({ const { server } = createServer({
context: () => { context: () => {
@ -45,6 +48,11 @@ describe('shout and unshout posts', () => {
mutate = createTestClient(server).mutate mutate = createTestClient(server).mutate
query = createTestClient(server).query query = createTestClient(server).query
}) })
afterAll(async () => {
await cleanDatabase()
})
beforeEach(async () => { beforeEach(async () => {
currentUser = await Factory.build( currentUser = await Factory.build(
'user', 'user',
@ -70,6 +78,8 @@ describe('shout and unshout posts', () => {
}, },
) )
}) })
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => { afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -6,6 +6,14 @@ import { getDriver } from '../../db/neo4j'
const driver = getDriver() const driver = getDriver()
beforeAll(async () => {
await cleanDatabase()
})
afterAll(async () => {
await cleanDatabase()
})
describe('SocialMedia', () => { describe('SocialMedia', () => {
let socialMediaAction, someUser, ownerNode, owner let socialMediaAction, someUser, ownerNode, owner
@ -61,6 +69,7 @@ describe('SocialMedia', () => {
} }
}) })
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => { afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -22,6 +22,8 @@ const statisticsQuery = gql`
} }
` `
beforeAll(async () => { beforeAll(async () => {
await cleanDatabase()
authenticatedUser = undefined authenticatedUser = undefined
const { server } = createServer({ const { server } = createServer({
context: () => { context: () => {
@ -33,9 +35,13 @@ beforeAll(async () => {
}, },
}) })
query = createTestClient(server).query query = createTestClient(server).query
})
afterAll(async () => {
await cleanDatabase() await cleanDatabase()
}) })
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => { afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -9,8 +9,32 @@ let query, authenticatedUser
const driver = getDriver() const driver = getDriver()
const neode = getNeode() const neode = getNeode()
const userDataQuery = gql`
query ($id: ID!) {
userData(id: $id) {
user {
id
name
slug
}
posts {
id
title
content
comments {
content
author {
slug
}
}
}
}
}
`
beforeAll(async () => { beforeAll(async () => {
await cleanDatabase() await cleanDatabase()
const user = await Factory.build('user', { const user = await Factory.build('user', {
id: 'a-user', id: 'a-user',
name: 'John Doe', name: 'John Doe',
@ -38,29 +62,6 @@ afterAll(async () => {
await cleanDatabase() await cleanDatabase()
}) })
const userDataQuery = gql`
query ($id: ID!) {
userData(id: $id) {
user {
id
name
slug
}
posts {
id
title
content
comments {
content
author {
slug
}
}
}
}
}
`
describe('resolvers/userData', () => { describe('resolvers/userData', () => {
let variables = { id: 'a-user' } let variables = { id: 'a-user' }

View File

@ -29,12 +29,9 @@ const disable = async (id) => {
]) ])
} }
beforeEach(() => { beforeAll(async () => {
user = null await cleanDatabase()
req = { headers: {} }
})
beforeAll(() => {
const { server } = createServer({ const { server } = createServer({
context: () => { context: () => {
// One of the rare occasions where we test // One of the rare occasions where we test
@ -46,6 +43,16 @@ beforeAll(() => {
mutate = createTestClient(server).mutate mutate = createTestClient(server).mutate
}) })
afterAll(async () => {
await cleanDatabase()
})
beforeEach(() => {
user = null
req = { headers: {} }
})
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => { afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -44,7 +44,6 @@ const deleteUserMutation = gql`
} }
} }
` `
const switchUserRoleMutation = gql` const switchUserRoleMutation = gql`
mutation ($role: UserGroup!, $id: ID!) { mutation ($role: UserGroup!, $id: ID!) {
switchUserRole(role: $role, id: $id) { switchUserRole(role: $role, id: $id) {
@ -57,7 +56,9 @@ const switchUserRoleMutation = gql`
} }
` `
beforeAll(() => { beforeAll(async () => {
await cleanDatabase()
const { server } = createServer({ const { server } = createServer({
context: () => { context: () => {
return { return {
@ -71,7 +72,12 @@ beforeAll(() => {
mutate = createTestClient(server).mutate mutate = createTestClient(server).mutate
}) })
beforeEach(async () => { afterAll(async () => {
await cleanDatabase()
})
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -15,7 +15,6 @@ const updateUserMutation = gql`
} }
} }
` `
const queryLocations = gql` const queryLocations = gql`
query ($place: String!, $lang: String!) { query ($place: String!, $lang: String!) {
queryLocations(place: $place, lang: $lang) { queryLocations(place: $place, lang: $lang) {
@ -24,7 +23,6 @@ const queryLocations = gql`
} }
} }
` `
const newlyCreatedNodesWithLocales = [ const newlyCreatedNodesWithLocales = [
{ {
city: { city: {
@ -74,7 +72,9 @@ const newlyCreatedNodesWithLocales = [
}, },
] ]
beforeAll(() => { beforeAll(async () => {
await cleanDatabase()
const { server } = createServer({ const { server } = createServer({
context: () => { context: () => {
return { return {
@ -88,12 +88,19 @@ beforeAll(() => {
query = createTestClient(server).query query = createTestClient(server).query
}) })
afterAll(async () => {
await cleanDatabase()
})
beforeEach(() => { beforeEach(() => {
variables = {} variables = {}
authenticatedUser = null authenticatedUser = null
}) })
afterEach(cleanDatabase) // TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => {
await cleanDatabase()
})
describe('Location Service', () => { describe('Location Service', () => {
// Authentication // Authentication

View File

@ -12,6 +12,14 @@ let mutedUser
let authenticatedUser let authenticatedUser
let server let server
beforeAll(async () => {
await cleanDatabase()
})
afterAll(async () => {
await cleanDatabase()
})
beforeEach(() => { beforeEach(() => {
authenticatedUser = undefined authenticatedUser = undefined
;({ server } = createServer({ ;({ server } = createServer({
@ -28,6 +36,7 @@ beforeEach(() => {
})) }))
}) })
// TODO: avoid database clean after each test in the future if possible for performance and flakyness reasons by filling the database step by step, see issue https://github.com/Ocelot-Social-Community/Ocelot-Social/issues/4543
afterEach(async () => { afterEach(async () => {
await cleanDatabase() await cleanDatabase()
}) })

View File

@ -13,6 +13,7 @@ let variables
beforeAll(async () => { beforeAll(async () => {
await cleanDatabase() await cleanDatabase()
const { server } = createServer({ const { server } = createServer({
context: () => { context: () => {
return { return {