diff --git a/twake/backend/node/package.json b/twake/backend/node/package.json index e9fa92d0af..e7168de1b3 100644 --- a/twake/backend/node/package.json +++ b/twake/backend/node/package.json @@ -88,7 +88,7 @@ "@types/ws": "^7.2.7", "@typescript-eslint/eslint-plugin": "^5.0.0", "@typescript-eslint/parser": "^4.2.0", - "babel-jest": "^26.5.2", + "babel-jest": "^29.3.1", "babel-plugin-parameter-decorator": "^1.0.16", "chai": "^4.2.0", "cpy-cli": "^4.2.0", @@ -97,13 +97,13 @@ "eslint-plugin-prettier": "^3.1.4", "eslint-plugin-unused-imports": "^2.0.0", "form-auto-content": "^2.2.0", - "jest": "^26.6.3", + "jest": "^29.3.1", "nodemon": "2.0.4", "pino-pretty": "^4.7.1", "prettier": "^2.1.2", "rimraf": "^3.0.2", "supertest": "4.0.2", - "ts-jest": "^26.4.0", + "ts-jest": "^29.0.3", "ts-node": "^9.0.0", "ts-node-dev": "^1.1.8", "tsc-watch": "^4.2.9", diff --git a/twake/backend/node/test/e2e/application/app-create-update.spec.ts b/twake/backend/node/test/e2e/application/app-create-update.spec.ts index 8b26d40a37..921c2a4310 100644 --- a/twake/backend/node/test/e2e/application/app-create-update.spec.ts +++ b/twake/backend/node/test/e2e/application/app-create-update.spec.ts @@ -18,7 +18,7 @@ describe("Applications", () => { let api: Api; let appRepo; - beforeAll(async ends => { + beforeAll(async () => { platform = await init(); await platform.database.getConnector().drop(); testDbService = await TestDbService.getInstance(platform, true); @@ -26,11 +26,10 @@ describe("Applications", () => { postPayload.company_id = platform.workspace.company_id; api = new Api(platform); appRepo = await testDbService.getRepository("application", Application); - ends(); }); - afterAll(done => { - platform.tearDown().then(() => done()); + afterAll(async () => { + await platform.tearDown(); }); const publishApp = async id => { @@ -41,7 +40,7 @@ describe("Applications", () => { }; describe("Create application", function () { - it("should 403 if creator is not a company admin", async done => { + it("should 403 if creator is not a company admin", async () => { const payload = { resource: cloneDeep(postPayload) }; const user = await testDbService.createUser([testDbService.defaultWorkspace()], { @@ -50,10 +49,9 @@ describe("Applications", () => { const response = await api.post(`${url}/applications`, payload, user.id); expect(response.statusCode).toBe(403); - done(); }); - it("should 200 on application create", async done => { + it("should 200 on application create", async () => { const payload = { resource: cloneDeep(postPayload) }; const response = await api.post(`${url}/applications`, payload); expect(response.statusCode).toBe(200); @@ -88,21 +86,19 @@ describe("Applications", () => { private_key: expect.any(String), }); - done(); }); }); describe("Update application", function () { let createdApp: PublicApplicationObject; - beforeAll(async done => { + beforeAll(async () => { const payload = { resource: cloneDeep(postPayload) }; const response = await api.post(`${url}/applications`, payload); createdApp = response.resource; - done(); }); - it("should 403 if editor is not a company admin", async done => { + it("should 403 if editor is not a company admin", async () => { if (!createdApp) throw new Error("can't find created app"); log.debug(createdApp); @@ -112,17 +108,15 @@ describe("Applications", () => { const response = await api.post(`${url}/applications/${createdApp.id}`, postPayload, user.id); expect(response.statusCode).toBe(403); - done(); }); - it("should 404 if application not found", async done => { + it("should 404 if application not found", async () => { const response = await api.post(`${url}/applications/${uuidv1()}`, { resource: postPayload }); expect(response.statusCode).toBe(404); - done(); }); describe("Unpublished application", () => { - it("should 200 on application update", async done => { + it("should 200 on application update", async () => { const payload = { resource: cloneDeep(postPayload) }; payload.resource.is_default = true; @@ -159,20 +153,18 @@ describe("Applications", () => { private_key: expect.any(String), }); - done(); }); }); describe.skip("Published application", () => { - beforeAll(async done => { + beforeAll(async () => { const payload = { resource: cloneDeep(postPayload) }; const response = await api.post(`${url}/applications`, payload); createdApp = response.resource; await publishApp(createdApp.id); - done(); }); - it("should 200 on update if allowed fields changed", async done => { + it("should 200 on update if allowed fields changed", async () => { const payload = { resource: cloneDeep(createdApp) as Application }; const entity = await appRepo.findOne({ id: createdApp.id }); payload.resource.api = cloneDeep(entity.api); @@ -184,16 +176,14 @@ describe("Applications", () => { requested: true, published: true, }); - done(); }); - it("should 400 on update if not allowed fields changed", async done => { + it("should 400 on update if not allowed fields changed", async () => { const payload = { resource: cloneDeep(createdApp) as Application }; const entity = await appRepo.findOne({ id: createdApp.id }); payload.resource.api = cloneDeep(entity.api); const response = await api.post(`${url}/applications/${createdApp.id}`, payload); expect(response.statusCode).toBe(400); - done(); }); }); }); @@ -201,7 +191,7 @@ describe("Applications", () => { let firstApp: PublicApplicationObject; let secondApp: PublicApplicationObject; let thirdApp: PublicApplicationObject; - beforeAll(async done => { + beforeAll(async () => { const payload = { resource: cloneDeep(postPayload) }; firstApp = (await api.post(`${url}/applications`, payload)).resource; secondApp = (await api.post(`${url}/applications`, payload)).resource; @@ -210,10 +200,9 @@ describe("Applications", () => { await publishApp(firstApp.id); await publishApp(secondApp.id); - done(); }); - it("should list published applications", async done => { + it("should list published applications", async () => { const response = await api.get(`${url}/applications`); expect(response.statusCode).toBe(200); @@ -227,40 +216,35 @@ describe("Applications", () => { expect.arrayContaining([firstApp.id, secondApp.id]), ); - done(); }); - it("should return public object for published application to any user", async done => { + it("should return public object for published application to any user", async () => { const response = await api.get(`${url}/applications/${firstApp.id}`, uuidv1()); expect(response.statusCode).toBe(200); expect(response.resource.id).toEqual(firstApp.id); expect(response.resource.api).toBeFalsy(); - done(); }); - it("should return public object for unpublished application to any user", async done => { + it("should return public object for unpublished application to any user", async () => { const response = await api.get(`${url}/applications/${thirdApp.id}`, uuidv1()); expect(response.statusCode).toBe(200); expect(response.resource.id).toEqual(thirdApp.id); expect(response.resource.api).toBeFalsy(); - done(); }); - it("should return whole object for published application to admin", async done => { + it("should return whole object for published application to admin", async () => { const response = await api.get(`${url}/applications/${firstApp.id}`); expect(response.statusCode).toBe(200); expect(response.resource.id).toEqual(firstApp.id); expect(response.resource.api).toBeTruthy(); - done(); }); - it("should return whole object for unpublished application to admin", async done => { + it("should return whole object for unpublished application to admin", async () => { const response = await api.get(`${url}/applications/${thirdApp.id}`); expect(response.statusCode).toBe(200); expect(response.resource.id).toEqual(thirdApp.id); expect(response.resource.api).toBeTruthy(); - done(); }); }); }); diff --git a/twake/backend/node/test/e2e/application/application-events.spec.ts b/twake/backend/node/test/e2e/application/application-events.spec.ts index 42c9bf81db..9c0bb092ff 100644 --- a/twake/backend/node/test/e2e/application/application-events.spec.ts +++ b/twake/backend/node/test/e2e/application/application-events.spec.ts @@ -16,7 +16,7 @@ describe("Application events", () => { let api: Api; let appId: string; - beforeAll(async ends => { + beforeAll(async () => { platform = await init(undefined, testAppHookRoute); await platform.database.getConnector().drop(); @@ -33,14 +33,9 @@ describe("Application events", () => { appId = createdApplication.resource.id; signingSecret = createdApplication.resource.api.private_key; - ends(); - - afterAll(done => { - platform.tearDown().then(() => done()); - }); }); - it("Should 200 on sending well formed event", async done => { + it("Should 200 on sending well formed event", async () => { const payload = { company_id: platform.workspace.company_id, workspace_id: platform.workspace.workspace_id, @@ -52,7 +47,6 @@ describe("Application events", () => { const response = await api.post(`${url}/applications/${appId}/event`, payload); expect(response.statusCode).toBe(200); expect(response.resource).toMatchObject({ a: "b" }); - done(); }); }); diff --git a/twake/backend/node/test/e2e/application/application-login.spec.ts b/twake/backend/node/test/e2e/application/application-login.spec.ts index e07e10dd7e..b5ae5571f0 100644 --- a/twake/backend/node/test/e2e/application/application-login.spec.ts +++ b/twake/backend/node/test/e2e/application/application-login.spec.ts @@ -14,7 +14,7 @@ describe("Applications", () => { let private_key: string; let accessToken: ApplicationLoginResponse["access_token"]; - beforeAll(async ends => { + beforeAll(async () => { platform = await init(); await platform.database.getConnector().drop(); testDbService = await TestDbService.getInstance(platform, true); @@ -29,15 +29,14 @@ describe("Applications", () => { appId = createdApplication.resource.id; private_key = createdApplication.resource.api.private_key; - ends(); }); - afterAll(done => { - platform.tearDown().then(() => done()); + afterAll(async () => { + await platform.tearDown(); }); describe("Login", function () { - it("Should be ok on valid token", async done => { + it("Should be ok on valid token", async () => { expect(appId).toBeTruthy(); const response = await api.post("/api/console/v1/login", { @@ -61,12 +60,11 @@ describe("Applications", () => { accessToken = resource.access_token; - done(); }); }); describe("Get myself", function () { - it("Should be 401 on invalid token", async done => { + it("Should be 401 on invalid token", async () => { const response = await platform.app.inject({ method: "GET", url: "/api/console/v1/me", @@ -76,10 +74,9 @@ describe("Applications", () => { }); log.debug(response.json()); expect(response.statusCode).toBe(401); - done(); }); - it("Should be 403 on auth by users (not company) token", async done => { + it("Should be 403 on auth by users (not company) token", async () => { const userToken = await platform.auth.getJWTToken(); const response = await platform.app.inject({ @@ -91,10 +88,9 @@ describe("Applications", () => { }); log.debug(response.json()); expect(response.statusCode).toBe(403); - done(); }); - it("Should be ok on valid token", async done => { + it("Should be ok on valid token", async () => { const response = await platform.app.inject({ method: "GET", url: "/api/console/v1/me", @@ -107,7 +103,6 @@ describe("Applications", () => { const resource = (await response.json()).resource; log.debug(resource); expect(resource).toMatchObject(postPayload); - done(); }); }); }); diff --git a/twake/backend/node/test/e2e/channels/channels.realtime.spec.ts b/twake/backend/node/test/e2e/channels/channels.realtime.spec.ts index d66cefe63c..aa21e3e136 100644 --- a/twake/backend/node/test/e2e/channels/channels.realtime.spec.ts +++ b/twake/backend/node/test/e2e/channels/channels.realtime.spec.ts @@ -58,7 +58,7 @@ describe("The Channels Realtime feature", () => { } describe("On channel creation", () => { - it("should notify the client", async done => { + it("should notify the client", async () => { const jwtToken = await platform.auth.getJWTToken(); const roomToken = "twake"; const channelName = new ObjectId().toString(); @@ -97,7 +97,6 @@ describe("The Channels Realtime feature", () => { expect(event.type).toEqual("channel"); expect(event.action).toEqual("saved"); expect(event.resource.name).toEqual(channelName); - done(); } }, ); @@ -110,7 +109,7 @@ describe("The Channels Realtime feature", () => { }); describe("On channel removal", () => { - it("should notify the client", async done => { + it("should notify the client", async () => { const jwtToken = await platform.auth.getJWTToken(); const roomToken = "twake"; const channelName = new ObjectId().toString(); @@ -149,7 +148,6 @@ describe("The Channels Realtime feature", () => { ), ); expect(event.resource.id).toEqual(creationResult.entity.id); - done(); }, ); socket.emit("realtime:join", { diff --git a/twake/backend/node/test/e2e/channels/channels.rest.spec.ts b/twake/backend/node/test/e2e/channels/channels.rest.spec.ts index 2bf97a75da..2ccdc4e065 100644 --- a/twake/backend/node/test/e2e/channels/channels.rest.spec.ts +++ b/twake/backend/node/test/e2e/channels/channels.rest.spec.ts @@ -33,10 +33,9 @@ describe("The /internal/services/channels/v1 API", () => { let testDbService: TestDbService; let api: Api; - beforeAll(async end => { + beforeAll(async () => { // platform = await init(); // await platform.database.getConnector().drop(); - end(); }); beforeEach(async () => { @@ -51,7 +50,7 @@ describe("The /internal/services/channels/v1 API", () => { platform = null; }); - async function testAccess(url, method, done) { + async function testAccess(url, method) { const jwtToken = await platform.auth.getJWTToken(); const response = await platform.app.inject({ method, @@ -62,7 +61,6 @@ describe("The /internal/services/channels/v1 API", () => { }); expect(response.statusCode).toBe(400); - done(); } function getContext(user?: User): WorkspaceExecutionContext { @@ -107,23 +105,21 @@ describe("The /internal/services/channels/v1 API", () => { } describe("The GET /companies/:companyId/workspaces/:workspaceId/channels route", () => { - it("should 400 when companyId is not valid", async done => { + it("should 400 when companyId is not valid", async () => { testAccess( `${url}/companies/123/workspaces/${platform.workspace.workspace_id}/channels`, "GET", - done, ); }); - it("should 400 when workspaceId is not valid", async done => { + it("should 400 when workspaceId is not valid", async () => { testAccess( `${url}/companies/${platform.workspace.company_id}/workspaces/123/channels`, "GET", - done, ); }); - it("should return empty list of channels", async done => { + it("should return empty list of channels", async () => { const jwtToken = await platform.auth.getJWTToken(); const response = await platform.app.inject({ method: "GET", @@ -141,10 +137,9 @@ describe("The /internal/services/channels/v1 API", () => { expect(response.statusCode).toBe(200); expect(result.resources.length).toEqual(0); - done(); }); - it("should return list of workspace channels", async done => { + it("should return list of workspace channels", async () => { const channel = new Channel(); channel.name = "Test Channel"; const creationResult = await gr.services.channels.channels.save(channel, {}, getContext()); @@ -177,10 +172,9 @@ describe("The /internal/services/channels/v1 API", () => { }); }); - done(); }); - it("should return list of channels the user is member of", async done => { + it("should return list of channels the user is member of", async () => { const ws0pk = { id: uuidv1(), company_id: platform.workspace.company_id }; await testDbService.createWorkspace(ws0pk); const newUser = await testDbService.createUser([ws0pk]); @@ -230,17 +224,16 @@ describe("The /internal/services/channels/v1 API", () => { id: creationResults[0].entity.id, }); - done(); }); - it("should return pagination information when not all channels are returned", async done => { + it("should return pagination information when not all channels are returned", async () => { await Promise.all( "0123456789".split("").map(name => { const channel = new Channel(); channel.name = name; return gr.services.channels.channels.save(channel, {}, getContext()); }), - ).catch(() => done(new Error("Failed on creation"))); + ).catch(() => {new Error("Failed on creation")}); const jwtToken = await platform.auth.getJWTToken(); const response = await platform.app.inject({ @@ -263,10 +256,9 @@ describe("The /internal/services/channels/v1 API", () => { expect(result.resources.length).toEqual(5); expect(result.next_page_token).toBeDefined; - done(); }); - it("should be able to paginate over channels from pagination information", async done => { + it("should be able to paginate over channels from pagination information", async () => { await platform.database.getConnector().drop(); await Promise.all( @@ -275,7 +267,7 @@ describe("The /internal/services/channels/v1 API", () => { channel.name = name; return gr.services.channels.channels.save(channel, {}, getContext()); }), - ).catch(() => done(new Error("Failed on creation"))); + ).catch(() => {new Error("Failed on creation")}); const jwtToken = await platform.auth.getJWTToken(); const firstPage = await platform.app.inject({ @@ -326,17 +318,16 @@ describe("The /internal/services/channels/v1 API", () => { ]).size, ).toEqual(10); - done(); }); - it("should not return pagination information when all channels are returned", async done => { + it("should not return pagination information when all channels are returned", async () => { await Promise.all( "0123456789".split("").map(name => { const channel = new Channel(); channel.name = name; return gr.services.channels.channels.save(channel, {}, getContext()); }), - ).catch(() => done(new Error("Failed on creation"))); + ).catch(() => {new Error("Failed on creation")}); const jwtToken = await platform.auth.getJWTToken(); const response = await platform.app.inject({ @@ -359,10 +350,9 @@ describe("The /internal/services/channels/v1 API", () => { expect(result.resources.length).toEqual(10); expect(result.next_page_token).not.toBeDefined; - done(); }); - it("should return websockets information", async done => { + it("should return websockets information", async () => { const jwtToken = await platform.auth.getJWTToken(); const response = await platform.app.inject({ method: "GET", @@ -387,10 +377,9 @@ describe("The /internal/services/channels/v1 API", () => { { room: expect.stringContaining(getPrivateRoomName(platform.workspace, { id: "" })) }, ]); - done(); }); - it.skip("should return websockets and direct information", async done => { + it.skip("should return websockets and direct information", async () => { const jwtToken = await platform.auth.getJWTToken(); const response = await platform.app.inject({ method: "GET", @@ -412,32 +401,29 @@ describe("The /internal/services/channels/v1 API", () => { expect(response.statusCode).toBe(200); expect(result.websockets.length).toEqual(3); - done(); }); }); describe("The GET /companies/:companyId/workspaces/:workspaceId/channels/:id route", () => { - it("should 400 when companyId is not valid", async done => { + it("should 400 when companyId is not valid", async () => { const channelId = "1"; testAccess( `${url}/companies/123/workspaces/${platform.workspace.workspace_id}/channels/${channelId}`, "GET", - done, ); }); - it("should 400 when workspaceId is not valid", async done => { + it("should 400 when workspaceId is not valid", async () => { const channelId = "1"; testAccess( `${url}/companies/${platform.workspace.company_id}/workspaces/123/channels/${channelId}`, "GET", - done, ); }); - it("should return the requested channel", async done => { + it("should return the requested channel", async () => { const jwtToken = await platform.auth.getJWTToken(); const channel = new Channel(); @@ -473,10 +459,9 @@ describe("The /internal/services/channels/v1 API", () => { token: expect.any(String), }); - done(); }); - it("channel counters", async done => { + it("channel counters", async () => { await platform.database.getConnector().drop(); await testDbService.createDefault(platform); @@ -568,28 +553,25 @@ describe("The /internal/services/channels/v1 API", () => { messages: 0, }); - done(); }); }); describe("The POST /companies/:companyId/workspaces/:workspaceId/channels route", () => { - it("should 400 when companyId is not valid", async done => { + it("should 400 when companyId is not valid", async () => { testAccess( `${url}/companies/123/workspaces/${platform.workspace.workspace_id}/channels`, "POST", - done, ); }); - it("should 400 when workspaceId is not valid", async done => { + it("should 400 when workspaceId is not valid", async () => { testAccess( `${url}/companies/${platform.workspace.company_id}/workspaces/123/channels`, "POST", - done, ); }); - it("should create a channel", async done => { + it("should create a channel", async () => { const jwtToken = await platform.auth.getJWTToken(); const response = await platform.app.inject({ @@ -628,10 +610,9 @@ describe("The /internal/services/channels/v1 API", () => { token: expect.any(String), }); expect(createdChannel).toBeDefined(); - done(); }); - it("should fail when channel name is not defined", async done => { + it("should fail when channel name is not defined", async () => { const jwtToken = await platform.auth.getJWTToken(); const response = await platform.app.inject({ method: "POST", @@ -647,7 +628,6 @@ describe("The /internal/services/channels/v1 API", () => { }); expect(response.statusCode).toEqual(400); - done(); }); }); @@ -700,19 +680,17 @@ describe("The /internal/services/channels/v1 API", () => { expect(response.statusCode).toEqual(expectedCode); } - it("should 400 when companyId is not valid", async done => { + it("should 400 when companyId is not valid", async () => { testAccess( `${url}/companies/123/workspaces/${platform.workspace.workspace_id}/channels/1`, "POST", - done, ); }); - it("should 400 when workspaceId is not valid", async done => { + it("should 400 when workspaceId is not valid", async () => { testAccess( `${url}/companies/${platform.workspace.company_id}/workspaces/123/channels/1`, "POST", - done, ); }); @@ -721,7 +699,7 @@ describe("The /internal/services/channels/v1 API", () => { platform.currentUser.isWorkspaceModerator = true; }); - it("should fail when resource is not defined", async done => { + it("should fail when resource is not defined", async () => { const jwtToken = await platform.auth.getJWTToken(); const channel = getChannel(); @@ -732,10 +710,9 @@ describe("The /internal/services/channels/v1 API", () => { ); await updateChannelFail(jwtToken, creationResult.entity.id, {}, 400); - done(); }); - it("should be able to update the is_default field", async done => { + it("should be able to update the is_default field", async () => { const jwtToken = await platform.auth.getJWTToken(); const channel = getChannel(); @@ -759,10 +736,9 @@ describe("The /internal/services/channels/v1 API", () => { archived: channel.archived, owner: channel.owner, }); - done(); }); - it("should be able to update the visibility field", async done => { + it("should be able to update the visibility field", async () => { const jwtToken = await platform.auth.getJWTToken(); const channel = getChannel(); @@ -786,10 +762,9 @@ describe("The /internal/services/channels/v1 API", () => { archived: channel.archived, owner: channel.owner, }); - done(); }); - it("should be able to update the archived field", async done => { + it("should be able to update the archived field", async () => { const jwtToken = await platform.auth.getJWTToken(); const channel = getChannel(); @@ -812,10 +787,9 @@ describe("The /internal/services/channels/v1 API", () => { archived: true, owner: channel.owner, }); - done(); }); - it("should be able to update all the fields at the same time", async done => { + it("should be able to update all the fields at the same time", async () => { const jwtToken = await platform.auth.getJWTToken(); const channel = getChannel(); @@ -842,7 +816,6 @@ describe("The /internal/services/channels/v1 API", () => { owner: channel.owner, }); - done(); }); }); @@ -851,7 +824,7 @@ describe("The /internal/services/channels/v1 API", () => { platform.currentUser.isWorkspaceModerator = false; }); - it("should be able to update the is_default field", async done => { + it("should be able to update the is_default field", async () => { const jwtToken = await platform.auth.getJWTToken(); const channel = getChannel(platform.currentUser.id); @@ -876,10 +849,9 @@ describe("The /internal/services/channels/v1 API", () => { owner: channel.owner, }); - done(); }); - it("should be able to update the visibility field", async done => { + it("should be able to update the visibility field", async () => { const jwtToken = await platform.auth.getJWTToken(); const channel = getChannel(platform.currentUser.id); @@ -904,10 +876,9 @@ describe("The /internal/services/channels/v1 API", () => { owner: channel.owner, }); - done(); }); - it("should be able to update the archived field", async done => { + it("should be able to update the archived field", async () => { const jwtToken = await platform.auth.getJWTToken(); const channel = getChannel(platform.currentUser.id); @@ -931,10 +902,9 @@ describe("The /internal/services/channels/v1 API", () => { archived: true, owner: channel.owner, }); - done(); }); - it("should be able to update all the fields at the same time", async done => { + it("should be able to update all the fields at the same time", async () => { const jwtToken = await platform.auth.getJWTToken(); const channel = getChannel(platform.currentUser.id); @@ -961,7 +931,6 @@ describe("The /internal/services/channels/v1 API", () => { owner: channel.owner, }); - done(); }); }); @@ -970,7 +939,7 @@ describe("The /internal/services/channels/v1 API", () => { platform.currentUser.isWorkspaceModerator = false; }); - it("should not be able to update the is_default field", async done => { + it("should not be able to update the is_default field", async () => { const jwtToken = await platform.auth.getJWTToken(); const channel = getChannel(); @@ -989,10 +958,9 @@ describe("The /internal/services/channels/v1 API", () => { 400, ); - done(); }); - it("should not be able to update the visibility field", async done => { + it("should not be able to update the visibility field", async () => { const jwtToken = await platform.auth.getJWTToken(); const channel = getChannel(); @@ -1011,10 +979,9 @@ describe("The /internal/services/channels/v1 API", () => { 400, ); - done(); }); - it("should not be able to update the archived field", async done => { + it("should not be able to update the archived field", async () => { const jwtToken = await platform.auth.getJWTToken(); const channel = getChannel(); @@ -1033,10 +1000,9 @@ describe("The /internal/services/channels/v1 API", () => { 400, ); - done(); }); - it("should be able to update the 'name', 'description', 'icon' fields", async done => { + it("should be able to update the 'name', 'description', 'icon' fields", async () => { const jwtToken = await platform.auth.getJWTToken(); const channel = getChannel(); @@ -1065,7 +1031,6 @@ describe("The /internal/services/channels/v1 API", () => { owner: channel.owner, }); - done(); }); }); }); @@ -1087,19 +1052,17 @@ describe("The /internal/services/channels/v1 API", () => { expect(response.statusCode).toEqual(status); } - it("should 400 when companyId is not valid", async done => { + it("should 400 when companyId is not valid", async () => { testAccess( `${url}/companies/123/workspaces/${platform.workspace.workspace_id}/channels/1`, "DELETE", - done, ); }); - it("should 400 when workspaceId is not valid", async done => { + it("should 400 when workspaceId is not valid", async () => { testAccess( `${url}/companies/${platform.workspace.company_id}/workspaces/123/channels/1`, "DELETE", - done, ); }); @@ -1108,7 +1071,7 @@ describe("The /internal/services/channels/v1 API", () => { platform.currentUser.isWorkspaceModerator = true; }); - it("should not be able to delete a direct channel", async done => { + it("should not be able to delete a direct channel", async () => { platform.workspace.workspace_id = "direct"; const jwtToken = await platform.auth.getJWTToken(); @@ -1125,10 +1088,9 @@ describe("The /internal/services/channels/v1 API", () => { `${url}/companies/${platform.workspace.company_id}/workspaces/${platform.workspace.workspace_id}/channels/${creationResult.entity.id}`, 400, ); - done(); }); - it("should be able to delete any channel of the workspace", async done => { + it("should be able to delete any channel of the workspace", async () => { const jwtToken = await platform.auth.getJWTToken(); const channel = getChannel(); @@ -1144,7 +1106,6 @@ describe("The /internal/services/channels/v1 API", () => { `${url}/companies/${platform.workspace.company_id}/workspaces/${platform.workspace.workspace_id}/channels/${creationResult.entity.id}`, 204, ); - done(); }); }); @@ -1153,7 +1114,7 @@ describe("The /internal/services/channels/v1 API", () => { platform.currentUser.isWorkspaceModerator = false; }); - it("should not be able to delete a direct channel", async done => { + it("should not be able to delete a direct channel", async () => { platform.workspace.workspace_id = "direct"; const jwtToken = await platform.auth.getJWTToken(); @@ -1170,10 +1131,9 @@ describe("The /internal/services/channels/v1 API", () => { `${url}/companies/${platform.workspace.company_id}/workspaces/${platform.workspace.workspace_id}/channels/${creationResult.entity.id}`, 400, ); - done(); }); - it("should be able to delete the channel", async done => { + it("should be able to delete the channel", async () => { const jwtToken = await platform.auth.getJWTToken(); const channel = getChannel(platform.currentUser.id); @@ -1189,7 +1149,6 @@ describe("The /internal/services/channels/v1 API", () => { `${url}/companies/${platform.workspace.company_id}/workspaces/${platform.workspace.workspace_id}/channels/${creationResult.entity.id}`, 204, ); - done(); }); }); @@ -1198,7 +1157,7 @@ describe("The /internal/services/channels/v1 API", () => { platform.currentUser.isWorkspaceModerator = false; }); - it("should not be able to delete the channel", async done => { + it("should not be able to delete the channel", async () => { const jwtToken = await platform.auth.getJWTToken(); const channel = getChannel(); @@ -1214,10 +1173,9 @@ describe("The /internal/services/channels/v1 API", () => { `${url}/companies/${platform.workspace.company_id}/workspaces/${platform.workspace.workspace_id}/channels/${creationResult.entity.id}`, 400, ); - done(); }); - it("should not be able to delete a direct channel", async done => { + it("should not be able to delete a direct channel", async () => { platform.workspace.workspace_id = "direct"; const jwtToken = await platform.auth.getJWTToken(); @@ -1234,13 +1192,12 @@ describe("The /internal/services/channels/v1 API", () => { `${url}/companies/${platform.workspace.company_id}/workspaces/${platform.workspace.workspace_id}/channels/${creationResult.entity.id}`, 400, ); - done(); }); }); }); describe("The GET /companies/:companyId/workspaces/:workspaceId/recent route", () => { - it("should return list of recent channels for workspace", async done => { + it("should return list of recent channels for workspace", async () => { await testDbService.createDefault(platform); const channels = []; @@ -1344,7 +1301,6 @@ describe("The /internal/services/channels/v1 API", () => { expect(result.resources[0].name).toEqual("FirstName2 LastName2"); expect(result.resources[1].name).toEqual("Regular Channel 2"); - done(); }); }); }); diff --git a/twake/backend/node/test/e2e/channels/channels.search.spec.ts b/twake/backend/node/test/e2e/channels/channels.search.spec.ts index bb1da691a8..a0a2933522 100644 --- a/twake/backend/node/test/e2e/channels/channels.search.spec.ts +++ b/twake/backend/node/test/e2e/channels/channels.search.spec.ts @@ -42,7 +42,6 @@ describe("The /internal/services/channels/v1 API", () => { }); expect(response.statusCode).toBe(400); - done(); } function getContext(user?: User): WorkspaceExecutionContext { @@ -87,7 +86,7 @@ describe("The /internal/services/channels/v1 API", () => { } describe("Channels search", () => { - it("Should find channels by name", async done => { + it("Should find channels by name", async () => { const ws0pk = { id: uuidv1(), company_id: platform.workspace.company_id }; await testDbService.createWorkspace(ws0pk); const newUser = await testDbService.createUser([ws0pk]); @@ -130,7 +129,6 @@ describe("The /internal/services/channels/v1 API", () => { expect(response.statusCode).toBe(200); expect(result.resources.length).toEqual(9); - done(); }); }); }); diff --git a/twake/backend/node/test/e2e/channels/direct-channels.spec.ts b/twake/backend/node/test/e2e/channels/direct-channels.spec.ts index 8c49e1566a..2694287cdd 100644 --- a/twake/backend/node/test/e2e/channels/direct-channels.spec.ts +++ b/twake/backend/node/test/e2e/channels/direct-channels.spec.ts @@ -52,7 +52,7 @@ describe("The direct channels API", () => { } describe("Channel List - GET /channels", () => { - it("should return empty list of direct channels", async done => { + it("should return empty list of direct channels", async () => { const jwtToken = await platform.auth.getJWTToken(); const response = await platform.app.inject({ method: "GET", @@ -70,10 +70,9 @@ describe("The direct channels API", () => { expect(response.statusCode).toBe(200); expect(result.resources.length).toEqual(0); - done(); }); - it("should return list of direct channels the user is member of", async done => { + it("should return list of direct channels the user is member of", async () => { const channel = channelUtils.getChannel(); const directChannelIn = channelUtils.getDirectChannel(); const directChannelNotIn = channelUtils.getDirectChannel(); @@ -148,10 +147,9 @@ describe("The direct channels API", () => { id: creationResult[0].entity.id, }); - done(); }); - it("should not return direct channels in workspace list", async done => { + it("should not return direct channels in workspace list", async () => { const channel = channelUtils.getChannel(); const directChannelIn = channelUtils.getDirectChannel(); const directChannelIn2 = channelUtils.getDirectChannel(); @@ -215,10 +213,9 @@ describe("The direct channels API", () => { }); expect(result.resources[0].visibility).not.toEqual(ChannelVisibility.DIRECT); - done(); }); - it("should not return direct channels in workspace list with mine parameter", async done => { + it("should not return direct channels in workspace list with mine parameter", async () => { const channel = channelUtils.getChannel(); const channel2 = channelUtils.getChannel(); const directChannelIn = channelUtils.getDirectChannel(); @@ -274,12 +271,11 @@ describe("The direct channels API", () => { expect(response.statusCode).toBe(200); expect(result.resources.length).toEqual(1); - done(); }); }); describe("Create direct channel - POST /channels", () => { - it("should be able to create a direct channel with members", async done => { + it("should be able to create a direct channel with members", async () => { const jwtToken = await platform.auth.getJWTToken(); const members = [uuidv1(), platform.currentUser.id]; @@ -330,10 +326,9 @@ describe("The direct channels API", () => { ); expect(directChannelsInCompany).toBeDefined(); - done(); }); - it("should not be able to create the same direct channel twice (with same users)", async done => { + it("should not be able to create the same direct channel twice (with same users)", async () => { function createChannel(members: string[]) { return platform.app.inject({ method: "POST", @@ -372,10 +367,9 @@ describe("The direct channels API", () => { expect(ids.size).toEqual(1); - done(); }); - it("should not be able to create the same direct channel twice (with same users not in the same order)", async done => { + it("should not be able to create the same direct channel twice (with same users not in the same order)", async () => { function createChannel(members: string[]) { return platform.app.inject({ method: "POST", @@ -414,7 +408,6 @@ describe("The direct channels API", () => { expect(ids.size).toEqual(1); - done(); }); }); }); diff --git a/twake/backend/node/test/e2e/channels/skip-channel-members.realtime.spec.ts b/twake/backend/node/test/e2e/channels/skip-channel-members.realtime.spec.ts index eede90a7bf..4216bc302c 100644 --- a/twake/backend/node/test/e2e/channels/skip-channel-members.realtime.spec.ts +++ b/twake/backend/node/test/e2e/channels/skip-channel-members.realtime.spec.ts @@ -59,7 +59,7 @@ describe.skip("The Channels Members Realtime feature", () => { ); }); - it("should notify the client", async done => { + it("should notify the client", async () => { const jwtToken = await platform.auth.getJWTToken(); const roomToken = "twake"; @@ -98,7 +98,6 @@ describe.skip("The Channels Members Realtime feature", () => { user_id: platform.currentUser.id, channel_id: createdChannel.entity.id, }); - done(); }); }) .on("unauthorized", () => { @@ -109,7 +108,7 @@ describe.skip("The Channels Members Realtime feature", () => { }); describe("On channel member removal", () => { - it("should notify the client", async done => { + it("should notify the client", async () => { const jwtToken = await platform.auth.getJWTToken(); const roomToken = "twake"; @@ -151,7 +150,6 @@ describe.skip("The Channels Members Realtime feature", () => { user_id: platform.currentUser.id, channel_id: creationResult.entity.id, }); - done(); }); socket.emit("realtime:join", { name: getPublicRoomName(creationResult.entity), diff --git a/twake/backend/node/test/e2e/channels/skip-channel-members.rest.spec.ts b/twake/backend/node/test/e2e/channels/skip-channel-members.rest.spec.ts index 10e6ece9e8..d8edb8ef69 100644 --- a/twake/backend/node/test/e2e/channels/skip-channel-members.rest.spec.ts +++ b/twake/backend/node/test/e2e/channels/skip-channel-members.rest.spec.ts @@ -81,10 +81,9 @@ describe.skip("The ChannelMembers REST API", () => { }); it("should 404 when channel does not exists", done => { - done(); }); - it("should return empty list of members", async done => { + it("should return empty list of members", async () => { const jwtToken = await platform.auth.getJWTToken(); const response = await platform.app.inject({ method: "GET", @@ -102,10 +101,9 @@ describe.skip("The ChannelMembers REST API", () => { expect(response.statusCode).toBe(200); expect(result.resources.length).toEqual(0); - done(); }); - it("should return list of members the user has access to", async done => { + it("should return list of members the user has access to", async () => { const member = getMember(createdChannel.entity, platform.currentUser); const memberCreationResult = await gr.services.channels.members.save( member, @@ -135,7 +133,6 @@ describe.skip("The ChannelMembers REST API", () => { user_id: memberCreationResult.entity.user_id, }); - done(); }); }); @@ -148,7 +145,7 @@ describe.skip("The ChannelMembers REST API", () => { createdChannel = await gr.services.channels.channels.save(channel, {}, getWorkspaceContext()); }); - it("should fail when user_id is not defined", async done => { + it("should fail when user_id is not defined", async () => { const jwtToken = await platform.auth.getJWTToken(); const response = await platform.app.inject({ method: "POST", @@ -163,10 +160,9 @@ describe.skip("The ChannelMembers REST API", () => { expect(response.statusCode).toEqual(400); - done(); }); - it("should be able to add current member", async done => { + it("should be able to add current member", async () => { const jwtToken = await platform.auth.getJWTToken(); const response = await platform.app.inject({ method: "POST", @@ -183,10 +179,9 @@ describe.skip("The ChannelMembers REST API", () => { expect(response.statusCode).toEqual(201); - done(); }); - it("should be able to add another member", async done => { + it("should be able to add another member", async () => { const jwtToken = await platform.auth.getJWTToken(); const response = await platform.app.inject({ method: "POST", @@ -202,7 +197,6 @@ describe.skip("The ChannelMembers REST API", () => { }); expect(response.statusCode).toEqual(201); - done(); }); }); @@ -215,7 +209,7 @@ describe.skip("The ChannelMembers REST API", () => { createdChannel = await gr.services.channels.channels.save(channel, {}, getWorkspaceContext()); }); - it("should 404 when member does not exist", async done => { + it("should 404 when member does not exist", async () => { const jwtToken = await platform.auth.getJWTToken(); const response = await platform.app.inject({ method: "GET", @@ -228,10 +222,9 @@ describe.skip("The ChannelMembers REST API", () => { }); expect(response.statusCode).toEqual(404); - done(); }); - it("should send back member", async done => { + it("should send back member", async () => { const member = getMember(createdChannel.entity, platform.currentUser); const memberCreationResult = await gr.services.channels.members.save( member, @@ -260,7 +253,6 @@ describe.skip("The ChannelMembers REST API", () => { user_id: memberCreationResult.entity.user_id, }); - done(); }); }); @@ -273,7 +265,7 @@ describe.skip("The ChannelMembers REST API", () => { createdChannel = await gr.services.channels.channels.save(channel, {}, getWorkspaceContext()); }); - it("should not be able to update a member when current user is not the member", async done => { + it("should not be able to update a member when current user is not the member", async () => { const member = getMember(createdChannel.entity, { id: uuidv4() }); const memberCreationResult = await gr.services.channels.members.save( member, @@ -294,10 +286,9 @@ describe.skip("The ChannelMembers REST API", () => { }); expect(response.statusCode).toEqual(400); - done(); }); - it("should be able to update member when current user is the member", async done => { + it("should be able to update member when current user is the member", async () => { const member = getMember(createdChannel.entity, platform.currentUser); const memberCreationResult = await gr.services.channels.members.save( member, @@ -329,7 +320,6 @@ describe.skip("The ChannelMembers REST API", () => { favorite: true, }); - done(); }); }); @@ -342,7 +332,7 @@ describe.skip("The ChannelMembers REST API", () => { createdChannel = await gr.services.channels.channels.save(channel, {}, getWorkspaceContext()); }); - it("should 404 when member does not exist", async done => { + it("should 404 when member does not exist", async () => { const jwtToken = await platform.auth.getJWTToken(); const response = await platform.app.inject({ method: "DELETE", @@ -360,10 +350,9 @@ describe.skip("The ChannelMembers REST API", () => { }); expect(response.statusCode).toEqual(404); - done(); }); - it("should not be able to remove the member when current user does not have enough rights", async done => { + it("should not be able to remove the member when current user does not have enough rights", async () => { // const member = getMember(createdChannel.entity, { id: uuidv4() }); // const memberCreationResult = await gr.services.channels.members.save(member); // const jwtToken = await platform.auth.getJWTToken(); @@ -376,10 +365,9 @@ describe.skip("The ChannelMembers REST API", () => { // }); // // expect(response.statusCode).toEqual(400); - // done(); }); - it("should be able to remove the member when current user is the member", async done => { + it("should be able to remove the member when current user is the member", async () => { const member = getMember(createdChannel.entity, platform.currentUser); const memberCreationResult = await gr.services.channels.members.save( member, @@ -395,7 +383,6 @@ describe.skip("The ChannelMembers REST API", () => { }); expect(response.statusCode).toEqual(204); - done(); }); }); }); diff --git a/twake/backend/node/test/e2e/console/console-auth.spec.ts b/twake/backend/node/test/e2e/console/console-auth.spec.ts index f542f79561..887b7a0e76 100644 --- a/twake/backend/node/test/e2e/console/console-auth.spec.ts +++ b/twake/backend/node/test/e2e/console/console-auth.spec.ts @@ -5,12 +5,11 @@ import { v1 as uuidv1 } from "uuid"; import gr from "../../../src/services/global-resolver"; export const itRemote = (name: string, cb: (a: any) => void) => { - _it(name, async done => { + _it(name, async () => { if (gr.services.console.consoleType === "remote") { cb(done); } else { console.warn(`[skipped]: ${name} (console-mode only)`); - done(); } }); }; @@ -28,7 +27,7 @@ describe("The console API auth", () => { const firstUserPassword = "superPassw0rd"; - beforeAll(async ends => { + beforeAll(async () => { platform = await init({ services: [ "database", @@ -66,16 +65,14 @@ describe("The console API auth", () => { await new Promise(r => setTimeout(r, 1000)); - ends(); }); - afterAll(async ends => { + afterAll(async () => { await platform.tearDown(); - ends(); }); describe("Common checks", () => { - it("should 400 when required params are missing ", async done => { + it("should 400 when required params are missing ", async () => { const response = await platform.app.inject({ method: "POST", url: `${loginUrl}`, @@ -91,11 +88,10 @@ describe("The console API auth", () => { error: "Bad Request", message: "remote_access_token or email+password are required", }); - done(); }); }); describe("Auth using token", () => { - itRemote("should 403 when token is invalid", async done => { + itRemote("should 403 when token is invalid", async () => { const response = await platform.app.inject({ method: "POST", url: `${loginUrl}`, @@ -110,10 +106,9 @@ describe("The console API auth", () => { }); expect(response.statusCode).toBe(403); - done(); }); - itRemote("should 200 when token is valid", async done => { + itRemote("should 200 when token is valid", async () => { const response = await platform.app.inject({ method: "POST", url: `${loginUrl}`, @@ -134,11 +129,10 @@ describe("The console API auth", () => { }, }); expect(response.statusCode).toBe(200); - done(); }); }); describe("Auth using email/password", () => { - it("should 403 when user doesn't exists", async done => { + it("should 403 when user doesn't exists", async () => { const response = await platform.app.inject({ method: "POST", url: `${loginUrl}`, @@ -153,10 +147,9 @@ describe("The console API auth", () => { message: "User doesn't exists", statusCode: 403, }); - done(); }); - it("should 403 when password doesn't match", async done => { + it("should 403 when password doesn't match", async () => { const user = testDbService.users[0]; const response = await platform.app.inject({ @@ -173,10 +166,9 @@ describe("The console API auth", () => { message: "Password doesn't match", statusCode: 403, }); - done(); }); - it("should 200 when credentials is valid", async done => { + it("should 200 when credentials is valid", async () => { const user = testDbService.users[0]; const response = await platform.app.inject({ @@ -199,11 +191,10 @@ describe("The console API auth", () => { }, }); - done(); }); }); describe("Token renewal", () => { - it("should 200 when refresh from access_token", async done => { + it("should 200 when refresh from access_token", async () => { const user = testDbService.users[0]; const firstResponse = await platform.app.inject({ @@ -232,11 +223,10 @@ describe("The console API auth", () => { expect(secondRes.expiration).toBeGreaterThan(firstRes.expiration); expect(secondRes.refresh_expiration).toBeGreaterThan(firstRes.refresh_expiration); - done(); }, 2000); }); - it("should 200 when refresh from refresh_token", async done => { + it("should 200 when refresh from refresh_token", async () => { const user = testDbService.users[0]; const firstResponse = await platform.app.inject({ @@ -265,7 +255,6 @@ describe("The console API auth", () => { expect(secondRes.expiration).toBeGreaterThan(firstRes.expiration); expect(secondRes.refresh_expiration).toBeGreaterThan(firstRes.refresh_expiration); - done(); }, 2000); }); }); diff --git a/twake/backend/node/test/e2e/console/console-hooks.spec.ts b/twake/backend/node/test/e2e/console/console-hooks.spec.ts index fadbbec93a..6ac44b8424 100644 --- a/twake/backend/node/test/e2e/console/console-hooks.spec.ts +++ b/twake/backend/node/test/e2e/console/console-hooks.spec.ts @@ -10,12 +10,11 @@ import { ConsoleServiceImpl } from "../../../src/services/console/service"; */ export const it = (name: string, cb: (a: any) => void) => { - _it(name, async done => { + _it(name, async () => { if (gr.services.console.consoleType === "remote") { cb(done); } else { console.warn(`[skipped]: ${name} (console-mode only)`); - done(); } }); }; @@ -34,7 +33,7 @@ describe("The console API hooks", () => { const secret = "ohquoo1fohzeigitochaJeepoowug4Yuqueite6etojieg1oowaeraeshiW8ku8g"; - beforeAll(async ends => { + beforeAll(async () => { platform = await init({ services: [ "database", @@ -68,12 +67,10 @@ describe("The console API hooks", () => { const console = platform.platform.getProvider("console"); - ends(); }); - afterAll(async ends => { + afterAll(async () => { await platform.tearDown(); - ends(); }); const getPayload = (type: string, content: Record) => { @@ -94,16 +91,15 @@ describe("The console API hooks", () => { }; describe("Common checks", () => { - it("should 404 when not POST ", async done => { + it("should 404 when not POST ", async () => { const response = await platform.app.inject({ method: "GET", url: `${url}`, }); expect(response.statusCode).toBe(404); - done(); }); - it("should 400 when secret key is missing", async done => { + it("should 400 when secret key is missing", async () => { const response = await platform.app.inject({ method: "POST", url: `${url}`, @@ -115,10 +111,9 @@ describe("The console API hooks", () => { error: "Bad Request", message: "querystring should have required property 'secret_key'", }); - done(); }); - it("should 403 when secret key is not valid ", async done => { + it("should 403 when secret key is not valid ", async () => { const response = await platform.app.inject({ method: "POST", url: `${url}?secret_key=wrongOne`, @@ -130,23 +125,21 @@ describe("The console API hooks", () => { error: "Forbidden", message: "Wrong secret", }); - done(); }); - it("should 501 when type is not implemented", async done => { + it("should 501 when type is not implemented", async () => { const response = await platform.app.inject({ method: "POST", url: `${url}?secret_key=${secret}`, payload: getPayload("unknown_type", {}), }); expect(response.statusCode).toBe(501); - done(); }); }); describe("User related hooks", () => { describe("User created/updated", () => { - it("should 200 when updated existing user", async done => { + it("should 200 when updated existing user", async () => { const user = testDbService.users[0]; const response = await platform.app.inject({ @@ -200,10 +193,9 @@ describe("The console API hooks", () => { }), ); - done(); }); - it("should 200 when creating new user", async done => { + it("should 200 when creating new user", async () => { const newUserConsoleId = String(testDbService.rand()); const response = await platform.app.inject({ @@ -259,10 +251,9 @@ describe("The console API hooks", () => { role: "moderator", }), ); - done(); }); - it("should 200 when creating new user with same username (generating new one)", async done => { + it("should 200 when creating new user with same username (generating new one)", async () => { const newUserConsoleId = String(testDbService.rand()); const response = await platform.app.inject({ @@ -318,10 +309,9 @@ describe("The console API hooks", () => { role: "member", }), ); - done(); }); - it("should 400 when creating user with email that already exists", async done => { + it("should 400 when creating user with email that already exists", async () => { const newUserConsoleId = String(testDbService.rand()); const response = await platform.app.inject({ @@ -339,11 +329,10 @@ describe("The console API hooks", () => { expect(response.json()).toMatchObject({ error: "Console user not created because email already exists", }); - done(); }); }); describe("User removed", () => { - it("should 200 when deleting", async done => { + it("should 200 when deleting", async () => { const company = testDbService.company; let users = await testDbService.getCompanyUsers(company.id); let user = users.find(a => a.username_canonical == "consolecreateduser"); @@ -366,10 +355,9 @@ describe("The console API hooks", () => { user = users.find(a => a.username_canonical == "consolecreateduser"); expect(user).toBeFalsy(); - done(); }); - it("should 400 when user not found", async done => { + it("should 400 when user not found", async () => { const company = testDbService.company; const response = await platform.app.inject({ @@ -385,14 +373,13 @@ describe("The console API hooks", () => { expect(response.statusCode).toBe(400); - done(); }); }); }); describe("Company related hooks", () => { describe("Company added", () => { - it("should 200 when company created", async done => { + it("should 200 when company created", async () => { const newCompanyCode = String(testDbService.rand()); const response = await platform.app.inject({ method: "POST", @@ -432,11 +419,10 @@ describe("The console API hooks", () => { }), ); - done(); }); }); describe("Company updated", () => { - it("should 200 when company updated", async done => { + it("should 200 when company updated", async () => { const company = testDbService.company; expect(company).toBeTruthy(); expect(company.identity_provider_id).toBeTruthy(); @@ -478,11 +464,10 @@ describe("The console API hooks", () => { }), ); - done(); }); }); describe("Plan updated", () => { - it("should 200 when plan updated", async done => { + it("should 200 when plan updated", async () => { const company = testDbService.company; expect(company).toBeTruthy(); expect(company.identity_provider_id).toBeTruthy(); @@ -514,12 +499,11 @@ describe("The console API hooks", () => { }), ); - done(); }); }); describe("Company removed", () => { - it("should 200 when company removed", async done => { + it("should 200 when company removed", async () => { const company = testDbService.company; expect(company).toBeTruthy(); expect(company.identity_provider_id).toBeTruthy(); @@ -538,7 +522,6 @@ describe("The console API hooks", () => { const deletedCompany = await testDbService.getCompanyFromDb(company.id); expect(deletedCompany).toBeFalsy(); - done(); }); }); }); diff --git a/twake/backend/node/test/e2e/counters.spec.ts b/twake/backend/node/test/e2e/counters.spec.ts index d26a3cc5c2..8cc7657e83 100644 --- a/twake/backend/node/test/e2e/counters.spec.ts +++ b/twake/backend/node/test/e2e/counters.spec.ts @@ -32,7 +32,7 @@ describe("Counters implementation", () => { let counterApi: CounterAPI; let testDbService: TestDbService; - beforeAll(async ends => { + beforeAll(async () => { platform = await init(); testDbService = new TestDbService(platform); @@ -42,11 +42,11 @@ describe("Counters implementation", () => { counterApi = platform.platform.getProvider("counter"); expect(counterApi).toBeTruthy(); - ends(); }); - afterAll(done => { - platform.tearDown().then(done); + afterAll(async () => { + await platform.tearDown(); + platform = null; }); const getCounter = async (type, entity) => { @@ -57,7 +57,7 @@ describe("Counters implementation", () => { let counter: CounterProvider; const counterPk = { id: uuidv1(), counter_type: WorkspaceCounterType.MEMBERS }; - beforeAll(async ends => { + beforeAll(async () => { counter = await getCounter("workspace_counters", WorkspaceCounterEntity); const workspaceUserRepository = await testDbService.getRepository( @@ -75,17 +75,15 @@ describe("Counters implementation", () => { expect(counter).toBeTruthy(); - ends(); }); - it("Initializing empty value", async done => { + it("Initializing empty value", async () => { await counter.increase(counterPk, 0); const val = await counter.get(counterPk); expect(val).toEqual(0); - done(); }); - it("Adding value", async done => { + it("Adding value", async () => { // adding 1 await counter.increase(counterPk, 1); @@ -98,10 +96,9 @@ describe("Counters implementation", () => { val = await counter.get(counterPk); expect(val).toEqual(3); - done(); }); - it("Subtracting value", async done => { + it("Subtracting value", async () => { // Subtracting 2 await counter.increase(counterPk, -2); @@ -114,10 +111,9 @@ describe("Counters implementation", () => { val = await counter.get(counterPk); expect(val).toEqual(-9); - done(); }); - it("Revising counter", async done => { + it("Revising counter", async () => { // Subtracting 2 const workspaceUserRepository = await testDbService.getRepository( @@ -135,7 +131,6 @@ describe("Counters implementation", () => { const val = await counter.get(counterPk); expect(val).toEqual(1); - done(); }); }); @@ -143,7 +138,7 @@ describe("Counters implementation", () => { let counter: CounterProvider; let counterPk: ChannelCounterPrimaryKey; - beforeAll(async ends => { + beforeAll(async () => { counterPk = { id: uuidv1(), company_id: uuidv1(), @@ -169,17 +164,15 @@ describe("Counters implementation", () => { expect(counter).toBeTruthy(); - ends(); }); - it("Initializing empty value", async done => { + it("Initializing empty value", async () => { await counter.increase(counterPk, 0); const val = await counter.get(counterPk); expect(val).toEqual(0); - done(); }); - it("Adding value", async done => { + it("Adding value", async () => { // adding 1 await counter.increase(counterPk, 1); @@ -192,10 +185,9 @@ describe("Counters implementation", () => { val = await counter.get(counterPk); expect(val).toEqual(3); - done(); }); - it("Subtracting value", async done => { + it("Subtracting value", async () => { // Subtracting 2 await counter.increase(counterPk, -2); @@ -208,10 +200,9 @@ describe("Counters implementation", () => { val = await counter.get(counterPk); expect(val).toEqual(-9); - done(); }); - it("Revising counter", async done => { + it("Revising counter", async () => { // Subtracting 2 const memberOfChannelRepository = await testDbService.getRepository( @@ -233,7 +224,6 @@ describe("Counters implementation", () => { const val = await counter.get(counterPk); expect(val).toEqual(1); - done(); }); }); }); diff --git a/twake/backend/node/test/e2e/documents/documents.spec.ts b/twake/backend/node/test/e2e/documents/documents.spec.ts index 7a2410b1ec..61303a1caa 100644 --- a/twake/backend/node/test/e2e/documents/documents.spec.ts +++ b/twake/backend/node/test/e2e/documents/documents.spec.ts @@ -51,7 +51,7 @@ describe("the Documents feature", () => { }); describe("On user send Drive item", () => { - it("did create the drive item", async done => { + it("did create the drive item", async () => { await TestDbService.getInstance(platform, true); const item = { @@ -69,10 +69,9 @@ describe("the Documents feature", () => { expect(result.name).toEqual("new test file"); expect(result.added).toBeDefined(); - done && done(); }); - it("did fetch the drive item", async done => { + it("did fetch the drive item", async () => { const response = await e2e_getDocument(platform, ""); const result = deserialize( DriveItemDetailsMockClass, @@ -81,7 +80,6 @@ describe("the Documents feature", () => { expect(result.item.name).toEqual("root"); - done && done(); }); }); }); diff --git a/twake/backend/node/test/e2e/files/files.spec.ts b/twake/backend/node/test/e2e/files/files.spec.ts index 32f8da328b..0c24ce75e3 100644 --- a/twake/backend/node/test/e2e/files/files.spec.ts +++ b/twake/backend/node/test/e2e/files/files.spec.ts @@ -19,10 +19,9 @@ describe.skip("The Files feature", () => { }); }); - afterAll(async done => { + afterAll(async () => { await platform?.tearDown(); platform = null; - done(); }); describe("On user send files", () => { @@ -36,7 +35,7 @@ describe.skip("The Files feature", () => { ].map(p => `${__dirname}/${p}`); const thumbnails = [1, 1, 2, 5, 0, 1]; - it("should save file and generate previews", async done => { + it("should save file and generate previews", async () => { for (const i in files) { const file = files[i]; @@ -66,7 +65,6 @@ describe.skip("The Files feature", () => { } } - done(); }, 120000); }); }); diff --git a/twake/backend/node/test/e2e/messages/messages.files.search.spec.ts b/twake/backend/node/test/e2e/messages/messages.files.search.spec.ts index 5da6fcb5f4..1d21cb7aaa 100644 --- a/twake/backend/node/test/e2e/messages/messages.files.search.spec.ts +++ b/twake/backend/node/test/e2e/messages/messages.files.search.spec.ts @@ -29,10 +29,9 @@ describe("Search files", () => { channelUtils = getChannelUtils(platform); }); - afterAll(async done => { + afterAll(async () => { await platform?.tearDown(); platform = null; - done(); }); const files = [ @@ -50,7 +49,7 @@ describe("Search files", () => { }; } - it("should return uploaded files", async done => { + it("should return uploaded files", async () => { let channel = channelUtils.getChannel(); channel = (await gr.services.channels.channels.save(channel, {}, getContext())).entity; const channelId = channel.id; @@ -117,7 +116,6 @@ describe("Search files", () => { resources = await search("sam"); expect(resources.length).toEqual(5); - done(); }); async function search( diff --git a/twake/backend/node/test/e2e/messages/messages.files.spec.ts b/twake/backend/node/test/e2e/messages/messages.files.spec.ts index 01b50f794a..ee8a4c4b84 100644 --- a/twake/backend/node/test/e2e/messages/messages.files.spec.ts +++ b/twake/backend/node/test/e2e/messages/messages.files.spec.ts @@ -48,7 +48,7 @@ describe("The Messages Files feature", () => { }); describe("On user send files", () => { - it("did add the files when full information is given (external source)", async done => { + it("did add the files when full information is given (external source)", async () => { const file: MessageFile = { cache: { channel_id: "", company_id: "", user_id: "", workspace_id: "" }, company_id: "", @@ -78,10 +78,9 @@ describe("The Messages Files feature", () => { expect(result.resource.message.files[0].metadata.external_id).toBe("1234"); expect(result.resource.message.files[0].metadata.source).toBe("linshare"); - done(); }); - it("did not deduplicate files", async done => { + it("did not deduplicate files", async () => { const file: MessageFile = { cache: { channel_id: "", company_id: "", user_id: "", workspace_id: "" }, company_id: "", @@ -141,7 +140,6 @@ describe("The Messages Files feature", () => { expect(messageUpdated.resource.files.length).toBe(2); expect(messageUpdated.resource.files.filter(f => f.id === firstFileId).length).toBe(1); - done(); }); }); }); @@ -158,10 +156,9 @@ describe("List user files", () => { await platform.database.getConnector().drop(); }); - afterAll(async done => { + afterAll(async () => { await platform?.tearDown(); platform = null; - done(); }); const files = [ @@ -172,7 +169,7 @@ describe("List user files", () => { "../files/assets/sample.zip", ].map(p => `${__dirname}/${p}`); - it("should return uploaded files", async done => { + it("should return uploaded files", async () => { const jwtToken = await platform.auth.getJWTToken(); const uploadedFiles = []; @@ -271,10 +268,9 @@ describe("List user files", () => { resources.forEach(checkResource); - done(); }); - it("should return downloaded files", async done => { + it("should return downloaded files", async () => { const jwtToken = await platform.auth.getJWTToken({ sub: v1() }); const uploadedFiles = []; for (const i in files) { @@ -352,7 +348,6 @@ describe("List user files", () => { context: expect.any(Object), }); - done(); }); }); diff --git a/twake/backend/node/test/e2e/messages/messages.messages.spec.ts b/twake/backend/node/test/e2e/messages/messages.messages.spec.ts index 2d30b256c1..e7ba600192 100644 --- a/twake/backend/node/test/e2e/messages/messages.messages.spec.ts +++ b/twake/backend/node/test/e2e/messages/messages.messages.spec.ts @@ -107,7 +107,7 @@ describe("The Messages feature", () => { }); describe("Inbox", () => { - it("Should get recent user messages", async done => { + it("Should get recent user messages", async () => { const directChannelIn = channelUtils.getDirectChannel(); const members = [platform.currentUser.id, uuidv1()]; const directWorkspace: Workspace = { @@ -193,7 +193,6 @@ describe("The Messages feature", () => { }); } - done(); }); }); }); diff --git a/twake/backend/node/test/e2e/messages/messages.search.spec.ts b/twake/backend/node/test/e2e/messages/messages.search.spec.ts index f1c3afdef2..fa7c728978 100644 --- a/twake/backend/node/test/e2e/messages/messages.search.spec.ts +++ b/twake/backend/node/test/e2e/messages/messages.search.spec.ts @@ -16,7 +16,7 @@ describe("The /messages API", () => { let platform: TestPlatform; let channelUtils: ChannelUtils; - beforeAll(async ends => { + beforeAll(async () => { platform = await init({ services: [ "database", @@ -56,18 +56,15 @@ describe("The /messages API", () => { const user = await testDbService.createUser([workspacePk], {}); platform.currentUser.id = user.id; - - ends(); }); - afterAll(async ends => { + afterAll(async () => { platform && (await platform.tearDown()); platform = null; - ends(); }); describe("The GET /messages/?search=... route", () => { - it("Should find the searched messages", async done => { + it("Should find the searched messages", async () => { // await testDbService.createWorkspace(workspacePk2); const channel = await createChannel(); @@ -118,9 +115,8 @@ describe("The /messages API", () => { expect(resources.length).toEqual(1); - done(); }); - it("Filter out messages from channels we are not member of", async done => { + it("Filter out messages from channels we are not member of", async () => { const anotherUserId = uuidv1(); const channel = await e2e_createChannel(platform, [platform.currentUser.id, anotherUserId]); const anotherChannel = await e2e_createChannel(platform, [anotherUserId], anotherUserId); //Test user is not the owner @@ -189,7 +185,6 @@ describe("The /messages API", () => { const resources5 = await search("Filtered", { sender: anotherUserId, has_files: true }); expect(resources5.length).toEqual(1); - done(); }); }); diff --git a/twake/backend/node/test/e2e/messages/messages.threads.spec.ts b/twake/backend/node/test/e2e/messages/messages.threads.spec.ts index 98d798a2bc..0c4eea5941 100644 --- a/twake/backend/node/test/e2e/messages/messages.threads.spec.ts +++ b/twake/backend/node/test/e2e/messages/messages.threads.spec.ts @@ -41,7 +41,7 @@ describe("The Messages Threads feature", () => { }); describe("On user manage threads", () => { - it("should create new thread", async done => { + it("should create new thread", async () => { const response = await e2e_createThread( platform, [ @@ -76,10 +76,9 @@ describe("The Messages Threads feature", () => { }); expect(result.resource.participants[0].created_at).toBeDefined(); - done(); }); - it("should enforce requester in thread participants", async done => { + it("should enforce requester in thread participants", async () => { const response = await e2e_createThread( platform, [ @@ -116,10 +115,9 @@ describe("The Messages Threads feature", () => { id: platform.currentUser.id, }); - done(); }); - it("should update thread participants when add participant", async done => { + it("should update thread participants when add participant", async () => { //Create thread const thread = await gr.services.messages.threads.save( { @@ -173,10 +171,9 @@ describe("The Messages Threads feature", () => { expect(response.statusCode).toBe(200); expect(result.resource.participants.length).toBe(2); - done(); }); - it("should update thread participants when remove participant", async done => { + it("should update thread participants when remove participant", async () => { //Create thread const thread = await gr.services.messages.threads.save( { @@ -236,7 +233,6 @@ describe("The Messages Threads feature", () => { expect(response.statusCode).toBe(200); expect(result.resource.participants.length).toBe(1); - done(); }); }); }); diff --git a/twake/backend/node/test/e2e/messages/messages.user-bookmarks.realtime.spec.ts b/twake/backend/node/test/e2e/messages/messages.user-bookmarks.realtime.spec.ts index a407e0099d..24d8febc29 100644 --- a/twake/backend/node/test/e2e/messages/messages.user-bookmarks.realtime.spec.ts +++ b/twake/backend/node/test/e2e/messages/messages.user-bookmarks.realtime.spec.ts @@ -47,7 +47,7 @@ describe("The Bookmarks Realtime feature", () => { } describe("On bookmark creation", () => { - it("should notify the client", async done => { + it("should notify the client", async () => { const jwtToken = await platform.auth.getJWTToken(); const roomToken = "twake"; @@ -72,7 +72,6 @@ describe("The Bookmarks Realtime feature", () => { expect(event.type).toEqual("user_message_bookmark"); expect(event.action).toEqual("saved"); expect(event.resource.name).toEqual("mybookmarksaved"); - done(); }); socket.emit("realtime:join", { name: `/companies/${platform.workspace.company_id}/messages/bookmarks`, @@ -87,7 +86,7 @@ describe("The Bookmarks Realtime feature", () => { }); describe("On bookmark removal", () => { - it("should notify the client", async done => { + it("should notify the client", async () => { const instance = await gr.services.messages.userBookmarks.save( { company_id: platform.workspace.company_id, @@ -120,7 +119,6 @@ describe("The Bookmarks Realtime feature", () => { socket.on("realtime:resource", (event: any) => { expect(event.type).toEqual("user_message_bookmark"); expect(event.action).toEqual("deleted"); - done(); }); socket.emit("realtime:join", { name: `/companies/${platform.workspace.company_id}/messages/bookmarks`, diff --git a/twake/backend/node/test/e2e/messages/messages.user-bookmarks.spec.ts b/twake/backend/node/test/e2e/messages/messages.user-bookmarks.spec.ts index 68cb02404b..6630abdb40 100644 --- a/twake/backend/node/test/e2e/messages/messages.user-bookmarks.spec.ts +++ b/twake/backend/node/test/e2e/messages/messages.user-bookmarks.spec.ts @@ -40,7 +40,7 @@ describe("The Messages User Bookmarks feature", () => { }); describe("On user manage bookmmarks", () => { - it("should create new bookmark", async done => { + it("should create new bookmark", async () => { const jwtToken = await platform.auth.getJWTToken(); const response = await platform.app.inject({ method: "POST", @@ -74,10 +74,9 @@ describe("The Messages User Bookmarks feature", () => { }); expect(list.getEntities().length).toBe(1); - done(); }); - it("should prevent duplicated bookmark", async done => { + it("should prevent duplicated bookmark", async () => { // const uuid = uuidv4(); const context = getContext(platform); @@ -125,10 +124,9 @@ describe("The Messages User Bookmarks feature", () => { }); expect(list.getEntities().length).toBe(1); - done(); }); - it("should remove bookmark", async done => { + it("should remove bookmark", async () => { const id = uuidv4(); const context = getContext(platform); @@ -165,10 +163,9 @@ describe("The Messages User Bookmarks feature", () => { }); expect(list.getEntities().length).toBe(0); - done(); }); - it("should list bookmarks", async done => { + it("should list bookmarks", async () => { const context = getContext(platform); await gr.services.messages.userBookmarks.save( @@ -204,7 +201,6 @@ describe("The Messages User Bookmarks feature", () => { expect(response.statusCode).toBe(200); expect(result.resources.length).toBe(1); expect(result.resources[0].name).toBe("mybookmark"); - done(); }); }); }); diff --git a/twake/backend/node/test/e2e/notifications/mention.spec.ts b/twake/backend/node/test/e2e/notifications/mention.spec.ts index bc3ae7d896..752c2fb58f 100644 --- a/twake/backend/node/test/e2e/notifications/mention.spec.ts +++ b/twake/backend/node/test/e2e/notifications/mention.spec.ts @@ -110,7 +110,7 @@ describe("The notification for user mentions", () => { }); } - it("should mention all users when preferences are MENTION", async done => { + it("should mention all users when preferences are MENTION", async () => { const threadId = uuidv1(); const messageId = uuidv1(); const unknownUser = uuidv1(); @@ -146,10 +146,9 @@ describe("The notification for user mentions", () => { expect(message.data.mentions.users).toContain(member3.user_id); expect(message.data.mentions.users).not.toContain(unknownUser); - done(); }); - it("should mention all users when preferences are default ones (ALL)", async done => { + it("should mention all users when preferences are default ones (ALL)", async () => { const messageId = uuidv1(); const unknownUser = uuidv1(); const channel = await createChannel(); @@ -179,10 +178,9 @@ describe("The notification for user mentions", () => { expect(message.data.mentions.users).toContain(member3.user_id); expect(message.data.mentions.users).not.toContain(unknownUser); - done(); }); - it("should not mention users with preferences ALL for replies of threads there are not member of", async done => { + it("should not mention users with preferences ALL for replies of threads there are not member of", async () => { const threadId = uuidv1(); const messageId = uuidv1(); const channel = await createChannel(); @@ -213,10 +211,9 @@ describe("The notification for user mentions", () => { expect(message.data.mentions.users).not.toContain(member.user_id); //The sender is not in the notified users expect(message.data.mentions.users).not.toContain(member3.user_id); - done(); }); - it("should not mention user when notification level is set to NONE", async done => { + it("should not mention user when notification level is set to NONE", async () => { const threadId = uuidv1(); const messageId = uuidv1(); const unknownUser = uuidv1(); @@ -253,10 +250,9 @@ describe("The notification for user mentions", () => { expect(message.data.mentions.users).toContain(member3.user_id); expect(message.data.mentions.users).not.toContain(member2.user_id); - done(); }); - it("should mention user when notification level is set to channel mention and notification is for @all", async done => { + it("should mention user when notification level is set to channel mention and notification is for @all", async () => { const threadId = uuidv1(); const messageId = uuidv1(); const channel = await createChannel(); @@ -293,10 +289,9 @@ describe("The notification for user mentions", () => { expect(message.data.mentions.users).toContain(member2.user_id); expect(message.data.mentions.users).not.toContain(member3.user_id); - done(); }); - it("should mention user when notification level is set to channel mention and notification is for @here", async done => { + it("should mention user when notification level is set to channel mention and notification is for @here", async () => { const threadId = uuidv1(); const messageId = uuidv1(); const channel = await createChannel(); @@ -331,10 +326,9 @@ describe("The notification for user mentions", () => { expect(message.data.mentions.users).toContain(member2.user_id); expect(message.data.mentions.users).not.toContain(member3.user_id); - done(); }); - it("should mention user when notification level is set to ME and updated notification later", async done => { + it("should mention user when notification level is set to ME and updated notification later", async () => { const threadId = uuidv1(); const messageId = uuidv1(); const channel = await createChannel(); @@ -376,6 +370,5 @@ describe("The notification for user mentions", () => { expect(message.data.mentions.users).not.toContain(member3.user_id); expect(message.data.mentions.users).toContain(member2.user_id); - done(); }); }); diff --git a/twake/backend/node/test/e2e/statistics.spec.ts b/twake/backend/node/test/e2e/statistics.spec.ts index 4d70b35f38..9b55c7c3b6 100644 --- a/twake/backend/node/test/e2e/statistics.spec.ts +++ b/twake/backend/node/test/e2e/statistics.spec.ts @@ -20,28 +20,25 @@ describe("Statistics implementation", () => { // let database: DatabaseServiceAPI; let channelUtils: ChannelUtils; - beforeAll(async ends => { + beforeAll(async () => { platform = await init({ services: ["database", "statistics", "webserver", "auth"], }); expect(gr.services.statistics).toBeTruthy(); - ends(); channelUtils = getChannelUtils(platform); }); - beforeEach(async ends => { + beforeEach(async () => { await platform.database.getConnector().drop(); - ends(); }); - afterAll(async done => { + afterAll(async () => { await platform.tearDown(); - done(); }); - it("Check statistics counters", async done => { + it("Check statistics counters", async () => { console.log(await gr.services.statistics.get(undefined, "counter-test")); expect(await gr.services.statistics.get(undefined, "counter-test")).toEqual(0); @@ -65,7 +62,6 @@ describe("Statistics implementation", () => { expect(await gr.services.statistics.get(secondCompanyId, "counter-test2")).toEqual(0); expect(await gr.services.statistics.get(undefined, "counter-test2")).toEqual(1); - done(); }); function getContext(user?: User): WorkspaceExecutionContext { diff --git a/twake/backend/node/test/e2e/users/users.search.spec.ts b/twake/backend/node/test/e2e/users/users.search.spec.ts index b95d1320e0..dd66ad2262 100644 --- a/twake/backend/node/test/e2e/users/users.search.spec.ts +++ b/twake/backend/node/test/e2e/users/users.search.spec.ts @@ -7,7 +7,7 @@ describe("The /users API", () => { const url = "/internal/services/users/v1"; let platform: TestPlatform; - beforeEach(async ends => { + beforeEach(async () => { platform = await init({ services: [ "database", @@ -26,17 +26,15 @@ describe("The /users API", () => { "platform-services", ], }); - ends(); }); - afterEach(async ends => { + afterEach(async () => { platform && (await platform.tearDown()); platform = null; - ends(); }); describe("The GET /users/?search=... route", () => { - it("Should find the searched users", async done => { + it("Should find the searched users", async () => { const testDbService = new TestDbService(platform); await testDbService.createCompany(platform.workspace.company_id); const workspacePk = { @@ -122,7 +120,6 @@ describe("The /users API", () => { resources = await search("rbs@twake.app", uuidv1()); expect(resources.length).toBe(0); - done(); }); }); diff --git a/twake/backend/node/test/e2e/users/users.spec.ts b/twake/backend/node/test/e2e/users/users.spec.ts index a8c031306c..e08145b23e 100644 --- a/twake/backend/node/test/e2e/users/users.spec.ts +++ b/twake/backend/node/test/e2e/users/users.spec.ts @@ -19,17 +19,15 @@ describe("The /users API", () => { const nonExistentId = uuidv1(); - beforeEach(async ends => { + beforeEach(async () => { platform = await init(); - ends(); }); - afterEach(async ends => { + afterEach(async () => { await platform.tearDown(); platform = null; - ends(); }); - beforeAll(async ends => { + beforeAll(async () => { const platform = await init({ services: [ "database", @@ -62,25 +60,19 @@ describe("The /users API", () => { }); await testDbService.createUser([workspacePk]); - ends(); - }); - - afterAll(async ends => { - ends(); }); describe("The GET /users/:id route", () => { - it("should 401 when not authenticated", async done => { + it("should 401 when not authenticated", async () => { const response = await platform.app.inject({ method: "GET", url: `${url}/users/1`, }); expect(response.statusCode).toBe(401); - done(); }); - it("should 404 when user does not exists", async done => { + it("should 404 when user does not exists", async () => { const jwtToken = await platform.auth.getJWTToken({ sub: testDbService.users[0].id }); const response = await platform.app.inject({ method: "GET", @@ -96,10 +88,9 @@ describe("The /users API", () => { message: `User ${nonExistentId} not found`, statusCode: 404, }); - done(); }); - it("should 200 and big response for myself", async done => { + it("should 200 and big response for myself", async () => { const myId = testDbService.users[0].id; const jwtToken = await platform.auth.getJWTToken({ sub: myId }); const response = await platform.app.inject({ @@ -150,10 +141,9 @@ describe("The /users API", () => { ]), ); - done(); }); - it("should 200 and short response for another user", async done => { + it("should 200 and short response for another user", async () => { const myId = testDbService.users[0].id; const anotherUserId = testDbService.users[1].id; @@ -191,22 +181,20 @@ describe("The /users API", () => { companies: expect.anything(), }); - done(); }); }); describe("The GET /users route", () => { - it("should 401 when user is not authenticated", async done => { + it("should 401 when user is not authenticated", async () => { const response = await platform.app.inject({ method: "GET", url: `${url}/users`, }); expect(response.statusCode).toBe(401); - done(); }); - it("should 200 with array of users", async done => { + it("should 200 with array of users", async () => { const myId = testDbService.users[0].id; const anotherUserId = testDbService.users[1].id; @@ -228,22 +216,20 @@ describe("The /users API", () => { expect(json).toMatchObject({ resources: expect.any(Array) }); const resources = json.resources; - done(); }); }); describe("The GET /users/:user_id/companies route", () => { - it("should 401 when not authenticated", async done => { + it("should 401 when not authenticated", async () => { const response = await platform.app.inject({ method: "GET", url: `${url}/users/1/companies`, }); expect(response.statusCode).toBe(401); - done(); }); - it("should 404 when user does not exists", async done => { + it("should 404 when user does not exists", async () => { const jwtToken = await platform.auth.getJWTToken({ sub: testDbService.users[0].id }); const response = await platform.app.inject({ method: "GET", @@ -259,10 +245,9 @@ describe("The /users API", () => { message: `User ${nonExistentId} not found`, statusCode: 404, }); - done(); }); - it("should 200 and on correct request", async done => { + it("should 200 and on correct request", async () => { const myId = testDbService.users[0].id; const anotherUserId = testDbService.users[1].id; @@ -306,21 +291,19 @@ describe("The /users API", () => { }); } } - done(); }); }); describe("The GET /companies/:company_id route", () => { - it("should 404 when company does not exists", async done => { + it("should 404 when company does not exists", async () => { const response = await platform.app.inject({ method: "GET", url: `${url}/companies/11111111-1111-1111-1111-111111111111`, }); expect(response.statusCode).toBe(404); - done(); }); - it("should 200 when company exists", async done => { + it("should 200 when company exists", async () => { const companyId = testDbService.company.id; const response = await platform.app.inject({ @@ -354,7 +337,6 @@ describe("The /users API", () => { total_messages: expect.any(Number), }); - done(); }); }); @@ -362,7 +344,7 @@ describe("The /users API", () => { const deviceToken = "testDeviceToken"; describe("Register device (POST)", () => { - it("should 400 when type is not FCM", async done => { + it("should 400 when type is not FCM", async () => { const myId = testDbService.users[0].id; const jwtToken = await platform.auth.getJWTToken({ sub: myId }); @@ -388,10 +370,9 @@ describe("The /users API", () => { error: "Bad Request", message: "Type should be FCM only", }); - done(); }); - it("should 200 when ok", async done => { + it("should 200 when ok", async () => { const firstId = testDbService.users[0].id; const jwtToken = await platform.auth.getJWTToken({ sub: firstId }); @@ -429,10 +410,9 @@ describe("The /users API", () => { version: "1", }); - done(); }); - it("should 200 when register token to another person", async done => { + it("should 200 when register token to another person", async () => { const firstId = testDbService.users[0].id; const secondId = testDbService.users[1].id; @@ -477,11 +457,10 @@ describe("The /users API", () => { user = await testDbService.getUserFromDb({ id: firstId }); expect(user.devices).toMatchObject([]); - done(); }); }); describe("List registered devices (GET)", () => { - it("should 200 when request devices", async done => { + it("should 200 when request devices", async () => { const myId = testDbService.users[1].id; const jwtToken = await platform.auth.getJWTToken({ sub: myId }); @@ -504,12 +483,11 @@ describe("The /users API", () => { }, ], }); - done(); }); }); describe("De-register device (DELETE)", () => { - it("should 200 when device not found for the user", async done => { + it("should 200 when device not found for the user", async () => { const myId = testDbService.users[1].id; const jwtToken = await platform.auth.getJWTToken({ sub: myId }); @@ -532,10 +510,9 @@ describe("The /users API", () => { version: "1", }); - done(); }); - it("should 200 when device found and device should be removed", async done => { + it("should 200 when device found and device should be removed", async () => { const myId = testDbService.users[1].id; const jwtToken = await platform.auth.getJWTToken({ sub: myId }); @@ -553,13 +530,12 @@ describe("The /users API", () => { const device = await testDbService.getDeviceFromDb(deviceToken); expect(device).toBeFalsy(); - done(); }); }); }); describe("Recent contacts", () => { - it("should return list of recent contacts of user", async done => { + it("should return list of recent contacts of user", async () => { // api = new Api(platform); const channelUtils = getChannelUtils(platform); @@ -639,7 +615,6 @@ describe("The /users API", () => { expect(result.resources.length).toEqual(5); expect(result.resources[0].first_name).toEqual("FirstName2"); - done(); }); }); }); diff --git a/twake/backend/node/test/e2e/websocket/auth.spec.ts b/twake/backend/node/test/e2e/websocket/auth.spec.ts index 2326101c1b..7c3447ea16 100644 --- a/twake/backend/node/test/e2e/websocket/auth.spec.ts +++ b/twake/backend/node/test/e2e/websocket/auth.spec.ts @@ -8,7 +8,7 @@ describe("The Websocket authentication", () => { let platform: TestPlatform; let socket: SocketIOClient.Socket; - beforeEach(async ends => { + beforeEach(async () => { platform = await init({ services: [ "webserver", @@ -31,15 +31,13 @@ describe("The Websocket authentication", () => { socket = io.connect("http://localhost:3000", { path: "/socket" }); - ends(); }); - afterEach(async ends => { + afterEach(async () => { platform && (await platform.tearDown()); platform = null; socket && socket.close(); socket = null; - ends(); }); describe("JWT-based Authentication", () => { @@ -71,7 +69,7 @@ describe("The Websocket authentication", () => { }); }); - it("should be able to connect with a JWT token", async done => { + it("should be able to connect with a JWT token", async () => { const token = await platform.auth.getJWTToken(); socket.connect(); @@ -79,10 +77,9 @@ describe("The Websocket authentication", () => { socket .emit("authenticate", { token }) .on("authenticated", () => { - done(); }) .on("unauthorized", () => { - done(new Error("Should not occur")); + new Error("Should not occur"); }); }); }); diff --git a/twake/backend/node/test/e2e/websocket/realtime.spec.ts b/twake/backend/node/test/e2e/websocket/realtime.spec.ts index d519932852..71b18e4411 100644 --- a/twake/backend/node/test/e2e/websocket/realtime.spec.ts +++ b/twake/backend/node/test/e2e/websocket/realtime.spec.ts @@ -8,7 +8,7 @@ describe("The Realtime API", () => { let platform: TestPlatform; let socket: SocketIOClient.Socket; - beforeEach(async ends => { + beforeEach(async () => { platform = await init({ services: [ "webserver", @@ -30,20 +30,18 @@ describe("The Realtime API", () => { socket = io.connect("http://localhost:3000", { path: "/socket" }); - ends(); }); - afterEach(async ends => { + afterEach(async () => { await platform.tearDown(); platform = null; socket && socket.close(); socket = null; - ends(); }); describe("Joining rooms", () => { - it("should fail when token is not defined", async done => { + it("should fail when token is not defined", async () => { const token = await platform.auth.getJWTToken(); const name = "/ping"; @@ -54,7 +52,6 @@ describe("The Realtime API", () => { socket.emit("realtime:join", { name }); socket.on("realtime:join:error", (event: any) => { expect(event.name).toEqual(name); - done(); }); socket.on("realtime:join:success", () => done(new Error("Should not occur"))); }) @@ -64,7 +61,7 @@ describe("The Realtime API", () => { }); }); - it("should fail when token is not valid", async done => { + it("should fail when token is not valid", async () => { const token = await platform.auth.getJWTToken(); const name = "/ping"; const roomToken = "invalid token"; @@ -76,7 +73,6 @@ describe("The Realtime API", () => { socket.emit("realtime:join", { name, token: roomToken }); socket.on("realtime:join:error", (event: any) => { expect(event.name).toEqual(name); - done(); }); socket.on("realtime:join:success", () => done(new Error("Should not occur"))); }) @@ -86,7 +82,7 @@ describe("The Realtime API", () => { }); }); - it("should receive a realtime:join:success when token is valid and room has been joined", async done => { + it("should receive a realtime:join:success when token is valid and room has been joined", async () => { const token = await platform.auth.getJWTToken(); const name = "test"; const roomToken = "twake"; @@ -99,7 +95,6 @@ describe("The Realtime API", () => { socket.on("realtime:join:error", () => done(new Error("Should not occur"))); socket.on("realtime:join:success", (event: any) => { expect(event.name).toEqual(name); - done(); }); }) .on("unauthorized", () => { @@ -110,7 +105,7 @@ describe("The Realtime API", () => { }); describe("Leaving rooms", () => { - it("should not fail when room has not been joined first", async done => { + it("should not fail when room has not been joined first", async () => { const token = await platform.auth.getJWTToken(); const name = "roomtest"; @@ -122,7 +117,6 @@ describe("The Realtime API", () => { socket.on("realtime:leave:error", () => done(new Error("should not fail"))); socket.on("realtime:leave:success", (event: any) => { expect(event.name).toEqual(name); - done(); }); }) .on("unauthorized", () => { @@ -131,7 +125,7 @@ describe("The Realtime API", () => { }); }); - it("should send success when room has been joined first", async done => { + it("should send success when room has been joined first", async () => { const token = await platform.auth.getJWTToken(); const roomToken = "twake"; const name = "roomtest"; @@ -145,7 +139,6 @@ describe("The Realtime API", () => { socket.on("realtime:leave:error", () => done(new Error("should not fail"))); socket.on("realtime:leave:success", (event: any) => { expect(event.name).toEqual(name); - done(); }); }) .on("unauthorized", () => { diff --git a/twake/backend/node/test/e2e/workspaces/workspace-pending-users.spec.ts b/twake/backend/node/test/e2e/workspaces/workspace-pending-users.spec.ts index cc021fcbf7..063b2d856c 100644 --- a/twake/backend/node/test/e2e/workspaces/workspace-pending-users.spec.ts +++ b/twake/backend/node/test/e2e/workspaces/workspace-pending-users.spec.ts @@ -7,13 +7,12 @@ import gr from "../../../src/services/global-resolver"; THIS TESTS RUNS ONLY FOR THE CONSOLE-MODE (CONSOLE TYPE: INTERNAL) */ -export const it = (name: string, cb: (a: any) => void) => { - _it(name, async done => { +export const it = async (name: string, cb: (a: any) => void) => { + return _it(name, async () => { if (gr.services.console.consoleType === "internal") { - cb(done); + await cb(); } else { console.warn(`[skipped]: ${name} (no-console mode only)`); - done(); } }); }; @@ -37,7 +36,7 @@ describe("The /workspace/pending users API", () => { return Promise.resolve(gr.services.console.consoleType === "remote"); } - beforeAll(async ends => { + beforeAll(async () => { platform = await init({ services: [ "user", @@ -79,16 +78,14 @@ describe("The /workspace/pending users API", () => { email: fourthUser, }); - ends(); }); - afterAll(async ends => { + afterAll(async () => { await platform.tearDown(); - ends(); }); describe("Invite users to a workspace by email", () => { - it("should 401 when not authenticated", async done => { + it("should 401 when not authenticated", async () => { const companyId = testDbService.company.id; const response = await platform.app.inject({ @@ -96,10 +93,9 @@ describe("The /workspace/pending users API", () => { url: `${url}/companies/${companyId}/workspaces/${nonExistentId}/users/invite`, }); expect(response.statusCode).toBe(401); - done(); }); - it("should 404 when workspace not found", async done => { + it("should 404 when workspace not found", async () => { const userId = testDbService.users[0].id; const jwtToken = await platform.auth.getJWTToken({ sub: userId }); @@ -120,10 +116,9 @@ describe("The /workspace/pending users API", () => { }); expect(response.statusCode).toBe(404); - done(); }); - it("should 403 when requester is not at least workspace member", async done => { + it("should 403 when requester is not at least workspace member", async () => { const workspace_id = testDbService.workspaces[2].workspace.id; const userId = testDbService.workspaces[2].users[0].id; @@ -144,10 +139,9 @@ describe("The /workspace/pending users API", () => { }, }); expect(response.statusCode).toBe(403); - done(); }); - it("should 200 when ok", async done => { + it("should 200 when ok", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[0].workspace.id; const userId = testDbService.workspaces[0].users[0].id; @@ -190,10 +184,9 @@ describe("The /workspace/pending users API", () => { }); } - done(); }); - it("should fail in response with already added users", async done => { + it("should fail in response with already added users", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[0].workspace.id; const userId = testDbService.workspaces[0].users[0].id; @@ -234,12 +227,11 @@ describe("The /workspace/pending users API", () => { status: "ok", }); - done(); }); }); describe("Delete a pending user from a workspace", () => { - it("should 401 when not authenticated", async done => { + it("should 401 when not authenticated", async () => { const companyId = testDbService.company.id; const email = "first@test-user.com"; @@ -249,10 +241,9 @@ describe("The /workspace/pending users API", () => { }); expect(response.statusCode).toBe(401); - done(); }); - it("should 404 when workspace not found", async done => { + it("should 404 when workspace not found", async () => { const companyId = testDbService.company.id; const email = "first@test-user.com"; @@ -266,10 +257,9 @@ describe("The /workspace/pending users API", () => { }); expect(response.statusCode).toBe(404); - done(); }); - it("should 403 when requester is not at least workspace member", async done => { + it("should 403 when requester is not at least workspace member", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[2].workspace.id; const userId = testDbService.workspaces[2].users[0].id; @@ -284,10 +274,9 @@ describe("The /workspace/pending users API", () => { }); expect(response.statusCode).toBe(403); - done(); }); - it("should {status:error} when email is absent in pending list", async done => { + it("should {status:error} when email is absent in pending list", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[0].workspace.id; const userId = testDbService.workspaces[0].users[0].id; @@ -305,10 +294,9 @@ describe("The /workspace/pending users API", () => { status: "error", }); - done(); }); - it("should 200 when ok", async done => { + it("should 200 when ok", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[0].workspace.id; const userId = testDbService.workspaces[0].users[0].id; @@ -326,12 +314,11 @@ describe("The /workspace/pending users API", () => { status: "success", }); - done(); }); }); describe("Get list of pending users in workspace", () => { - it("should 401 when not authenticated", async done => { + it("should 401 when not authenticated", async () => { const companyId = testDbService.company.id; const email = "first@test-user.com"; @@ -340,10 +327,9 @@ describe("The /workspace/pending users API", () => { url: `${url}/companies/${companyId}/workspaces/${nonExistentId}/pending`, }); expect(response.statusCode).toBe(401); - done(); }); - it("should 404 when workspace not found", async done => { + it("should 404 when workspace not found", async () => { const companyId = testDbService.company.id; const email = "first@test-user.com"; @@ -357,10 +343,9 @@ describe("The /workspace/pending users API", () => { }); expect(response.statusCode).toBe(404); - done(); }); - it("should 403 when requester is not at least workspace member", async done => { + it("should 403 when requester is not at least workspace member", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[2].workspace.id; const userId = testDbService.workspaces[2].users[0].id; @@ -375,10 +360,9 @@ describe("The /workspace/pending users API", () => { }); expect(response.statusCode).toBe(403); - done(); }); - it("should 200 when ok", async done => { + it("should 200 when ok", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[0].workspace.id; const userId = testDbService.workspaces[0].users[0].id; @@ -408,10 +392,9 @@ describe("The /workspace/pending users API", () => { company_role: "member", }); - done(); }); - it("existed user should be added instantly", async done => { + it("existed user should be added instantly", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[0].workspace.id; const userId = testDbService.workspaces[0].users[0].id; @@ -431,7 +414,6 @@ describe("The /workspace/pending users API", () => { console.log("resources B: ", resources); expect(resources.find((a: any) => a.user.email === emailForExistedUser)).toBeDefined(); - done(); }); }); }); diff --git a/twake/backend/node/test/e2e/workspaces/workspace-users.spec.ts b/twake/backend/node/test/e2e/workspaces/workspace-users.spec.ts index c70f2e836c..f81171871d 100644 --- a/twake/backend/node/test/e2e/workspaces/workspace-users.spec.ts +++ b/twake/backend/node/test/e2e/workspaces/workspace-users.spec.ts @@ -37,7 +37,7 @@ describe("The /workspace users API", () => { }); }; - beforeAll(async ends => { + beforeAll(async () => { platform = await init({ services: [ "database", @@ -76,16 +76,14 @@ describe("The /workspace users API", () => { await testDbService.createUser([ws2pk], { workspaceRole: "member" }); await testDbService.createUser([], { companyRole: "member" }); await testDbService.createUser([ws3pk], { companyRole: "guest", workspaceRole: "member" }); - ends(); }); - afterAll(async ends => { + afterAll(async () => { await platform.tearDown(); - ends(); }); describe("The GET /workspaces/users route", () => { - it("should 401 when not authenticated", async done => { + it("should 401 when not authenticated", async () => { const companyId = testDbService.company.id; const response = await platform.app.inject({ @@ -93,10 +91,9 @@ describe("The /workspace users API", () => { url: `${url}/companies/${companyId}/workspaces/${nonExistentId}/users`, }); expect(response.statusCode).toBe(401); - done(); }); - it("should 404 when workspace not found", async done => { + it("should 404 when workspace not found", async () => { const userId = testDbService.users[0].id; const jwtToken = await platform.auth.getJWTToken({ sub: userId }); @@ -107,10 +104,9 @@ describe("The /workspace users API", () => { headers: { authorization: `Bearer ${jwtToken}` }, }); expect(response.statusCode).toBe(404); - done(); }); - it("should 200 when ok", async done => { + it("should 200 when ok", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[2].workspace.id; const userId = testDbService.workspaces[2].users[0].id; @@ -131,12 +127,11 @@ describe("The /workspace users API", () => { checkUserObject(resource); } - done(); }); }); describe("The GET /workspaces/users/:user_id route", () => { - it("should 401 when not authenticated", async done => { + it("should 401 when not authenticated", async () => { const companyId = testDbService.company.id; const userId = testDbService.users[0].id; @@ -145,10 +140,9 @@ describe("The /workspace users API", () => { url: `${url}/companies/${companyId}/workspaces/${nonExistentId}/users/${userId}`, }); expect(response.statusCode).toBe(401); - done(); }); - it("should 404 when workspace not found", async done => { + it("should 404 when workspace not found", async () => { const userId = testDbService.users[0].id; const jwtToken = await platform.auth.getJWTToken({ sub: userId }); @@ -159,10 +153,9 @@ describe("The /workspace users API", () => { headers: { authorization: `Bearer ${jwtToken}` }, }); expect(response.statusCode).toBe(404); - done(); }); - it("should 200 when ok", async done => { + it("should 200 when ok", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[0].workspace.id; const userId = testDbService.workspaces[0].users[0].id; @@ -177,12 +170,11 @@ describe("The /workspace users API", () => { const resource = response.json()["resource"]; checkUserObject(resource); - done(); }); }); describe("The POST /workspaces/users route (add)", () => { - it("should 401 when not authenticated", async done => { + it("should 401 when not authenticated", async () => { const companyId = testDbService.company.id; const response = await platform.app.inject({ @@ -190,10 +182,9 @@ describe("The /workspace users API", () => { url: `${url}/companies/${companyId}/workspaces/${nonExistentId}/users`, }); expect(response.statusCode).toBe(401); - done(); }); - it("should 403 user is not workspace moderator", async done => { + it("should 403 user is not workspace moderator", async () => { const userId = testDbService.users[0].id; const anotherUserId = testDbService.users[1].id; const workspaceId = testDbService.workspaces[0].workspace.id; @@ -212,10 +203,9 @@ describe("The /workspace users API", () => { }, }); expect(response.statusCode).toBe(403); - done(); }); - it("should 400 when requested user not in company", async done => { + it("should 400 when requested user not in company", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[2].workspace.id; const userId = testDbService.workspaces[2].users[1].id; @@ -233,10 +223,9 @@ describe("The /workspace users API", () => { }, }); expect(response.statusCode).toBe(400); - done(); }); - it("should 201 when requested already in workspace (ignore)", async done => { + it("should 201 when requested already in workspace (ignore)", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[2].workspace.id; const userId = testDbService.workspaces[2].users[1].id; @@ -254,10 +243,9 @@ describe("The /workspace users API", () => { }, }); expect(response.statusCode).toBe(201); - done(); }); - it("should 200 when ok", async done => { + it("should 200 when ok", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[2].workspace.id; const userId = testDbService.workspaces[2].users[1].id; @@ -294,12 +282,11 @@ describe("The /workspace users API", () => { expect(workspaceUsersCount).toBe(5); // expect(companyUsersCount).toBe(6); - done(); }); }); describe("The POST /workspaces/users/:user_id route (update)", () => { - it("should 401 when not authenticated", async done => { + it("should 401 when not authenticated", async () => { const companyId = testDbService.company.id; const userId = testDbService.users[0].id; @@ -308,10 +295,9 @@ describe("The /workspace users API", () => { url: `${url}/companies/${companyId}/workspaces/${nonExistentId}/users/${userId}`, }); expect(response.statusCode).toBe(401); - done(); }); - it("should 403 user is not workspace moderator", async done => { + it("should 403 user is not workspace moderator", async () => { const userId = testDbService.users[0].id; const anotherUserId = testDbService.users[1].id; const workspaceId = testDbService.workspaces[0].workspace.id; @@ -330,10 +316,9 @@ describe("The /workspace users API", () => { }, }); expect(response.statusCode).toBe(403); - done(); }); - it("should 404 when user not found in workspace", async done => { + it("should 404 when user not found in workspace", async () => { const workspaceId = testDbService.workspaces[2].workspace.id; const userId = testDbService.workspaces[2].users[1].id; const anotherWorkspaceUserId = testDbService.workspaces[3].users[0].id; @@ -351,10 +336,9 @@ describe("The /workspace users API", () => { }); expect(response.statusCode).toBe(404); - done(); }); - it("should 200 when ok", async done => { + it("should 200 when ok", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[2].workspace.id; const userId = testDbService.workspaces[2].users[1].id; @@ -381,12 +365,11 @@ describe("The /workspace users API", () => { const usersCount = await testDbService.getWorkspaceUsersCountFromDb(workspaceId); expect(usersCount).toBe(5); - done(); }); }); describe("The DELETE /workspaces/users/:user_id route", () => { - it("should 401 when not authenticated", async done => { + it("should 401 when not authenticated", async () => { const companyId = testDbService.company.id; const anotherUserId = testDbService.users[1].id; @@ -395,10 +378,9 @@ describe("The /workspace users API", () => { url: `${url}/companies/${companyId}/workspaces/${nonExistentId}/users/${anotherUserId}`, }); expect(response.statusCode).toBe(401); - done(); }); - it("should 403 user is not workspace moderator", async done => { + it("should 403 user is not workspace moderator", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[2].workspace.id; const userId = testDbService.workspaces[2].users[3].id; @@ -415,10 +397,9 @@ describe("The /workspace users API", () => { console.log(response.body); expect(response.statusCode).toBe(403); - done(); }); - it("should 404 when user not found in workspace", async done => { + it("should 404 when user not found in workspace", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[2].workspace.id; const userId = testDbService.workspaces[2].users[1].id; @@ -432,10 +413,9 @@ describe("The /workspace users API", () => { expect(response.statusCode).toBe(404); - done(); }); - it("should 200 when ok", async done => { + it("should 200 when ok", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[2].workspace.id; const userId = testDbService.workspaces[2].users[1].id; @@ -463,7 +443,6 @@ describe("The /workspace users API", () => { const usersCount = await testDbService.getWorkspaceUsersCountFromDb(workspaceId); expect(usersCount).toBe(4); - done(); }); }); }); diff --git a/twake/backend/node/test/e2e/workspaces/workspaces.invite-tokens.spec.ts b/twake/backend/node/test/e2e/workspaces/workspaces.invite-tokens.spec.ts index 908534670f..bdcf9de282 100644 --- a/twake/backend/node/test/e2e/workspaces/workspaces.invite-tokens.spec.ts +++ b/twake/backend/node/test/e2e/workspaces/workspaces.invite-tokens.spec.ts @@ -68,7 +68,7 @@ describe("The /workspaces API (invite tokens)", () => { describe("The GET /tokens/ route", () => { beforeAll(startup); afterAll(shutdown); - it("should 401 when not authenticated", async done => { + it("should 401 when not authenticated", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[0].workspace.id; @@ -78,10 +78,9 @@ describe("The /workspaces API (invite tokens)", () => { url: `${url}/companies/${companyId}/workspaces/${workspaceId}/users/tokens`, }); expect(response.statusCode).toBe(401); - done(); }); - it("should 403 when user is not a workspace member", async done => { + it("should 403 when user is not a workspace member", async () => { const workspaceId = testDbService.workspaces[0].workspace.id; const userIdFromAnotherWorkspace = platform.currentUser.id; const companyId = testDbService.company.id; @@ -95,10 +94,9 @@ describe("The /workspaces API (invite tokens)", () => { }); expect(response.statusCode).toBe(403); - done(); }); - it("should 404 when token doesn't exists yet", async done => { + it("should 404 when token doesn't exists yet", async () => { const workspaceId = testDbService.workspaces[0].workspace.id; const userId = testDbService.workspaces[0].users[0].id; const companyId = testDbService.company.id; @@ -113,10 +111,9 @@ describe("The /workspaces API (invite tokens)", () => { expect(response.statusCode).toBe(404); - done(); }); - it("should 200 when user is a workspace member", async done => { + it("should 200 when user is a workspace member", async () => { const workspaceId = testDbService.workspaces[0].workspace.id; const userId = testDbService.workspaces[0].users[0].id; const companyId = testDbService.company.id; @@ -141,7 +138,6 @@ describe("The /workspaces API (invite tokens)", () => { ], }); - done(); }); }); @@ -149,7 +145,7 @@ describe("The /workspaces API (invite tokens)", () => { beforeAll(startup); afterAll(shutdown); - it("should 401 when not authenticated", async done => { + it("should 401 when not authenticated", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[0].workspace.id; @@ -159,10 +155,9 @@ describe("The /workspaces API (invite tokens)", () => { url: `${url}/companies/${companyId}/workspaces/${workspaceId}/users/tokens`, }); expect(response.statusCode).toBe(401); - done(); }); - it("should 403 when user is not a workspace member", async done => { + it("should 403 when user is not a workspace member", async () => { const workspaceId = testDbService.workspaces[0].workspace.id; const userIdFromAnotherWorkspace = platform.currentUser.id; const companyId = testDbService.company.id; @@ -179,10 +174,9 @@ describe("The /workspaces API (invite tokens)", () => { }); expect(response.statusCode).toBe(403); - done(); }); - it("should 200 when user is a workspace member", async done => { + it("should 200 when user is a workspace member", async () => { const workspaceId = testDbService.workspaces[0].workspace.id; const userId = testDbService.workspaces[0].users[0].id; const companyId = testDbService.company.id; @@ -237,10 +231,9 @@ describe("The /workspaces API (invite tokens)", () => { expect(createToken.t).toEqual(getToken.t); - done(); }); - it("should 200 when when recreate token", async done => { + it("should 200 when when recreate token", async () => { const workspaceId = testDbService.workspaces[0].workspace.id; const userId = testDbService.workspaces[0].users[0].id; const companyId = testDbService.company.id; @@ -304,7 +297,6 @@ describe("The /workspaces API (invite tokens)", () => { expect(responseToken).toEqual(afterResponseToken); expect(afterResponseToken).not.toEqual(beforeResponseToken); - done(); }); }); @@ -312,7 +304,7 @@ describe("The /workspaces API (invite tokens)", () => { beforeAll(startup); afterAll(shutdown); - it("should 401 when not authenticated", async done => { + it("should 401 when not authenticated", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[0].workspace.id; @@ -322,10 +314,9 @@ describe("The /workspaces API (invite tokens)", () => { url: `${url}/companies/${companyId}/workspaces/${workspaceId}/users/tokens/fake1-${new Date().getTime()}`, }); expect(response.statusCode).toBe(401); - done(); }); - it("should 403 when user is not a workspace member", async done => { + it("should 403 when user is not a workspace member", async () => { const workspaceId = testDbService.workspaces[0].workspace.id; const userIdFromAnotherWorkspace = platform.currentUser.id; const companyId = testDbService.company.id; @@ -340,10 +331,9 @@ describe("The /workspaces API (invite tokens)", () => { }); expect(response.statusCode).toBe(403); - done(); }); - it("should 204 when user is a workspace member", async done => { + it("should 204 when user is a workspace member", async () => { const workspaceId = testDbService.workspaces[0].workspace.id; const userId = testDbService.workspaces[0].users[0].id; const companyId = testDbService.company.id; @@ -378,10 +368,9 @@ describe("The /workspaces API (invite tokens)", () => { expect(afterResponse.statusCode).toBe(404); - done(); }); - it("should 404 when deleting token that doesn't exists", async done => { + it("should 404 when deleting token that doesn't exists", async () => { const workspaceId = testDbService.workspaces[0].workspace.id; const userId = testDbService.workspaces[0].users[0].id; const companyId = testDbService.company.id; @@ -396,7 +385,6 @@ describe("The /workspaces API (invite tokens)", () => { }); expect(response.statusCode).toBe(404); - done(); }); }); @@ -415,7 +403,7 @@ describe("The /workspaces API (invite tokens)", () => { }); afterAll(shutdown); - it("should 404 when when token not found", async done => { + it("should 404 when when token not found", async () => { const jwtToken = await platform.auth.getJWTToken({ sub: userId }); const response = await platform.app.inject({ @@ -428,10 +416,9 @@ describe("The /workspaces API (invite tokens)", () => { }, }); expect(response.statusCode).toBe(404); - done(); }); - it("should 200 when user is not authorized", async done => { + it("should 200 when user is not authorized", async () => { const response = await platform.app.inject({ method: "POST", url: `${url}/join`, @@ -455,10 +442,9 @@ describe("The /workspaces API (invite tokens)", () => { auth_required: true, }); - done(); }); - it("should 200 when user is authorized and not joining", async done => { + it("should 200 when user is authorized and not joining", async () => { const jwtToken = await platform.auth.getJWTToken({ sub: userId }); const response = await platform.app.inject({ @@ -484,10 +470,9 @@ describe("The /workspaces API (invite tokens)", () => { auth_required: false, }); - done(); }); - it("should 200 when user is authorized and joining", async done => { + it("should 200 when user is authorized and joining", async () => { const jwtToken = await platform.auth.getJWTToken({ sub: userId }); const response = await platform.app.inject({ @@ -515,7 +500,6 @@ describe("The /workspaces API (invite tokens)", () => { auth_required: false, }); - done(); }); }); }); diff --git a/twake/backend/node/test/e2e/workspaces/workspaces.spec.ts b/twake/backend/node/test/e2e/workspaces/workspaces.spec.ts index d251e3040f..363f263f97 100644 --- a/twake/backend/node/test/e2e/workspaces/workspaces.spec.ts +++ b/twake/backend/node/test/e2e/workspaces/workspaces.spec.ts @@ -12,7 +12,7 @@ describe("The /workspaces API", () => { const nonExistentId = uuidv1(); let companyId = ""; - beforeAll(async ends => { + beforeAll(async () => { platform = await init({ services: [ "database", @@ -46,25 +46,22 @@ describe("The /workspaces API", () => { await testDbService.createUser([ws2pk], { companyRole: "admin" }); await testDbService.createUser([ws2pk], { companyRole: undefined, workspaceRole: "moderator" }); await testDbService.createUser([], { companyRole: "guest" }); - ends(); }); - afterAll(async ends => { + afterAll(async () => { await platform.tearDown(); - ends(); }); describe("The GET /workspaces/ route", () => { - it("should 401 when not authenticated", async done => { + it("should 401 when not authenticated", async () => { const response = await platform.app.inject({ method: "GET", url: `${url}/companies/${nonExistentId}/workspaces`, }); expect(response.statusCode).toBe(401); - done(); }); - it("should 404 when company not found", async done => { + it("should 404 when company not found", async () => { const userId = testDbService.workspaces[0].users[0].id; const jwtToken = await platform.auth.getJWTToken({ sub: userId }); @@ -75,10 +72,9 @@ describe("The /workspaces API", () => { headers: { authorization: `Bearer ${jwtToken}` }, }); expect(response.statusCode).toBe(404); - done(); }); - it("should 200 when company belongs to user", async done => { + it("should 200 when company belongs to user", async () => { const userId = testDbService.workspaces[0].users[0].id; const jwtToken = await platform.auth.getJWTToken({ sub: userId }); @@ -113,12 +109,11 @@ describe("The /workspaces API", () => { } } - done(); }); }); describe("The GET /workspaces/:workspace_id route", () => { - it("should 401 when not authenticated", async done => { + it("should 401 when not authenticated", async () => { const workspaceId = testDbService.workspaces[0].workspace.id; const response = await platform.app.inject({ @@ -126,10 +121,9 @@ describe("The /workspaces API", () => { url: `${url}/companies/${nonExistentId}/workspaces/${workspaceId}`, }); expect(response.statusCode).toBe(401); - done(); }); - it("should 404 when workspace not found", async done => { + it("should 404 when workspace not found", async () => { const userId = testDbService.workspaces[0].users[0].id; const jwtToken = await platform.auth.getJWTToken({ sub: userId }); @@ -139,10 +133,9 @@ describe("The /workspaces API", () => { headers: { authorization: `Bearer ${jwtToken}` }, }); expect(response.statusCode).toBe(404); - done(); }); - it("should 403 when user not belong to workspace and not company_admin", async done => { + it("should 403 when user not belong to workspace and not company_admin", async () => { const workspaceId = testDbService.workspaces[2].workspace.id; const userIdFromAnotherWorkspace = testDbService.workspaces[0].users[0].id; @@ -161,10 +154,9 @@ describe("The /workspaces API", () => { statusCode: 403, }); - done(); }); - it("should 200 when user is company_admin", async done => { + it("should 200 when user is company_admin", async () => { const workspaceId = testDbService.workspaces[0].workspace.id; const userIdFromAnotherWorkspace = testDbService.workspaces[2].users[0].id; @@ -195,10 +187,9 @@ describe("The /workspaces API", () => { }); } - done(); }); - it("should 200 when user is belong to workspace", async done => { + it("should 200 when user is belong to workspace", async () => { const workspaceId = testDbService.workspaces[0].workspace.id; const userIdFromThisWorkspace = testDbService.workspaces[0].users[0].id; @@ -230,14 +221,13 @@ describe("The /workspaces API", () => { }); } - done(); }); }); // create describe("The POST /workspaces route (creating workspace)", () => { - it("should 401 when not authenticated", async done => { + it("should 401 when not authenticated", async () => { const companyId = testDbService.company.id; const response = await platform.app.inject({ @@ -245,10 +235,9 @@ describe("The /workspaces API", () => { url: `${url}/companies/${companyId}/workspaces/${nonExistentId}`, }); expect(response.statusCode).toBe(401); - done(); }); - it("should 403 when user is not (company member or company admin) ", async done => { + it("should 403 when user is not (company member or company admin) ", async () => { const companyId = testDbService.company.id; const userId = testDbService.users[3].id; const jwtToken = await platform.auth.getJWTToken({ sub: userId }); @@ -267,10 +256,9 @@ describe("The /workspaces API", () => { }); expect(response.statusCode).toBe(403); - done(); }); - it("should 201 when workspace created well", async done => { + it("should 201 when workspace created well", async () => { const companyId = testDbService.company.id; const userId = testDbService.users[0].id; const jwtToken = await platform.auth.getJWTToken({ sub: userId }); @@ -302,14 +290,13 @@ describe("The /workspaces API", () => { role: expect.stringMatching(/moderator/), }); - done(); }); }); // update describe("The POST /workspaces/:workspace_id route (updating workspace)", () => { - it("should 401 when not authenticated", async done => { + it("should 401 when not authenticated", async () => { const companyId = testDbService.company.id; const response = await platform.app.inject({ @@ -318,10 +305,9 @@ describe("The /workspaces API", () => { payload: { resource: {} }, }); expect(response.statusCode).toBe(401); - done(); }); - it("should 403 when not workspace not found", async done => { + it("should 403 when not workspace not found", async () => { const companyId = testDbService.company.id; const userId = testDbService.workspaces[0].users[0].id; @@ -336,10 +322,9 @@ describe("The /workspaces API", () => { expect(response.statusCode).toBe(403); - done(); }); - it("should 403 when not belong to workspace", async done => { + it("should 403 when not belong to workspace", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[1].workspace.id; const userId = testDbService.workspaces[0].users[0].id; @@ -355,10 +340,9 @@ describe("The /workspaces API", () => { expect(response.statusCode).toBe(403); - done(); }); - it("should 403 when not workspace moderator", async done => { + it("should 403 when not workspace moderator", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[1].workspace.id; const userId = testDbService.workspaces[0].users[0].id; @@ -374,10 +358,9 @@ describe("The /workspaces API", () => { expect(response.statusCode).toBe(403); - done(); }); - it("should 200 when admin of company (full update)", async done => { + it("should 200 when admin of company (full update)", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[2].workspace.id; const userId = testDbService.workspaces[2].users[0].id; // company owner @@ -412,10 +395,9 @@ describe("The /workspaces API", () => { role: "moderator", //Company admin is a moderator }); - done(); }); - it("should 200 when moderator of workspace (partial update)", async done => { + it("should 200 when moderator of workspace (partial update)", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[2].workspace.id; const userId = testDbService.workspaces[2].users[1].id; // workspace admin @@ -449,14 +431,13 @@ describe("The /workspaces API", () => { role: "moderator", }); - done(); }); }); // delete describe("The DELETE /workspaces route", () => { - it("should 401 when not authenticated", async done => { + it("should 401 when not authenticated", async () => { const companyId = testDbService.company.id; const response = await platform.app.inject({ @@ -464,10 +445,9 @@ describe("The /workspaces API", () => { url: `${url}/companies/${companyId}/workspaces/${nonExistentId}`, }); expect(response.statusCode).toBe(401); - done(); }); - it("should 403 when user is not (company member or company admin) ", async done => { + it("should 403 when user is not (company member or company admin) ", async () => { const companyId = testDbService.company.id; const userId = testDbService.users[3].id; const jwtToken = await platform.auth.getJWTToken({ sub: userId }); @@ -480,10 +460,9 @@ describe("The /workspaces API", () => { }); expect(response.statusCode).toBe(403); - done(); }); - it("should 204 when workspace deleted", async done => { + it("should 204 when workspace deleted", async () => { const companyId = testDbService.company.id; const workspaceId = testDbService.workspaces[2].workspace.id; const userId = testDbService.workspaces[2].users[0].id; @@ -507,7 +486,6 @@ describe("The /workspaces API", () => { expect(checkResponseJson.resources.find((a: any) => a.id === workspaceId)).toBe(undefined); - done(); }); }); }); diff --git a/twake/backend/node/test/unit/core/platform/framework/decorators/realtime/created.test.ts b/twake/backend/node/test/unit/core/platform/framework/decorators/realtime/created.test.ts index 19cd9250a2..7b73b7adf3 100644 --- a/twake/backend/node/test/unit/core/platform/framework/decorators/realtime/created.test.ts +++ b/twake/backend/node/test/unit/core/platform/framework/decorators/realtime/created.test.ts @@ -5,7 +5,7 @@ import { websocketEventBus } from "../../../../../../../src/core/platform/servic import { ResourcePath } from "../../../../../../../src/core/platform/services/realtime/types"; describe("The RealtimeCreated decorator", () => { - it("should call the original method send back original result but do not emit event if result type is wrong", async done => { + it("should call the original method send back original result but do not emit event if result type is wrong", async () => { const emitSpy = jest.spyOn(websocketEventBus, "emit"); class TestMe { @@ -27,10 +27,9 @@ describe("The RealtimeCreated decorator", () => { expect(emitSpy).toHaveBeenCalledTimes(0); emitSpy.mockRestore(); - done(); }); - it("should call the original method send back original result and emit event", async done => { + it("should call the original method send back original result and emit event", async () => { const emitSpy = jest.spyOn(websocketEventBus, "emit"); class TestMe { @@ -68,10 +67,9 @@ describe("The RealtimeCreated decorator", () => { }); emitSpy.mockRestore(); - done(); }); - it("should emit event with path computed from function", async done => { + it("should emit event with path computed from function", async () => { const emitSpy = jest.spyOn(websocketEventBus, "emit"); class TestMe { @@ -111,6 +109,5 @@ describe("The RealtimeCreated decorator", () => { }); emitSpy.mockRestore(); - done(); }); }); diff --git a/twake/backend/node/test/unit/core/platform/framework/decorators/realtime/deleted.test.ts b/twake/backend/node/test/unit/core/platform/framework/decorators/realtime/deleted.test.ts index d41290bad2..5156fe881a 100644 --- a/twake/backend/node/test/unit/core/platform/framework/decorators/realtime/deleted.test.ts +++ b/twake/backend/node/test/unit/core/platform/framework/decorators/realtime/deleted.test.ts @@ -5,7 +5,7 @@ import { websocketEventBus } from "../../../../../../../src/core/platform/servic import { ResourcePath } from "../../../../../../../src/core/platform/services/realtime/types"; describe("The RealtimeDeleted decorator", () => { - it("should call the original method send back original result but do not emit event if result type is wrong", async done => { + it("should call the original method send back original result but do not emit event if result type is wrong", async () => { const emitSpy = jest.spyOn(websocketEventBus, "emit"); class TestMe { @@ -27,10 +27,9 @@ describe("The RealtimeDeleted decorator", () => { expect(emitSpy).toHaveBeenCalledTimes(0); emitSpy.mockRestore(); - done(); }); - it("should call the original method send back original result and emit event", async done => { + it("should call the original method send back original result and emit event", async () => { const emitSpy = jest.spyOn(websocketEventBus, "emit"); class TestMe { @@ -68,10 +67,9 @@ describe("The RealtimeDeleted decorator", () => { }); emitSpy.mockRestore(); - done(); }); - it("should emit event with path computed from function", async done => { + it("should emit event with path computed from function", async () => { const emitSpy = jest.spyOn(websocketEventBus, "emit"); class TestMe { @@ -111,6 +109,5 @@ describe("The RealtimeDeleted decorator", () => { }); emitSpy.mockRestore(); - done(); }); }); diff --git a/twake/backend/node/test/unit/core/platform/framework/decorators/realtime/updated.test.ts b/twake/backend/node/test/unit/core/platform/framework/decorators/realtime/updated.test.ts index af2929cbfb..1f63fabb3f 100644 --- a/twake/backend/node/test/unit/core/platform/framework/decorators/realtime/updated.test.ts +++ b/twake/backend/node/test/unit/core/platform/framework/decorators/realtime/updated.test.ts @@ -5,7 +5,7 @@ import { websocketEventBus } from "../../../../../../../src/core/platform/servic import { ResourcePath } from "../../../../../../../src/core/platform/services/realtime/types"; describe("The RealtimeUpdated decorator", () => { - it("should call the original method send back original result but do not emit event if result type is wrong", async done => { + it("should call the original method send back original result but do not emit event if result type is wrong", async () => { const emitSpy = jest.spyOn(websocketEventBus, "emit"); class TestMe { @@ -27,10 +27,9 @@ describe("The RealtimeUpdated decorator", () => { expect(emitSpy).toHaveBeenCalledTimes(0); emitSpy.mockRestore(); - done(); }); - it("should call the original method send back original result and emit event", async done => { + it("should call the original method send back original result and emit event", async () => { const emitSpy = jest.spyOn(websocketEventBus, "emit"); class TestMe { @@ -69,10 +68,9 @@ describe("The RealtimeUpdated decorator", () => { }); emitSpy.mockRestore(); - done(); }); - it("should emit event with path computed from function", async done => { + it("should emit event with path computed from function", async () => { const emitSpy = jest.spyOn(websocketEventBus, "emit"); class TestMe { @@ -113,6 +111,5 @@ describe("The RealtimeUpdated decorator", () => { }); emitSpy.mockRestore(); - done(); }); }); diff --git a/twake/backend/node/test/unit/services/notifications/services/engine/processors/new-channel-message/index.test.ts b/twake/backend/node/test/unit/services/notifications/services/engine/processors/new-channel-message/index.test.ts index 4688d43182..c871ebb088 100644 --- a/twake/backend/node/test/unit/services/notifications/services/engine/processors/new-channel-message/index.test.ts +++ b/twake/backend/node/test/unit/services/notifications/services/engine/processors/new-channel-message/index.test.ts @@ -138,7 +138,7 @@ describe("The NewChannelMessageProcessor class", () => { ]); } - it("should return undefined when there is no one to notify", async done => { + it("should return undefined when there is no one to notify", async () => { const message = getMessage(true); const result = await processor.process(message); @@ -163,10 +163,9 @@ describe("The NewChannelMessageProcessor class", () => { }); expect(result).toBeUndefined(); - done(); }); - it("without mentions, should get the preferences for all channel members and return only the ones who want to be notified", async done => { + it("without mentions, should get the preferences for all channel members and return only the ones who want to be notified", async () => { const message = getMessage(true); setNewThreadPreferences(); const result = await processor.process(message); @@ -192,10 +191,9 @@ describe("The NewChannelMessageProcessor class", () => { }); expect(result.mentions.users).toEqual(["1"]); - done(); }); - it("with @all mention, should get the preferences for all channel members and return only the ones who want to be notified", async done => { + it("with @all mention, should get the preferences for all channel members and return only the ones who want to be notified", async () => { const message = getMessage(true); message.mentions.specials = ["all"]; setNewThreadPreferences(); @@ -222,10 +220,9 @@ describe("The NewChannelMessageProcessor class", () => { }); expect(result.mentions.users).toEqual(["1", "2"]); - done(); }); - it("with @here mentions, should get the preferences for all channel members and return only the ones who want to be notified", async done => { + it("with @here mentions, should get the preferences for all channel members and return only the ones who want to be notified", async () => { const message = getMessage(true); message.mentions.specials = ["here"]; setNewThreadPreferences(); @@ -252,10 +249,9 @@ describe("The NewChannelMessageProcessor class", () => { }); expect(result.mentions.users).toEqual(["1", "2"]); - done(); }); - it("with @user mentions, should get the preferences for all channel members and return only the ones who want to be notified", async done => { + it("with @user mentions, should get the preferences for all channel members and return only the ones who want to be notified", async () => { const message = getMessage(true); message.mentions.users = ["1", "2", "3", "4"]; setNewThreadPreferences(); @@ -306,10 +302,9 @@ describe("The NewChannelMessageProcessor class", () => { }); expect(result.mentions.users).toEqual(["1", "2", "3"]); - done(); }); - it("When message is a direct message", async done => { + it("When message is a direct message", async () => { const message = getMessage(true); message.workspace_id = ChannelType.DIRECT; message.mentions.users = ["1", "2", "3", "4"]; @@ -361,7 +356,6 @@ describe("The NewChannelMessageProcessor class", () => { }); expect(result.mentions.users).toEqual(["1", "2", "3"]); - done(); }); }); @@ -399,7 +393,7 @@ describe("The NewChannelMessageProcessor class", () => { ]); } - it("should return undefined when there is no one to notify", async done => { + it("should return undefined when there is no one to notify", async () => { const message = getMessage(); setUsersInThread(["1", "2", "3", "4"]); const result = await processor.process(message); @@ -421,10 +415,9 @@ describe("The NewChannelMessageProcessor class", () => { expect(service.channelPreferences.getChannelPreferencesForUsers).toBeCalledTimes(1); expect(result).toBeUndefined(); - done(); }); - it("without mentions, should get the preferences for all members involved and return only the ones with preference !== NONE", async done => { + it("without mentions, should get the preferences for all members involved and return only the ones with preference !== NONE", async () => { const message = getMessage(); setUsersInThread(["1", "2", "3", "4"]); setThreadResponsePreferences(); @@ -447,10 +440,9 @@ describe("The NewChannelMessageProcessor class", () => { expect(service.channelPreferences.getChannelPreferencesForUsers).toBeCalledTimes(1); expect(result.mentions.users).toEqual(["1", "2", "3"]); - done(); }); - it("with @user mentions, should get the preferences for all members involved and return only the ones who want to be notified", async done => { + it("with @user mentions, should get the preferences for all members involved and return only the ones who want to be notified", async () => { const message = getMessage(); message.mentions.users = ["1", "2", "3", "4"]; setUsersInThread(["1", "2", "3", "4"]); @@ -497,7 +489,6 @@ describe("The NewChannelMessageProcessor class", () => { expect(service.channelThreads.getUsersInThread).toBeCalled; expect(service.channelPreferences.getChannelPreferencesForUsers).toBeCalledTimes(1); expect(result.mentions.users).toEqual(["1", "2", "3"]); - done(); }); }); }); diff --git a/twake/backend/node/test/unit/services/notifications/services/engine/processors/push-to-users/index.test.ts b/twake/backend/node/test/unit/services/notifications/services/engine/processors/push-to-users/index.test.ts index 11207143c1..128748454a 100644 --- a/twake/backend/node/test/unit/services/notifications/services/engine/processors/push-to-users/index.test.ts +++ b/twake/backend/node/test/unit/services/notifications/services/engine/processors/push-to-users/index.test.ts @@ -151,7 +151,7 @@ describe("The PushNotificationToUsersMessageProcessor class", () => { await expect(processor.process(message)).rejects.toThrowError("Missing required fields"); }); - it("will do nothing when mentions is not defined", async done => { + it("will do nothing when mentions is not defined", async () => { const message = getMessage(); delete message.mentions; @@ -159,10 +159,9 @@ describe("The PushNotificationToUsersMessageProcessor class", () => { expect(gr.services.notifications.channelPreferences.getChannelPreferencesForUsers).not .toBeCalled; - done(); }); - it("will do nothing when mentions.users is not defined", async done => { + it("will do nothing when mentions.users is not defined", async () => { const message = getMessage(); message.mentions = { users: undefined }; @@ -170,10 +169,9 @@ describe("The PushNotificationToUsersMessageProcessor class", () => { expect(gr.services.notifications.channelPreferences.getChannelPreferencesForUsers).not .toBeCalled; - done(); }); - it("will do nothing when mentions.users is empty", async done => { + it("will do nothing when mentions.users is empty", async () => { const message = getMessage(); message.mentions = { users: [] }; @@ -181,10 +179,9 @@ describe("The PushNotificationToUsersMessageProcessor class", () => { expect(gr.services.notifications.channelPreferences.getChannelPreferencesForUsers).not .toBeCalled; - done(); }); - it("will keep users who did not read the channel yet", async done => { + it("will keep users who did not read the channel yet", async () => { const message = getMessage(); setPreferences([ @@ -238,7 +235,6 @@ describe("The PushNotificationToUsersMessageProcessor class", () => { expect(gr.services.notifications.badges.save).toBeCalledTimes(2); expect(pubsubService.publish).toBeCalledTimes(2); - done(); }); }); });