Merge pull request #5964 from Ocelot-Social-Community/backend-update-jest

refactor(backend): update jest
This commit is contained in:
Moriz Wahl 2023-02-14 13:31:16 +01:00 committed by GitHub
commit 284b7cc0f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 1590 additions and 1399 deletions

View File

@ -116,7 +116,7 @@
"eslint-plugin-prettier": "~3.4.1", "eslint-plugin-prettier": "~3.4.1",
"eslint-plugin-promise": "~4.3.1", "eslint-plugin-promise": "~4.3.1",
"eslint-plugin-standard": "~4.0.1", "eslint-plugin-standard": "~4.0.1",
"jest": "~25.3.0", "jest": "29.4",
"nodemon": "~2.0.2", "nodemon": "~2.0.2",
"prettier": "~2.3.2", "prettier": "~2.3.2",
"rosie": "^2.0.1", "rosie": "^2.0.1",

View File

@ -33,6 +33,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
// 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 // 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

View File

@ -36,6 +36,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
// 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 // 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

View File

@ -50,6 +50,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
beforeEach(async () => { beforeEach(async () => {

View File

@ -80,14 +80,6 @@ const testEmailData = (emailTemplate, templateBuilder, templateData, texts) => {
return emailTemplate return emailTemplate
} }
// beforeAll(async () => {
// await cleanDatabase()
// })
// afterAll(async () => {
// await cleanDatabase()
// })
describe('templateBuilder', () => { describe('templateBuilder', () => {
describe('signupTemplate', () => { describe('signupTemplate', () => {
describe('multi language', () => { describe('multi language', () => {

View File

@ -28,6 +28,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
const createPostMutation = gql` const createPostMutation = gql`

View File

@ -56,6 +56,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
beforeEach(async () => { beforeEach(async () => {

View File

@ -24,6 +24,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
beforeEach(async () => { beforeEach(async () => {

View File

@ -28,6 +28,7 @@ describe('authorization', () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
// 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 // 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

View File

@ -33,6 +33,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
beforeEach(async () => { beforeEach(async () => {
@ -152,7 +153,7 @@ describe('slugifyMiddleware', () => {
}) })
describe('but if the client specifies a slug', () => { describe('but if the client specifies a slug', () => {
it('rejects CreateGroup', async (done) => { it('rejects CreateGroup', async () => {
try { try {
await expect( await expect(
mutate({ mutate({
@ -171,7 +172,6 @@ describe('slugifyMiddleware', () => {
}, },
], ],
}) })
done()
} catch (error) { } catch (error) {
throw new Error(` throw new Error(`
${error} ${error}
@ -258,7 +258,7 @@ describe('slugifyMiddleware', () => {
}) })
describe('setting slug explicitly', () => { describe('setting slug explicitly', () => {
it('rejects UpdateGroup', async (done) => { it('rejects UpdateGroup', async () => {
try { try {
await expect( await expect(
mutate({ mutate({
@ -275,7 +275,6 @@ describe('slugifyMiddleware', () => {
}, },
], ],
}) })
done()
} catch (error) { } catch (error) {
throw new Error(` throw new Error(`
${error} ${error}
@ -382,7 +381,7 @@ describe('slugifyMiddleware', () => {
}) })
describe('but if the client specifies a slug', () => { describe('but if the client specifies a slug', () => {
it('rejects CreatePost', async (done) => { it('rejects CreatePost', async () => {
try { try {
await expect( await expect(
mutate({ mutate({
@ -402,7 +401,6 @@ describe('slugifyMiddleware', () => {
}, },
], ],
}) })
done()
} catch (error) { } catch (error) {
throw new Error(` throw new Error(`
${error} ${error}

View File

@ -195,6 +195,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
describe('softDeleteMiddleware', () => { describe('softDeleteMiddleware', () => {

View File

@ -42,6 +42,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
describe('middleware/userInteractions', () => { describe('middleware/userInteractions', () => {

View File

@ -75,6 +75,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
beforeEach(async () => { beforeEach(async () => {

View File

@ -1,6 +1,7 @@
import { cleanDatabase } from '../db/factories' import { cleanDatabase } from '../db/factories'
import { getNeode } from '../db/neo4j' import { getNeode, getDriver } from '../db/neo4j'
const driver = getDriver()
const neode = getNeode() const neode = getNeode()
beforeAll(async () => { beforeAll(async () => {
@ -9,6 +10,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
// 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 // 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
@ -37,11 +39,10 @@ describe('slug', () => {
) )
}) })
it('must be unique', async (done) => { it('must be unique', async () => {
await neode.create('User', { slug: 'Matt' }) await neode.create('User', { slug: 'Matt' })
try { try {
await expect(neode.create('User', { slug: 'Matt' })).rejects.toThrow('already exists') await expect(neode.create('User', { slug: 'Matt' })).rejects.toThrow('already exists')
done()
} catch (error) { } catch (error) {
throw new Error(` throw new Error(`
${error} ${error}

View File

@ -25,6 +25,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
beforeEach(async () => { beforeEach(async () => {

View File

@ -37,6 +37,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
describe('donations', () => { describe('donations', () => {

View File

@ -30,6 +30,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
beforeEach(async () => { beforeEach(async () => {

View File

@ -71,6 +71,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
beforeEach(async () => { beforeEach(async () => {

View File

@ -252,6 +252,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
describe('in mode', () => { describe('in mode', () => {

View File

@ -15,6 +15,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
beforeEach(async () => { beforeEach(async () => {
@ -78,7 +79,7 @@ describe('deleteImage', () => {
await expect(someString).toEqual('Hello') await expect(someString).toEqual('Hello')
}) })
it('rolls back the transaction in case of errors', async (done) => { it('rolls back the transaction in case of errors', async () => {
await expect(neode.all('Image')).resolves.toHaveLength(1) await expect(neode.all('Image')).resolves.toHaveLength(1)
const session = driver.session() const session = driver.session()
try { try {
@ -93,7 +94,6 @@ describe('deleteImage', () => {
// nothing has been deleted // nothing has been deleted
await expect(neode.all('Image')).resolves.toHaveLength(1) await expect(neode.all('Image')).resolves.toHaveLength(1)
// all good // all good
done()
} finally { } finally {
session.close() session.close()
} }
@ -239,7 +239,7 @@ describe('mergeImage', () => {
}) })
}) })
it('rolls back the transaction in case of errors', async (done) => { it('rolls back the transaction in case of errors', async () => {
const session = driver.session() const session = driver.session()
try { try {
await session.writeTransaction(async (transaction) => { await session.writeTransaction(async (transaction) => {
@ -254,7 +254,6 @@ describe('mergeImage', () => {
// nothing has been created // nothing has been created
await expect(neode.all('Image')).resolves.toHaveLength(0) await expect(neode.all('Image')).resolves.toHaveLength(0)
// all good // all good
done()
} finally { } finally {
session.close() session.close()
} }

View File

@ -52,6 +52,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
describe('inviteCodes', () => { describe('inviteCodes', () => {

View File

@ -26,6 +26,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
// 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 // 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

View File

@ -70,6 +70,7 @@ describe('moderate resources', () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
beforeEach(async () => { beforeEach(async () => {

View File

@ -29,6 +29,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
beforeEach(async () => { beforeEach(async () => {

View File

@ -38,6 +38,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
beforeEach(() => { beforeEach(() => {

View File

@ -56,6 +56,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
beforeEach(async () => { beforeEach(async () => {

View File

@ -61,6 +61,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
describe('Posts in Groups', () => { describe('Posts in Groups', () => {

View File

@ -29,6 +29,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
beforeEach(async () => { beforeEach(async () => {

View File

@ -117,6 +117,7 @@ describe('file a report on a resource', () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
// 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 // 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

View File

@ -33,6 +33,7 @@ describe('rewards', () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
beforeEach(async () => { beforeEach(async () => {

View File

@ -26,6 +26,8 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
neode.close()
}) })
const searchQuery = gql` const searchQuery = gql`

View File

@ -51,6 +51,7 @@ describe('shout and unshout posts', () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
beforeEach(async () => { beforeEach(async () => {

View File

@ -12,6 +12,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
describe('SocialMedia', () => { describe('SocialMedia', () => {

View File

@ -39,6 +39,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
// 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 // 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

View File

@ -60,6 +60,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
describe('resolvers/userData', () => { describe('resolvers/userData', () => {

View File

@ -6,10 +6,12 @@ import { loginMutation } from '../../graphql/userManagement'
import { createTestClient } from 'apollo-server-testing' import { createTestClient } from 'apollo-server-testing'
import createServer, { context } from '../../server' import createServer, { context } from '../../server'
import encode from '../../jwt/encode' import encode from '../../jwt/encode'
import { getNeode } from '../../db/neo4j' import { getNeode, getDriver } from '../../db/neo4j'
import { categories } from '../../constants/categories' import { categories } from '../../constants/categories'
const neode = getNeode() const neode = getNeode()
const driver = getDriver()
let query, mutate, variables, req, user let query, mutate, variables, req, user
const disable = async (id) => { const disable = async (id) => {
@ -47,6 +49,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
beforeEach(() => { beforeEach(() => {
@ -137,7 +140,12 @@ describe('currentUser', () => {
describe('authenticated', () => { describe('authenticated', () => {
describe('and corresponding user in the database', () => { describe('and corresponding user in the database', () => {
let avatar
beforeEach(async () => { beforeEach(async () => {
avatar = await Factory.build('image', {
url: 'https://s3.amazonaws.com/uifaces/faces/twitter/jimmuirhead/128.jpg',
})
await Factory.build( await Factory.build(
'user', 'user',
{ {
@ -149,9 +157,7 @@ describe('currentUser', () => {
}, },
{ {
email: 'test@example.org', email: 'test@example.org',
avatar: Factory.build('image', { avatar,
url: 'https://s3.amazonaws.com/uifaces/faces/twitter/jimmuirhead/128.jpg',
}),
}, },
) )
const userBearerToken = encode({ id: 'u3' }) const userBearerToken = encode({ id: 'u3' })
@ -163,9 +169,11 @@ describe('currentUser', () => {
data: { data: {
currentUser: { currentUser: {
id: 'u3', id: 'u3',
avatar: Factory.build('image', { avatar: {
url: 'https://s3.amazonaws.com/uifaces/faces/twitter/jimmuirhead/128.jpg', url: expect.stringContaining(
}), 'https://s3.amazonaws.com/uifaces/faces/twitter/jimmuirhead/128.jpg',
),
},
email: 'test@example.org', email: 'test@example.org',
name: 'Matilde Hermiston', name: 'Matilde Hermiston',
slug: 'matilde-hermiston', slug: 'matilde-hermiston',
@ -243,7 +251,7 @@ describe('login', () => {
describe('ask for a `token`', () => { describe('ask for a `token`', () => {
describe('with a valid email/password combination', () => { describe('with a valid email/password combination', () => {
it('responds with a JWT bearer token', async (done) => { it('responds with a JWT bearer token', async () => {
const { const {
data: { login: token }, data: { login: token },
} = await mutate({ mutation: loginMutation, variables }) } = await mutate({ mutation: loginMutation, variables })
@ -252,7 +260,6 @@ describe('login', () => {
id: 'acb2d923-f3af-479e-9f00-61b12e864666', id: 'acb2d923-f3af-479e-9f00-61b12e864666',
}) })
expect(err).toBeNull() expect(err).toBeNull()
done()
}) })
}) })

View File

@ -81,6 +81,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
// 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 // 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

View File

@ -90,6 +90,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
beforeEach(() => { beforeEach(() => {

View File

@ -18,6 +18,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
beforeEach(() => { beforeEach(() => {

View File

@ -28,6 +28,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await cleanDatabase() await cleanDatabase()
driver.close()
}) })
describe('count post teaser views', () => { describe('count post teaser views', () => {

File diff suppressed because it is too large Load Diff