From f60ddda230a954116449f8c1914cff2e84485e85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Thu, 22 Jul 2021 13:34:49 +0200 Subject: [PATCH 1/2] Fix as quick fix for first backend tests --- backend/src/activitypub/routes/webfinger.spec.js | 9 +++++++++ backend/src/jwt/decode.spec.js | 9 +++++++++ backend/src/middleware/orderByMiddleware.spec.js | 9 +++++++++ backend/src/middleware/permissionsMiddleware.spec.js | 6 ++++++ 4 files changed, 33 insertions(+) diff --git a/backend/src/activitypub/routes/webfinger.spec.js b/backend/src/activitypub/routes/webfinger.spec.js index 528490541..8b0e5ff55 100644 --- a/backend/src/activitypub/routes/webfinger.spec.js +++ b/backend/src/activitypub/routes/webfinger.spec.js @@ -27,6 +27,15 @@ const request = () => { return handler(req, res) } +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 () => { await cleanDatabase() }) diff --git a/backend/src/jwt/decode.spec.js b/backend/src/jwt/decode.spec.js index 80dfe9733..78ceadecb 100644 --- a/backend/src/jwt/decode.spec.js +++ b/backend/src/jwt/decode.spec.js @@ -24,6 +24,15 @@ const neode = getNeode() export const validAuthorizationHeader = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoidXNlciIsImxvY2F0aW9uTmFtZSI6bnVsbCwibmFtZSI6Ikplbm55IFJvc3RvY2siLCJhYm91dCI6bnVsbCwiYXZhdGFyIjoiaHR0cHM6Ly9zMy5hbWF6b25hd3MuY29tL3VpZmFjZXMvZmFjZXMvdHdpdHRlci9zYXNoYV9zaGVzdGFrb3YvMTI4LmpwZyIsImlkIjoidTMiLCJlbWFpbCI6InVzZXJAZXhhbXBsZS5vcmciLCJzbHVnIjoiamVubnktcm9zdG9jayIsImlhdCI6MTU1MDg0NjY4MCwiZXhwIjoxNjM3MjQ2NjgwLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjMwMDAiLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjQwMDAiLCJzdWIiOiJ1MyJ9.eZ_mVKas4Wzoc_JrQTEWXyRn7eY64cdIg4vqQ-F_7Jc' +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 () => { await cleanDatabase() }) diff --git a/backend/src/middleware/orderByMiddleware.spec.js b/backend/src/middleware/orderByMiddleware.spec.js index 91caa1f54..cc3cf7a94 100644 --- a/backend/src/middleware/orderByMiddleware.spec.js +++ b/backend/src/middleware/orderByMiddleware.spec.js @@ -18,6 +18,14 @@ const { server } = createServer({ }) const { query } = createTestClient(server) +beforeAll(async () => { + await cleanDatabase() +}) + +afterAll(async () => { + await cleanDatabase() +}) + beforeEach(async () => { await neode.create('Post', { title: 'first' }) await neode.create('Post', { title: 'second' }) @@ -25,6 +33,7 @@ beforeEach(async () => { await neode.create('Post', { title: 'last' }) }) +// 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() }) diff --git a/backend/src/middleware/permissionsMiddleware.spec.js b/backend/src/middleware/permissionsMiddleware.spec.js index 5fa4a8f01..80e3dc05c 100644 --- a/backend/src/middleware/permissionsMiddleware.spec.js +++ b/backend/src/middleware/permissionsMiddleware.spec.js @@ -14,6 +14,7 @@ let authenticatedUser, owner, anotherRegularUser, administrator, moderator describe('authorization', () => { beforeAll(async () => { await cleanDatabase() + const { server } = createServer({ context: () => ({ driver, @@ -25,6 +26,11 @@ describe('authorization', () => { 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 () => { await cleanDatabase() }) From 62de9a158e27e1bd14a6ac734508e18659233fb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Mon, 26 Jul 2021 11:36:42 +0200 Subject: [PATCH 2/2] Fix as quick fix for all reminding tests --- LICENSE.md | 1 - .../hashtags/hashtagsMiddleware.spec.js | 9 +++- .../middleware/languages/languages.spec.js | 3 +- .../notificationsMiddleware.spec.js | 6 +++ .../src/middleware/slugifyMiddleware.spec.js | 6 +++ .../softDelete/softDeleteMiddleware.spec.js | 2 + .../src/middleware/userInteractions.spec.js | 1 + .../validation/validationMiddleware.spec.js | 11 ++++- backend/src/models/User.spec.js | 9 ++++ backend/src/schema/resolvers/comments.spec.js | 6 +++ .../src/schema/resolvers/donations.spec.js | 9 ++++ backend/src/schema/resolvers/emails.spec.js | 14 ++++-- backend/src/schema/resolvers/follow.spec.js | 8 +++- .../schema/resolvers/images/images.spec.js | 14 +++++- .../src/schema/resolvers/inviteCodes.spec.js | 3 +- .../src/schema/resolvers/locations.spec.js | 9 +++- .../src/schema/resolvers/moderation.spec.js | 6 +++ .../schema/resolvers/notifications.spec.js | 9 +++- .../schema/resolvers/passwordReset.spec.js | 15 ++++-- backend/src/schema/resolvers/posts.spec.js | 6 +++ .../src/schema/resolvers/registration.spec.js | 14 ++++-- backend/src/schema/resolvers/reports.spec.js | 6 +++ backend/src/schema/resolvers/rewards.spec.js | 6 +++ backend/src/schema/resolvers/searches.spec.js | 1 + backend/src/schema/resolvers/shout.spec.js | 12 ++++- .../src/schema/resolvers/socialMedia.spec.js | 9 ++++ .../src/schema/resolvers/statistics.spec.js | 6 +++ backend/src/schema/resolvers/userData.spec.js | 47 ++++++++++--------- .../schema/resolvers/user_management.spec.js | 17 +++++-- backend/src/schema/resolvers/users.spec.js | 12 +++-- .../schema/resolvers/users/location.spec.js | 15 ++++-- .../schema/resolvers/users/mutedUsers.spec.js | 9 ++++ .../resolvers/viewedTeaserCount.spec.js | 1 + 33 files changed, 242 insertions(+), 60 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 646ae3a6d..c0d3b6e18 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -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 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. - diff --git a/backend/src/middleware/hashtags/hashtagsMiddleware.spec.js b/backend/src/middleware/hashtags/hashtagsMiddleware.spec.js index 613bd6b62..19f60556f 100644 --- a/backend/src/middleware/hashtags/hashtagsMiddleware.spec.js +++ b/backend/src/middleware/hashtags/hashtagsMiddleware.spec.js @@ -30,7 +30,9 @@ const updatePostMutation = gql` } ` -beforeAll(() => { +beforeAll(async () => { + await cleanDatabase() + const createServerResult = createServer({ context: () => { return { @@ -46,6 +48,10 @@ beforeAll(() => { mutate = createTestClientResult.mutate }) +afterAll(async () => { + await cleanDatabase() +}) + beforeEach(async () => { hashtagingUser = await neode.create( '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 () => { await cleanDatabase() }) diff --git a/backend/src/middleware/languages/languages.spec.js b/backend/src/middleware/languages/languages.spec.js index 9bba45c0c..b22de9148 100644 --- a/backend/src/middleware/languages/languages.spec.js +++ b/backend/src/middleware/languages/languages.spec.js @@ -12,6 +12,8 @@ const driver = getDriver() const neode = getNeode() beforeAll(async () => { + await cleanDatabase() + const { server } = createServer({ context: () => { return { @@ -43,7 +45,6 @@ describe('languagesMiddleware', () => { } beforeAll(async () => { - await cleanDatabase() const user = await Factory.build('user') authenticatedUser = await user.toJson() await Factory.build('category', { diff --git a/backend/src/middleware/notifications/notificationsMiddleware.spec.js b/backend/src/middleware/notifications/notificationsMiddleware.spec.js index 7583a6727..6c06ac072 100644 --- a/backend/src/middleware/notifications/notificationsMiddleware.spec.js +++ b/backend/src/middleware/notifications/notificationsMiddleware.spec.js @@ -37,6 +37,7 @@ const createCommentMutation = gql` beforeAll(async () => { await cleanDatabase() + publishSpy = jest.spyOn(pubsub, 'publish') const createServerResult = createServer({ context: () => { @@ -53,6 +54,10 @@ beforeAll(async () => { mutate = createTestClientResult.mutate }) +afterAll(async () => { + await cleanDatabase() +}) + beforeEach(async () => { publishSpy.mockClear() 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 () => { await cleanDatabase() }) diff --git a/backend/src/middleware/slugifyMiddleware.spec.js b/backend/src/middleware/slugifyMiddleware.spec.js index 1f45c29df..9f1969c0c 100644 --- a/backend/src/middleware/slugifyMiddleware.spec.js +++ b/backend/src/middleware/slugifyMiddleware.spec.js @@ -13,6 +13,7 @@ const neode = getNeode() beforeAll(async () => { await cleanDatabase() + const { server } = createServer({ context: () => { return { @@ -25,6 +26,10 @@ beforeAll(async () => { mutate = createTestClient(server).mutate }) +afterAll(async () => { + await cleanDatabase() +}) + beforeEach(async () => { variables = {} const admin = await Factory.build('user', { @@ -46,6 +51,7 @@ beforeEach(async () => { 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 () => { await cleanDatabase() }) diff --git a/backend/src/middleware/softDelete/softDeleteMiddleware.spec.js b/backend/src/middleware/softDelete/softDeleteMiddleware.spec.js index 63569ddb0..a4d32c4a7 100644 --- a/backend/src/middleware/softDelete/softDeleteMiddleware.spec.js +++ b/backend/src/middleware/softDelete/softDeleteMiddleware.spec.js @@ -15,6 +15,8 @@ const action = () => { } beforeAll(async () => { + await cleanDatabase() + // For performance reasons we do this only once const users = await Promise.all([ Factory.build('user', { id: 'u1', role: 'user' }), diff --git a/backend/src/middleware/userInteractions.spec.js b/backend/src/middleware/userInteractions.spec.js index 27bee87c8..3846e1e8e 100644 --- a/backend/src/middleware/userInteractions.spec.js +++ b/backend/src/middleware/userInteractions.spec.js @@ -19,6 +19,7 @@ const postQuery = gql` beforeAll(async () => { await cleanDatabase() + aUser = await Factory.build('user', { id: 'a-user', }) diff --git a/backend/src/middleware/validation/validationMiddleware.spec.js b/backend/src/middleware/validation/validationMiddleware.spec.js index 530a80b1e..b6bcafa9b 100644 --- a/backend/src/middleware/validation/validationMiddleware.spec.js +++ b/backend/src/middleware/validation/validationMiddleware.spec.js @@ -50,7 +50,6 @@ const reviewMutation = gql` } } ` - const updateUserMutation = gql` mutation ($id: ID!, $name: String) { UpdateUser(id: $id, name: $name) { @@ -58,7 +57,10 @@ const updateUserMutation = gql` } } ` -beforeAll(() => { + +beforeAll(async () => { + await cleanDatabase() + const { server } = createServer({ context: () => { return { @@ -71,6 +73,10 @@ beforeAll(() => { mutate = createTestClient(server).mutate }) +afterAll(async () => { + await cleanDatabase() +}) + beforeEach(async () => { users = await Promise.all([ Factory.build('user', { @@ -120,6 +126,7 @@ beforeEach(async () => { 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 () => { await cleanDatabase() }) diff --git a/backend/src/models/User.spec.js b/backend/src/models/User.spec.js index 7d7f391b0..102acde6a 100644 --- a/backend/src/models/User.spec.js +++ b/backend/src/models/User.spec.js @@ -3,6 +3,15 @@ import { getNeode } from '../db/neo4j' 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 () => { await cleanDatabase() }) diff --git a/backend/src/schema/resolvers/comments.spec.js b/backend/src/schema/resolvers/comments.spec.js index 63a5538d0..cbd2b98fc 100644 --- a/backend/src/schema/resolvers/comments.spec.js +++ b/backend/src/schema/resolvers/comments.spec.js @@ -11,6 +11,7 @@ let variables, mutate, authenticatedUser, commentAuthor, newlyCreatedComment beforeAll(async () => { await cleanDatabase() + const { server } = createServer({ context: () => { return { @@ -22,6 +23,10 @@ beforeAll(async () => { mutate = createTestClient(server).mutate }) +afterAll(async () => { + await cleanDatabase() +}) + beforeEach(async () => { variables = {} 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 () => { await cleanDatabase() }) diff --git a/backend/src/schema/resolvers/donations.spec.js b/backend/src/schema/resolvers/donations.spec.js index 5bbbd60e0..32c502c29 100644 --- a/backend/src/schema/resolvers/donations.spec.js +++ b/backend/src/schema/resolvers/donations.spec.js @@ -29,6 +29,14 @@ const donationsQuery = gql` } ` +beforeAll(async () => { + await cleanDatabase() +}) + +afterAll(async () => { + await cleanDatabase() +}) + describe('donations', () => { let currentUser, newlyCreatedDonations beforeAll(async () => { @@ -52,6 +60,7 @@ describe('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 () => { await cleanDatabase() }) diff --git a/backend/src/schema/resolvers/emails.spec.js b/backend/src/schema/resolvers/emails.spec.js index c5596cc27..60f5ae899 100644 --- a/backend/src/schema/resolvers/emails.spec.js +++ b/backend/src/schema/resolvers/emails.spec.js @@ -12,12 +12,9 @@ let user let variables const driver = getDriver() -beforeEach(async () => { - variables = {} -}) - beforeAll(async () => { await cleanDatabase() + const { server } = createServer({ context: () => { return { @@ -31,6 +28,15 @@ beforeAll(async () => { 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 () => { await cleanDatabase() }) diff --git a/backend/src/schema/resolvers/follow.spec.js b/backend/src/schema/resolvers/follow.spec.js index 6d8db982a..9cc8403e5 100644 --- a/backend/src/schema/resolvers/follow.spec.js +++ b/backend/src/schema/resolvers/follow.spec.js @@ -27,7 +27,6 @@ const mutationFollowUser = gql` } } ` - const mutationUnfollowUser = gql` mutation ($id: ID!) { unfollowUser(id: $id) { @@ -40,7 +39,6 @@ const mutationUnfollowUser = gql` } } ` - const userQuery = gql` query ($id: ID) { User(id: $id) { @@ -54,6 +52,7 @@ const userQuery = gql` beforeAll(async () => { await cleanDatabase() + const { server } = createServer({ context: () => ({ driver, @@ -70,6 +69,10 @@ beforeAll(async () => { mutate = testClient.mutate }) +afterAll(async () => { + await cleanDatabase() +}) + beforeEach(async () => { user1 = await Factory.build( 'user', @@ -98,6 +101,7 @@ beforeEach(async () => { 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 () => { await cleanDatabase() }) diff --git a/backend/src/schema/resolvers/images/images.spec.js b/backend/src/schema/resolvers/images/images.spec.js index 42064621c..5ede151a9 100644 --- a/backend/src/schema/resolvers/images/images.spec.js +++ b/backend/src/schema/resolvers/images/images.spec.js @@ -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 deleteCallback -beforeEach(async () => { +beforeAll(async () => { await cleanDatabase() +}) + +afterAll(async () => { + await cleanDatabase() +}) + +beforeEach(async () => { uploadCallback = jest.fn(({ uniqueFilename }) => `/uploads/${uniqueFilename}`) 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('given a resource with an image', () => { let user diff --git a/backend/src/schema/resolvers/inviteCodes.spec.js b/backend/src/schema/resolvers/inviteCodes.spec.js index 940aa8403..094716871 100644 --- a/backend/src/schema/resolvers/inviteCodes.spec.js +++ b/backend/src/schema/resolvers/inviteCodes.spec.js @@ -19,7 +19,6 @@ const generateInviteCodeMutation = gql` } } ` - const myInviteCodesQuery = gql` query { MyInviteCodes { @@ -29,7 +28,6 @@ const myInviteCodesQuery = gql` } } ` - const isValidInviteCodeQuery = gql` query ($code: ID!) { isValidInviteCode(code: $code) @@ -38,6 +36,7 @@ const isValidInviteCodeQuery = gql` beforeAll(async () => { await cleanDatabase() + const { server } = createServer({ context: () => { return { diff --git a/backend/src/schema/resolvers/locations.spec.js b/backend/src/schema/resolvers/locations.spec.js index fa562cbfd..3742c59c6 100644 --- a/backend/src/schema/resolvers/locations.spec.js +++ b/backend/src/schema/resolvers/locations.spec.js @@ -9,7 +9,9 @@ let mutate, authenticatedUser const driver = getDriver() const neode = getNeode() -beforeAll(() => { +beforeAll(async () => { + await cleanDatabase() + const { server } = createServer({ context: () => { return { @@ -22,6 +24,11 @@ beforeAll(() => { 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 () => { await cleanDatabase() }) diff --git a/backend/src/schema/resolvers/moderation.spec.js b/backend/src/schema/resolvers/moderation.spec.js index a579c62da..662be41bd 100644 --- a/backend/src/schema/resolvers/moderation.spec.js +++ b/backend/src/schema/resolvers/moderation.spec.js @@ -54,6 +54,7 @@ const reviewMutation = gql` describe('moderate resources', () => { beforeAll(async () => { await cleanDatabase() + authenticatedUser = undefined const { server } = createServer({ context: () => { @@ -67,6 +68,10 @@ describe('moderate resources', () => { mutate = createTestClient(server).mutate }) + afterAll(async () => { + await cleanDatabase() + }) + beforeEach(async () => { disableVariables = { 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 () => { await cleanDatabase() }) diff --git a/backend/src/schema/resolvers/notifications.spec.js b/backend/src/schema/resolvers/notifications.spec.js index f600e7d1c..2ea468914 100644 --- a/backend/src/schema/resolvers/notifications.spec.js +++ b/backend/src/schema/resolvers/notifications.spec.js @@ -12,7 +12,9 @@ let variables let query let mutate -beforeAll(() => { +beforeAll(async () => { + await cleanDatabase() + const { server } = createServer({ context: () => { return { @@ -25,11 +27,16 @@ beforeAll(() => { mutate = createTestClient(server).mutate }) +afterAll(async () => { + await cleanDatabase() +}) + beforeEach(async () => { authenticatedUser = null 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 () => { await cleanDatabase() }) diff --git a/backend/src/schema/resolvers/passwordReset.spec.js b/backend/src/schema/resolvers/passwordReset.spec.js index 40a18f5d9..0a66a7a64 100644 --- a/backend/src/schema/resolvers/passwordReset.spec.js +++ b/backend/src/schema/resolvers/passwordReset.spec.js @@ -20,11 +20,9 @@ const getAllPasswordResets = async () => { return resets } -beforeEach(() => { - variables = {} -}) +beforeAll(async () => { + await cleanDatabase() -beforeAll(() => { const { server } = createServer({ context: () => { return { @@ -37,6 +35,15 @@ beforeAll(() => { 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 () => { await cleanDatabase() }) diff --git a/backend/src/schema/resolvers/posts.spec.js b/backend/src/schema/resolvers/posts.spec.js index 20dbecfb6..2c8b7e90b 100644 --- a/backend/src/schema/resolvers/posts.spec.js +++ b/backend/src/schema/resolvers/posts.spec.js @@ -40,6 +40,7 @@ const createPostMutation = gql` beforeAll(async () => { await cleanDatabase() + const { server } = createServer({ context: () => { return { @@ -53,6 +54,10 @@ beforeAll(async () => { mutate = createTestClient(server).mutate }) +afterAll(async () => { + await cleanDatabase() +}) + beforeEach(async () => { variables = {} user = await Factory.build( @@ -91,6 +96,7 @@ beforeEach(async () => { 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 () => { await cleanDatabase() }) diff --git a/backend/src/schema/resolvers/registration.spec.js b/backend/src/schema/resolvers/registration.spec.js index 25e8fd1c8..753639118 100644 --- a/backend/src/schema/resolvers/registration.spec.js +++ b/backend/src/schema/resolvers/registration.spec.js @@ -12,12 +12,9 @@ let authenticatedUser let variables const driver = getDriver() -beforeEach(async () => { - variables = {} -}) - beforeAll(async () => { await cleanDatabase() + const { server } = createServer({ context: () => { return { @@ -30,6 +27,15 @@ beforeAll(async () => { 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 () => { await cleanDatabase() }) diff --git a/backend/src/schema/resolvers/reports.spec.js b/backend/src/schema/resolvers/reports.spec.js index 1208db7fe..09d0869fc 100644 --- a/backend/src/schema/resolvers/reports.spec.js +++ b/backend/src/schema/resolvers/reports.spec.js @@ -101,6 +101,7 @@ describe('file a report on a resource', () => { beforeAll(async () => { await cleanDatabase() + const { server } = createServer({ context: () => { return { @@ -114,6 +115,11 @@ describe('file a report on a resource', () => { 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 () => { await cleanDatabase() }) diff --git a/backend/src/schema/resolvers/rewards.spec.js b/backend/src/schema/resolvers/rewards.spec.js index 0f76e1ed1..718378699 100644 --- a/backend/src/schema/resolvers/rewards.spec.js +++ b/backend/src/schema/resolvers/rewards.spec.js @@ -17,6 +17,7 @@ describe('rewards', () => { beforeAll(async () => { await cleanDatabase() + const { server } = createServer({ context: () => { return { @@ -30,6 +31,10 @@ describe('rewards', () => { mutate = createTestClient(server).mutate }) + afterAll(async () => { + await cleanDatabase() + }) + beforeEach(async () => { regularUser = await Factory.build( '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 () => { await cleanDatabase() }) diff --git a/backend/src/schema/resolvers/searches.spec.js b/backend/src/schema/resolvers/searches.spec.js index ceb63304e..4a8623df5 100644 --- a/backend/src/schema/resolvers/searches.spec.js +++ b/backend/src/schema/resolvers/searches.spec.js @@ -11,6 +11,7 @@ const neode = getNeode() beforeAll(async () => { await cleanDatabase() + const { server } = createServer({ context: () => { return { diff --git a/backend/src/schema/resolvers/shout.spec.js b/backend/src/schema/resolvers/shout.spec.js index 383bd83f0..a4e9890d5 100644 --- a/backend/src/schema/resolvers/shout.spec.js +++ b/backend/src/schema/resolvers/shout.spec.js @@ -31,7 +31,10 @@ const queryPost = gql` describe('shout and unshout posts', () => { let currentUser, postAuthor - beforeAll(() => { + + beforeAll(async () => { + await cleanDatabase() + authenticatedUser = undefined const { server } = createServer({ context: () => { @@ -45,6 +48,11 @@ describe('shout and unshout posts', () => { mutate = createTestClient(server).mutate query = createTestClient(server).query }) + + afterAll(async () => { + await cleanDatabase() + }) + beforeEach(async () => { currentUser = await Factory.build( '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 () => { await cleanDatabase() }) diff --git a/backend/src/schema/resolvers/socialMedia.spec.js b/backend/src/schema/resolvers/socialMedia.spec.js index cff20185b..bb7886c3f 100644 --- a/backend/src/schema/resolvers/socialMedia.spec.js +++ b/backend/src/schema/resolvers/socialMedia.spec.js @@ -6,6 +6,14 @@ import { getDriver } from '../../db/neo4j' const driver = getDriver() +beforeAll(async () => { + await cleanDatabase() +}) + +afterAll(async () => { + await cleanDatabase() +}) + describe('SocialMedia', () => { 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 () => { await cleanDatabase() }) diff --git a/backend/src/schema/resolvers/statistics.spec.js b/backend/src/schema/resolvers/statistics.spec.js index 0aedd0cef..b9fdd9196 100644 --- a/backend/src/schema/resolvers/statistics.spec.js +++ b/backend/src/schema/resolvers/statistics.spec.js @@ -22,6 +22,8 @@ const statisticsQuery = gql` } ` beforeAll(async () => { + await cleanDatabase() + authenticatedUser = undefined const { server } = createServer({ context: () => { @@ -33,9 +35,13 @@ beforeAll(async () => { }, }) 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 () => { await cleanDatabase() }) diff --git a/backend/src/schema/resolvers/userData.spec.js b/backend/src/schema/resolvers/userData.spec.js index 0a4e54295..779f090e4 100644 --- a/backend/src/schema/resolvers/userData.spec.js +++ b/backend/src/schema/resolvers/userData.spec.js @@ -9,8 +9,32 @@ let query, authenticatedUser const driver = getDriver() 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 () => { await cleanDatabase() + const user = await Factory.build('user', { id: 'a-user', name: 'John Doe', @@ -38,29 +62,6 @@ afterAll(async () => { 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', () => { let variables = { id: 'a-user' } diff --git a/backend/src/schema/resolvers/user_management.spec.js b/backend/src/schema/resolvers/user_management.spec.js index 57fe4a7f4..2dcb14855 100644 --- a/backend/src/schema/resolvers/user_management.spec.js +++ b/backend/src/schema/resolvers/user_management.spec.js @@ -29,12 +29,9 @@ const disable = async (id) => { ]) } -beforeEach(() => { - user = null - req = { headers: {} } -}) +beforeAll(async () => { + await cleanDatabase() -beforeAll(() => { const { server } = createServer({ context: () => { // One of the rare occasions where we test @@ -46,6 +43,16 @@ beforeAll(() => { 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 () => { await cleanDatabase() }) diff --git a/backend/src/schema/resolvers/users.spec.js b/backend/src/schema/resolvers/users.spec.js index 6fd893240..102d2f6fe 100644 --- a/backend/src/schema/resolvers/users.spec.js +++ b/backend/src/schema/resolvers/users.spec.js @@ -44,7 +44,6 @@ const deleteUserMutation = gql` } } ` - const switchUserRoleMutation = gql` mutation ($role: UserGroup!, $id: ID!) { switchUserRole(role: $role, id: $id) { @@ -57,7 +56,9 @@ const switchUserRoleMutation = gql` } ` -beforeAll(() => { +beforeAll(async () => { + await cleanDatabase() + const { server } = createServer({ context: () => { return { @@ -71,7 +72,12 @@ beforeAll(() => { 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() }) diff --git a/backend/src/schema/resolvers/users/location.spec.js b/backend/src/schema/resolvers/users/location.spec.js index c966fe720..f4ff08fb0 100644 --- a/backend/src/schema/resolvers/users/location.spec.js +++ b/backend/src/schema/resolvers/users/location.spec.js @@ -15,7 +15,6 @@ const updateUserMutation = gql` } } ` - const queryLocations = gql` query ($place: String!, $lang: String!) { queryLocations(place: $place, lang: $lang) { @@ -24,7 +23,6 @@ const queryLocations = gql` } } ` - const newlyCreatedNodesWithLocales = [ { city: { @@ -74,7 +72,9 @@ const newlyCreatedNodesWithLocales = [ }, ] -beforeAll(() => { +beforeAll(async () => { + await cleanDatabase() + const { server } = createServer({ context: () => { return { @@ -88,12 +88,19 @@ beforeAll(() => { query = createTestClient(server).query }) +afterAll(async () => { + await cleanDatabase() +}) + beforeEach(() => { variables = {} 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', () => { // Authentication diff --git a/backend/src/schema/resolvers/users/mutedUsers.spec.js b/backend/src/schema/resolvers/users/mutedUsers.spec.js index c86cf2eb1..36b526268 100644 --- a/backend/src/schema/resolvers/users/mutedUsers.spec.js +++ b/backend/src/schema/resolvers/users/mutedUsers.spec.js @@ -12,6 +12,14 @@ let mutedUser let authenticatedUser let server +beforeAll(async () => { + await cleanDatabase() +}) + +afterAll(async () => { + await cleanDatabase() +}) + beforeEach(() => { authenticatedUser = undefined ;({ 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 () => { await cleanDatabase() }) diff --git a/backend/src/schema/resolvers/viewedTeaserCount.spec.js b/backend/src/schema/resolvers/viewedTeaserCount.spec.js index ceb95c0ed..7f8e7f102 100644 --- a/backend/src/schema/resolvers/viewedTeaserCount.spec.js +++ b/backend/src/schema/resolvers/viewedTeaserCount.spec.js @@ -13,6 +13,7 @@ let variables beforeAll(async () => { await cleanDatabase() + const { server } = createServer({ context: () => { return {