🤝 Shared with me (#71)

* 🚧 #46 Shared with me
  - added converter of DriveFile to dto with user information
  - updated version of jest to the latest for better compatibility with typescript and mocking class instances
  - added run configuration for unit tests

Co-authored-by: Romaric Mourgues <rmourgues@linagora.com>
This commit is contained in:
Anton Shepilov
2023-06-09 14:37:15 +02:00
committed by GitHub
parent f1bf507865
commit dfd25a234a
32 changed files with 3215 additions and 4560 deletions
@@ -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@tdrive.app", uuidv1());
expect(resources.length).toBe(0);
done();
}, 1200000);
});
@@ -12,17 +12,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",
@@ -55,25 +53,22 @@ describe("The /users API", () => {
});
await testDbService.createUser([workspacePk]);
ends();
});
afterAll(async ends => {
ends();
afterAll(async () => {
});
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",
@@ -89,10 +84,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({
@@ -143,10 +137,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;
@@ -183,23 +176,20 @@ describe("The /users API", () => {
timezone: expect.anything(),
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;
@@ -220,23 +210,20 @@ describe("The /users API", () => {
const json = response.json();
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",
@@ -252,10 +239,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;
@@ -299,21 +285,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({
@@ -347,7 +331,6 @@ describe("The /users API", () => {
total_messages: expect.any(Number),
});
done();
});
});
@@ -355,7 +338,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 });
@@ -381,10 +364,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 });
@@ -413,7 +395,7 @@ describe("The /users API", () => {
});
const user = await testDbService.getUserFromDb({ id: firstId });
expect(user.devices).toMatchObject([deviceToken]);
expect(user.devices).toEqual([deviceToken]);
const device = await testDbService.getDeviceFromDb(deviceToken);
expect(device).toMatchObject({
id: deviceToken,
@@ -421,11 +403,9 @@ describe("The /users API", () => {
type: "FCM",
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;
@@ -456,7 +436,7 @@ describe("The /users API", () => {
// second user should have now this token
let user = await testDbService.getUserFromDb({ id: secondId });
expect(user.devices).toMatchObject([deviceToken]);
expect(user.devices).toEqual([deviceToken]);
const device = await testDbService.getDeviceFromDb(deviceToken);
expect(device).toMatchObject({
id: deviceToken,
@@ -470,11 +450,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 });
@@ -497,12 +476,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 });
@@ -516,7 +494,7 @@ describe("The /users API", () => {
expect(response.statusCode).toBe(204);
const user = await testDbService.getUserFromDb({ id: myId });
expect(user.devices).toMatchObject([deviceToken]);
expect(user.devices).toEqual([deviceToken]);
const device = await testDbService.getDeviceFromDb(deviceToken);
expect(device).toMatchObject({
id: deviceToken,
@@ -524,11 +502,9 @@ describe("The /users API", () => {
type: "FCM",
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 });
@@ -546,7 +522,6 @@ describe("The /users API", () => {
const device = await testDbService.getDeviceFromDb(deviceToken);
expect(device).toBeFalsy();
done();
});
});
});