Skip to content

Commit

Permalink
Update to jest 29
Browse files Browse the repository at this point in the history
  • Loading branch information
guimard committed Feb 6, 2023
1 parent b456bef commit 802254f
Show file tree
Hide file tree
Showing 37 changed files with 316 additions and 626 deletions.
6 changes: 3 additions & 3 deletions twake/backend/node/package.json
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
52 changes: 18 additions & 34 deletions twake/backend/node/test/e2e/application/app-create-update.spec.ts
Expand Up @@ -18,19 +18,18 @@ 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);
await testDbService.createDefault();
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 => {
Expand All @@ -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()], {
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -184,24 +176,22 @@ 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();
});
});
});
describe("Get applications", function () {
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;
Expand All @@ -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);

Expand All @@ -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();
});
});
});
Expand Down
Expand Up @@ -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();
Expand All @@ -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,
Expand All @@ -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();
});
});

Expand Down
19 changes: 7 additions & 12 deletions twake/backend/node/test/e2e/application/application-login.spec.ts
Expand Up @@ -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);
Expand All @@ -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", {
Expand All @@ -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",
Expand All @@ -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({
Expand All @@ -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",
Expand All @@ -107,7 +103,6 @@ describe("Applications", () => {
const resource = (await response.json()).resource;
log.debug(resource);
expect(resource).toMatchObject(postPayload);
done();
});
});
});
Expand Down
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
},
);
Expand All @@ -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();
Expand Down Expand Up @@ -149,7 +148,6 @@ describe("The Channels Realtime feature", () => {
),
);
expect(event.resource.id).toEqual(creationResult.entity.id);
done();
},
);
socket.emit("realtime:join", {
Expand Down

0 comments on commit 802254f

Please sign in to comment.