chore: Improve perf of server tests (#5785)

This commit is contained in:
Tom Moor
2023-09-06 07:14:49 -04:00
committed by GitHub
parent a724a21c21
commit 3eb947e9a5
69 changed files with 2045 additions and 1551 deletions

View File

@@ -1,44 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`#users.activate should activate a suspended user 1`] = `
{
"data": {
"avatarUrl": null,
"color": "#e600e0",
"createdAt": "2018-01-02T00:00:00.000Z",
"email": "user1@example.com",
"id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61",
"isAdmin": false,
"isSuspended": false,
"isViewer": false,
"language": "en_US",
"lastActiveAt": null,
"name": "User 1",
"notificationSettings": {},
"preferences": null,
"updatedAt": "2018-01-02T00:00:00.000Z",
},
"ok": true,
"policies": [
{
"abilities": {
"activate": true,
"delete": true,
"demote": true,
"promote": true,
"read": true,
"readDetails": true,
"resendInvite": true,
"suspend": true,
"update": true,
},
"id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61",
},
],
"status": 200,
}
`;
exports[`#users.activate should require admin 1`] = `
{
"error": "admin_required",
@@ -57,123 +18,6 @@ exports[`#users.delete should require authentication 1`] = `
}
`;
exports[`#users.demote should demote an admin 1`] = `
{
"data": {
"avatarUrl": null,
"color": "#e600e0",
"createdAt": "2018-01-02T00:00:00.000Z",
"email": "user1@example.com",
"id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61",
"isAdmin": false,
"isSuspended": false,
"isViewer": false,
"language": "en_US",
"lastActiveAt": null,
"name": "User 1",
"notificationSettings": {},
"preferences": null,
"updatedAt": "2018-01-02T00:00:00.000Z",
},
"ok": true,
"policies": [
{
"abilities": {
"activate": true,
"delete": true,
"demote": true,
"promote": true,
"read": true,
"readDetails": true,
"resendInvite": true,
"suspend": true,
"update": true,
},
"id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61",
},
],
"status": 200,
}
`;
exports[`#users.demote should demote an admin to member 1`] = `
{
"data": {
"avatarUrl": null,
"color": "#e600e0",
"createdAt": "2018-01-02T00:00:00.000Z",
"email": "user1@example.com",
"id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61",
"isAdmin": false,
"isSuspended": false,
"isViewer": false,
"language": "en_US",
"lastActiveAt": null,
"name": "User 1",
"notificationSettings": {},
"preferences": null,
"updatedAt": "2018-01-02T00:00:00.000Z",
},
"ok": true,
"policies": [
{
"abilities": {
"activate": true,
"delete": true,
"demote": true,
"promote": true,
"read": true,
"readDetails": true,
"resendInvite": true,
"suspend": true,
"update": true,
},
"id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61",
},
],
"status": 200,
}
`;
exports[`#users.demote should demote an admin to viewer 1`] = `
{
"data": {
"avatarUrl": null,
"color": "#e600e0",
"createdAt": "2018-01-02T00:00:00.000Z",
"email": "user1@example.com",
"id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61",
"isAdmin": false,
"isSuspended": false,
"isViewer": true,
"language": "en_US",
"lastActiveAt": null,
"name": "User 1",
"notificationSettings": {},
"preferences": null,
"updatedAt": "2018-01-02T00:00:00.000Z",
},
"ok": true,
"policies": [
{
"abilities": {
"activate": true,
"delete": true,
"demote": true,
"promote": true,
"read": true,
"readDetails": true,
"resendInvite": true,
"suspend": true,
"update": true,
},
"id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61",
},
],
"status": 200,
}
`;
exports[`#users.demote should not allow demoting self 1`] = `
{
"error": "validation_error",
@@ -192,45 +36,6 @@ exports[`#users.demote should require admin 1`] = `
}
`;
exports[`#users.promote should promote a new admin 1`] = `
{
"data": {
"avatarUrl": null,
"color": "#e600e0",
"createdAt": "2018-01-02T00:00:00.000Z",
"email": "user1@example.com",
"id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61",
"isAdmin": true,
"isSuspended": false,
"isViewer": false,
"language": "en_US",
"lastActiveAt": null,
"name": "User 1",
"notificationSettings": {},
"preferences": null,
"updatedAt": "2018-01-02T00:00:00.000Z",
},
"ok": true,
"policies": [
{
"abilities": {
"activate": true,
"delete": true,
"demote": true,
"promote": false,
"read": true,
"readDetails": true,
"resendInvite": true,
"suspend": true,
"update": true,
},
"id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61",
},
],
"status": 200,
}
`;
exports[`#users.promote should require admin 1`] = `
{
"error": "admin_required",
@@ -258,45 +63,6 @@ exports[`#users.suspend should require admin 1`] = `
}
`;
exports[`#users.suspend should suspend an user 1`] = `
{
"data": {
"avatarUrl": null,
"color": "#e600e0",
"createdAt": "2018-01-02T00:00:00.000Z",
"email": "user1@example.com",
"id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61",
"isAdmin": false,
"isSuspended": true,
"isViewer": false,
"language": "en_US",
"lastActiveAt": null,
"name": "User 1",
"notificationSettings": {},
"preferences": null,
"updatedAt": "2018-01-02T00:00:00.000Z",
},
"ok": true,
"policies": [
{
"abilities": {
"activate": true,
"delete": true,
"demote": false,
"promote": false,
"read": true,
"readDetails": true,
"resendInvite": true,
"suspend": true,
"update": true,
},
"id": "46fde1d4-0050-428f-9f0b-0bf77f4bdf61",
},
],
"status": 200,
}
`;
exports[`#users.update should require authentication 1`] = `
{
"error": "authentication_required",

View File

@@ -4,7 +4,7 @@ import {
buildUser,
buildInvite,
} from "@server/test/factories";
import { seed, getTestServer } from "@server/test/support";
import { getTestServer } from "@server/test/support";
const server = getTestServer();
@@ -117,21 +117,27 @@ describe("#users.list", () => {
});
it("should return teams paginated user list", async () => {
const { admin, user } = await seed();
const team = await buildTeam();
const admin = await buildAdmin({ teamId: team.id });
await buildUser({ teamId: team.id });
const res = await server.post("/api/users.list", {
body: {
token: admin.getJwtToken(),
sort: "createdAt",
direction: "DESC",
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.length).toEqual(2);
expect(body.data[0].id).toEqual(user.id);
expect(body.data[1].id).toEqual(admin.id);
});
it("should allow filtering by id", async () => {
const { admin, user } = await seed();
const team = await buildTeam();
const admin = await buildAdmin({ teamId: team.id });
const user = await buildUser({ teamId: team.id });
const res = await server.post("/api/users.list", {
body: {
token: admin.getJwtToken(),
@@ -145,7 +151,9 @@ describe("#users.list", () => {
});
it("should require admin for detailed info", async () => {
const { user, admin } = await seed();
const team = await buildTeam();
await buildAdmin({ teamId: team.id });
const user = await buildUser({ teamId: team.id });
const res = await server.post("/api/users.list", {
body: {
token: user.getJwtToken(),
@@ -156,8 +164,6 @@ describe("#users.list", () => {
expect(body.data.length).toEqual(2);
expect(body.data[0].email).toEqual(undefined);
expect(body.data[1].email).toEqual(undefined);
expect(body.data[0].id).toEqual(user.id);
expect(body.data[1].id).toEqual(admin.id);
});
});
@@ -381,7 +387,7 @@ describe("#users.delete", () => {
describe("#users.update", () => {
it("should update user profile information", async () => {
const { user } = await seed();
const user = await buildUser();
const res = await server.post("/api/users.update", {
body: {
token: user.getJwtToken(),
@@ -427,7 +433,7 @@ describe("#users.update", () => {
});
it("should fail upon sending invalid user preference", async () => {
const { user } = await seed();
const user = await buildUser();
const res = await server.post("/api/users.update", {
body: {
token: user.getJwtToken(),
@@ -439,7 +445,7 @@ describe("#users.update", () => {
});
it("should fail upon sending invalid user preference value", async () => {
const { user } = await seed();
const user = await buildUser();
const res = await server.post("/api/users.update", {
body: {
token: user.getJwtToken(),
@@ -451,7 +457,7 @@ describe("#users.update", () => {
});
it("should update rememberLastPath user preference", async () => {
const { user } = await seed();
const user = await buildUser();
const res = await server.post("/api/users.update", {
body: {
token: user.getJwtToken(),
@@ -476,16 +482,17 @@ describe("#users.update", () => {
describe("#users.promote", () => {
it("should promote a new admin", async () => {
const { admin, user } = await seed();
const team = await buildTeam();
const admin = await buildAdmin({ teamId: team.id });
const user = await buildUser({ teamId: team.id });
const res = await server.post("/api/users.promote", {
body: {
token: admin.getJwtToken(),
id: user.id,
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body).toMatchSnapshot();
});
it("should require admin", async () => {
@@ -504,7 +511,10 @@ describe("#users.promote", () => {
describe("#users.demote", () => {
it("should demote an admin", async () => {
const { admin, user } = await seed();
const team = await buildTeam();
const admin = await buildAdmin({ teamId: team.id });
const user = await buildUser({ teamId: team.id });
await user.update({
isAdmin: true,
}); // Make another admin
@@ -515,13 +525,14 @@ describe("#users.demote", () => {
id: user.id,
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body).toMatchSnapshot();
});
it("should demote an admin to viewer", async () => {
const { admin, user } = await seed();
const team = await buildTeam();
const admin = await buildAdmin({ teamId: team.id });
const user = await buildUser({ teamId: team.id });
await user.update({
isAdmin: true,
}); // Make another admin
@@ -533,13 +544,14 @@ describe("#users.demote", () => {
to: "viewer",
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body).toMatchSnapshot();
});
it("should demote an admin to member", async () => {
const { admin, user } = await seed();
const team = await buildTeam();
const admin = await buildAdmin({ teamId: team.id });
const user = await buildUser({ teamId: team.id });
await user.update({
isAdmin: true,
}); // Make another admin
@@ -551,9 +563,7 @@ describe("#users.demote", () => {
to: "member",
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body).toMatchSnapshot();
});
it("should not allow demoting self", async () => {
@@ -585,16 +595,17 @@ describe("#users.demote", () => {
describe("#users.suspend", () => {
it("should suspend an user", async () => {
const { admin, user } = await seed();
const team = await buildTeam();
const admin = await buildAdmin({ teamId: team.id });
const user = await buildUser({ teamId: team.id });
const res = await server.post("/api/users.suspend", {
body: {
token: admin.getJwtToken(),
id: user.id,
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body).toMatchSnapshot();
});
it("should not allow suspending the user themselves", async () => {
@@ -626,7 +637,10 @@ describe("#users.suspend", () => {
describe("#users.activate", () => {
it("should activate a suspended user", async () => {
const { admin, user } = await seed();
const team = await buildTeam();
const admin = await buildAdmin({ teamId: team.id });
const user = await buildUser({ teamId: team.id });
await user.update({
suspendedById: admin.id,
suspendedAt: new Date(),
@@ -638,9 +652,7 @@ describe("#users.activate", () => {
id: user.id,
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body).toMatchSnapshot();
});
it("should require admin", async () => {
@@ -660,9 +672,7 @@ describe("#users.activate", () => {
describe("#users.count", () => {
it("should count active users", async () => {
const team = await buildTeam();
const user = await buildUser({
teamId: team.id,
});
const user = await buildUser({ teamId: team.id });
const res = await server.post("/api/users.count", {
body: {
token: user.getJwtToken(),
@@ -699,9 +709,7 @@ describe("#users.count", () => {
it("should count suspended users", async () => {
const team = await buildTeam();
const user = await buildUser({
teamId: team.id,
});
const user = await buildUser({ teamId: team.id });
await buildUser({
teamId: team.id,
suspendedAt: new Date(),