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,13 +1,23 @@
import { CollectionPermission } from "@shared/types";
import { View, CollectionUser } from "@server/models";
import { buildUser } from "@server/test/factories";
import { seed, getTestServer } from "@server/test/support";
import {
buildAdmin,
buildCollection,
buildDocument,
buildTeam,
buildUser,
} from "@server/test/factories";
import { getTestServer } from "@server/test/support";
const server = getTestServer();
describe("#views.list", () => {
it("should return views for a document", async () => {
const { user, document } = await seed();
const user = await buildUser();
const document = await buildDocument({
userId: user.id,
teamId: user.teamId,
});
await View.incrementOrCreate({
documentId: document.id,
userId: user.id,
@@ -25,7 +35,10 @@ describe("#views.list", () => {
});
it("should not return views for suspended user by default", async () => {
const { user, admin, document } = await seed();
const team = await buildTeam();
const admin = await buildAdmin({ teamId: team.id });
const user = await buildUser({ teamId: team.id });
const document = await buildDocument({ userId: user.id, teamId: team.id });
await View.incrementOrCreate({
documentId: document.id,
userId: user.id,
@@ -45,7 +58,17 @@ describe("#views.list", () => {
});
it("should return views for a document in read-only collection", async () => {
const { user, document, collection } = await seed();
const team = await buildTeam();
const user = await buildUser({ teamId: team.id });
const collection = await buildCollection({
userId: user.id,
teamId: team.id,
});
const document = await buildDocument({
userId: user.id,
collectionId: collection.id,
teamId: team.id,
});
collection.permission = null;
await collection.save();
await CollectionUser.create({
@@ -71,7 +94,7 @@ describe("#views.list", () => {
});
it("should require authentication", async () => {
const { document } = await seed();
const document = await buildDocument();
const res = await server.post("/api/views.list", {
body: {
documentId: document.id,
@@ -83,7 +106,7 @@ describe("#views.list", () => {
});
it("should require authorization", async () => {
const { document } = await seed();
const document = await buildDocument();
const user = await buildUser();
const res = await server.post("/api/views.list", {
body: {
@@ -97,7 +120,11 @@ describe("#views.list", () => {
describe("#views.create", () => {
it("should allow creating a view record for document", async () => {
const { user, document } = await seed();
const user = await buildUser();
const document = await buildDocument({
userId: user.id,
teamId: user.teamId,
});
const res = await server.post("/api/views.create", {
body: {
token: user.getJwtToken(),
@@ -110,7 +137,17 @@ describe("#views.create", () => {
});
it("should allow creating a view record for document in read-only collection", async () => {
const { user, document, collection } = await seed();
const team = await buildTeam();
const user = await buildUser({ teamId: team.id });
const collection = await buildCollection({
userId: user.id,
teamId: team.id,
});
const document = await buildDocument({
userId: user.id,
collectionId: collection.id,
teamId: team.id,
});
collection.permission = null;
await collection.save();
await CollectionUser.create({
@@ -131,7 +168,7 @@ describe("#views.create", () => {
});
it("should require authentication", async () => {
const { document } = await seed();
const document = await buildDocument();
const res = await server.post("/api/views.create", {
body: {
documentId: document.id,
@@ -143,7 +180,7 @@ describe("#views.create", () => {
});
it("should require authorization", async () => {
const { document } = await seed();
const document = await buildDocument();
const user = await buildUser();
const res = await server.post("/api/views.create", {
body: {