From 7906307a8fb559ab764b4bc41d4ebe21e83a31f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20Jedlicska?= Date: Thu, 31 Mar 2022 15:21:13 +0200 Subject: [PATCH] fix(server tests): fixed all non awaited rejected promisses --- packages/server/.mocharc.js | 3 ++- packages/server/.vscode/launch.json | 9 ++++++++- .../server/modules/auth/tests/apps.spec.js | 10 +++++----- .../server/modules/auth/tests/auth.spec.js | 1 + .../modules/comments/tests/comments.spec.js | 20 +++++++++---------- .../server/modules/core/tests/generic.spec.js | 14 ++++++------- .../server/modules/core/tests/streams.spec.js | 2 +- .../server/modules/core/tests/users.spec.js | 2 +- .../serverinvites/tests/serverInvites.spec.js | 16 +++++++-------- packages/server/test/hooks.js | 2 ++ 10 files changed, 45 insertions(+), 34 deletions(-) diff --git a/packages/server/.mocharc.js b/packages/server/.mocharc.js index 33c200d73..95bb6e740 100644 --- a/packages/server/.mocharc.js +++ b/packages/server/.mocharc.js @@ -5,7 +5,8 @@ const config = { spec: ['modules/**/*.spec.js'], require: 'test/hooks.js', slow: 0, - timeout: '10000', + // timeout: '15000', + timeout: '1500000000000', exit: true } diff --git a/packages/server/.vscode/launch.json b/packages/server/.vscode/launch.json index f959c56af..d46b1d2ef 100644 --- a/packages/server/.vscode/launch.json +++ b/packages/server/.vscode/launch.json @@ -44,7 +44,14 @@ { "name": "NPM test", "request": "launch", - "runtimeArgs": ["run-script", "test", "--", "-g='Comments @comments'", "--exit"], + "runtimeArgs": [ + "run-script", + "test", + "--", + // "-g='@apps-api'", + "--exit", + "--timeout=0" + ], "console": "integratedTerminal", "env": { // "POSTGRES_URL": "postgres://speckle:speckle@localhost/speckle2_test", diff --git a/packages/server/modules/auth/tests/apps.spec.js b/packages/server/modules/auth/tests/apps.spec.js index d93d2146b..3c0e22e97 100644 --- a/packages/server/modules/auth/tests/apps.spec.js +++ b/packages/server/modules/auth/tests/apps.spec.js @@ -85,7 +85,7 @@ describe('Services @apps-services', () => { }) it('Should fail to register an app with no scopes', async () => { - createApp({ name: 'test application2', redirectUrl: 'http://localhost:1335' }) + await createApp({ name: 'test application2', redirectUrl: 'http://localhost:1335' }) .then(() => { throw new Error('this should have been rejected') }) @@ -192,7 +192,7 @@ describe('Services @apps-services', () => { let validationResponse = await validateToken(apiTokenResponse.token) expect(validationResponse.valid).to.equal(false) - refreshAppToken({ + await refreshAppToken({ refreshToken: apiTokenResponse.refreshToken, appId: myTestApp.id, appSecret: myTestApp.secret @@ -202,7 +202,7 @@ describe('Services @apps-services', () => { }) .catch((err) => expect(err.message).to.equal('Invalid request')) - createAppTokenFromAccessCode({ + await createAppTokenFromAccessCode({ appId: myTestApp.id, appSecret: myTestApp.secret, accessCode: unusedAccessCode, @@ -239,7 +239,7 @@ describe('Services @apps-services', () => { userId: secondUser.id }) - refreshAppToken({ + await refreshAppToken({ refreshToken: apiTokenResponse.refreshToken, appId: myTestApp.id, appSecret: myTestApp.secret @@ -255,7 +255,7 @@ describe('Services @apps-services', () => { challenge }) - createAppTokenFromAccessCode({ + await createAppTokenFromAccessCode({ appId: myTestApp.id, appSecret: myTestApp.secret, accessCode: unusedAccessCode, diff --git a/packages/server/modules/auth/tests/auth.spec.js b/packages/server/modules/auth/tests/auth.spec.js index bd249b3a7..f60ee6589 100644 --- a/packages/server/modules/auth/tests/auth.spec.js +++ b/packages/server/modules/auth/tests/auth.spec.js @@ -19,6 +19,7 @@ let server describe('Auth @auth', () => { describe('Local authN & authZ (token endpoints)', () => { before(async () => { + console.log('before auth') ;({ app } = await beforeEachContext()) ;({ server, sendRequest } = await initializeTestServer(app)) }) diff --git a/packages/server/modules/comments/tests/comments.spec.js b/packages/server/modules/comments/tests/comments.spec.js index d4d98c4da..4aea3c96f 100644 --- a/packages/server/modules/comments/tests/comments.spec.js +++ b/packages/server/modules/comments/tests/comments.spec.js @@ -80,7 +80,7 @@ describe('Comments @comments', () => { }) it('Should not be allowed to comment without specifying at least one target resource', async () => { - return await createComment({ + await createComment({ userId: user.id, input: { streamId: stream.id, @@ -129,7 +129,7 @@ describe('Comments @comments', () => { }) // create a comment on streamA but objectB - createComment({ + await createComment({ userId: user.id, input: { streamId: streamA.id, @@ -142,7 +142,7 @@ describe('Comments @comments', () => { .catch((error) => expect(error.message).to.be.equal('Object not found')) // create a comment on streamA but commitB - createComment({ + await createComment({ userId: user.id, input: { streamId: streamA.id, @@ -155,7 +155,7 @@ describe('Comments @comments', () => { .catch((error) => expect(error.message).to.be.equal('Commit not found')) // mixed bag of resources (A, B) - createComment({ + await createComment({ userId: user.id, input: { streamId: streamA.id, @@ -183,7 +183,7 @@ describe('Comments @comments', () => { }) // replies should also not be swappable - createCommentReply({ + await createCommentReply({ authorId: user.id, parentCommentId: correctCommentId, streamId: streamB.id, @@ -351,7 +351,7 @@ describe('Comments @comments', () => { }) it('Should not be allowed to comment targeting multiple streams as a resource', async () => { - return await createComment({ + await createComment({ userId: user.id, input: { streamId: stream.id, @@ -714,7 +714,7 @@ describe('Comments @comments', () => { }) it('Should not be allowed to edit a not existing comment', async () => { - editComment({ userId: user.id, input: { id: 'this is not going to be found' } }) + await editComment({ userId: user.id, input: { id: 'this is not going to be found' } }) .then(() => { throw new Error('This should have been rejected') }) @@ -738,7 +738,7 @@ describe('Comments @comments', () => { } }) - editComment({ userId: otherUser.id, input: { id: commentId, text: 'properText' } }) + await editComment({ userId: otherUser.id, input: { id: commentId, text: 'properText' } }) .then(() => { throw new Error('This should have been rejected') }) @@ -780,7 +780,7 @@ describe('Comments @comments', () => { }) it('Should not be allowed to archive a not existing comment', async () => { - archiveComment({ commentId: 'badabumm', streamId: stream.id, userId: user.id }) + await archiveComment({ commentId: 'badabumm', streamId: stream.id, userId: user.id }) .then(() => { throw new Error('This should have been rejected') }) @@ -802,7 +802,7 @@ describe('Comments @comments', () => { } }) - archiveComment({ commentId, streamId: stream.id, userId: otherUser.id }) + await archiveComment({ commentId, streamId: stream.id, userId: otherUser.id }) .then(() => { throw new Error('This should have been rejected') }) diff --git a/packages/server/modules/core/tests/generic.spec.js b/packages/server/modules/core/tests/generic.spec.js index 43d490e91..dae8888ec 100644 --- a/packages/server/modules/core/tests/generic.spec.js +++ b/packages/server/modules/core/tests/generic.spec.js @@ -17,7 +17,7 @@ describe('Generic AuthN & AuthZ controller tests', () => { }) it('Validate scopes', async () => { - validateScopes() + await validateScopes() .then(() => { throw new Error('This should have been rejected') }) @@ -25,7 +25,7 @@ describe('Generic AuthN & AuthZ controller tests', () => { expect('You do not have the required privileges.').to.equal(err.message) ) - validateScopes(['a'], 'b') + await validateScopes(['a'], 'b') .then(() => { throw new Error('This should have been rejected') }) @@ -48,7 +48,7 @@ describe('Generic AuthN & AuthZ controller tests', () => { }) it('Should validate server role', async () => { - validateServerRole({ auth: true, role: 'server:user' }, 'server:admin') + await validateServerRole({ auth: true, role: 'server:user' }, 'server:admin') .then(() => { throw new Error('This should have been rejected') }) @@ -56,13 +56,13 @@ describe('Generic AuthN & AuthZ controller tests', () => { expect('You do not have the required server role').to.equal(err.message) ) - validateServerRole({ auth: true, role: 'HACZOR' }, '133TCR3w') + await validateServerRole({ auth: true, role: 'HACZOR' }, '133TCR3w') .then(() => { throw new Error('This should have been rejected') }) .catch((err) => expect('Invalid server role specified').to.equal(err.message)) - validateServerRole({ auth: true, role: 'server:admin' }, '133TCR3w') + await validateServerRole({ auth: true, role: 'server:admin' }, '133TCR3w') .then(() => { throw new Error('This should have been rejected') }) @@ -76,14 +76,14 @@ describe('Generic AuthN & AuthZ controller tests', () => { }) it('Resolver Authorization Should fail nicely when roles & resources are wanky', async () => { - authorizeResolver(null, 'foo', 'bar') + await authorizeResolver(null, 'foo', 'bar') .then(() => { throw new Error('This should have been rejected') }) .catch((err) => expect('Unknown role: bar').to.equal(err.message)) // this caught me out, but streams:read is not a valid role for now - authorizeResolver('foo', 'bar', 'streams:read') + await authorizeResolver('foo', 'bar', 'streams:read') .then(() => { throw new Error('This should have been rejected') }) diff --git a/packages/server/modules/core/tests/streams.spec.js b/packages/server/modules/core/tests/streams.spec.js index 8f97d5926..e05ad8ba6 100644 --- a/packages/server/modules/core/tests/streams.spec.js +++ b/packages/server/modules/core/tests/streams.spec.js @@ -154,7 +154,7 @@ describe('Streams @core-streams', () => { }) it('Should not revoke owner permissions', async () => { - revokePermissionsStream({ streamId: testStream.id, userId: userOne.id }) + await revokePermissionsStream({ streamId: testStream.id, userId: userOne.id }) .then(() => { throw new Error('This should have thrown') }) diff --git a/packages/server/modules/core/tests/users.spec.js b/packages/server/modules/core/tests/users.spec.js index 7ac1831cb..dac8e6d5b 100644 --- a/packages/server/modules/core/tests/users.spec.js +++ b/packages/server/modules/core/tests/users.spec.js @@ -137,7 +137,7 @@ describe('Actors & Tokens @user-services', () => { newUser.email = 'bill@gates.com' newUser.password = 'testthebest' - createUser(newUser) + await createUser(newUser) .then(() => { throw new Error('This should have failed with duplicate email error') }) diff --git a/packages/server/modules/serverinvites/tests/serverInvites.spec.js b/packages/server/modules/serverinvites/tests/serverInvites.spec.js index acfa4d47a..ea9bef2b2 100644 --- a/packages/server/modules/serverinvites/tests/serverInvites.spec.js +++ b/packages/server/modules/serverinvites/tests/serverInvites.spec.js @@ -58,7 +58,7 @@ describe('Server Invites @server-invites', () => { message: 'Hey, join!' }) - createAndSendInvite({ + await createAndSendInvite({ email: 'cat@speckle.systems', inviterId: actor.id, message: 'Hey, join!' @@ -70,8 +70,8 @@ describe('Server Invites @server-invites', () => { expect(err.message).to.equal('Already invited!') }) }) - it('low multiple invites for the same email regardles of casing', () => { - createAndSendInvite({ + it('low multiple invites for the same email regardles of casing', async () => { + await createAndSendInvite({ email: 'dIdImItrIe@gmaIl.com', inviterId: actor.id, message: 'Hey, join!' @@ -85,7 +85,7 @@ describe('Server Invites @server-invites', () => { }) it('should not allow self invites', async () => { - createAndSendInvite({ + await createAndSendInvite({ email: 'didimitrie-100@gmail.com', inviterId: actor.id }) @@ -100,7 +100,7 @@ describe('Server Invites @server-invites', () => { }) it('should not allow invites from no user', async () => { - createAndSendInvite({ + await createAndSendInvite({ email: 'didimitrie233-100@gmail.com', inviterId: 'fake' }) @@ -113,7 +113,7 @@ describe('Server Invites @server-invites', () => { }) it('should not allow invites with a too long message', async () => { - createAndSendInvite({ + await createAndSendInvite({ email: '123456@gmail.com', inviterId: actor.id, message: longInviteMessage @@ -189,7 +189,7 @@ describe('Server Invites @server-invites', () => { message: 'Hey, join!' }) - useInvite({ id: inviteId, email: 'parrot@speckle.systems' }) + await useInvite({ id: inviteId, email: 'parrot@speckle.systems' }) .then(() => { throw new Error('This should have thrown') }) @@ -205,7 +205,7 @@ describe('Server Invites @server-invites', () => { expect(result).equals(true) expect(invite.used).equals(true) - useInvite({ id: inviteId, email: 'CrOw@speckle.systems' }) + await useInvite({ id: inviteId, email: 'CrOw@speckle.systems' }) .then(() => { throw new Error('This should have thrown') }) diff --git a/packages/server/test/hooks.js b/packages/server/test/hooks.js index 55495bbdd..0086fb8b0 100644 --- a/packages/server/test/hooks.js +++ b/packages/server/test/hooks.js @@ -75,7 +75,9 @@ exports.mochaHooks = { } exports.beforeEachContext = async () => { + console.log('running before each') await exports.truncateTables() + console.log('done truncating tables') const { app, graphqlServer } = await init() return { app, graphqlServer } }