chore: Test performance (#5786)
This commit is contained in:
@@ -5,15 +5,9 @@ import { TeamDomain } from "@server/models";
|
||||
import Collection from "@server/models/Collection";
|
||||
import UserAuthentication from "@server/models/UserAuthentication";
|
||||
import { buildUser, buildTeam, buildAdmin } from "@server/test/factories";
|
||||
import {
|
||||
setupTestDatabase,
|
||||
setCloudHosted,
|
||||
setSelfHosted,
|
||||
} from "@server/test/support";
|
||||
import { setCloudHosted, setSelfHosted } from "@server/test/support";
|
||||
import accountProvisioner from "./accountProvisioner";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("accountProvisioner", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
@@ -371,7 +365,7 @@ describe("accountProvisioner", () => {
|
||||
},
|
||||
authenticationProvider: {
|
||||
name: "google",
|
||||
providerId: "example-company.com",
|
||||
providerId: faker.internet.domainName(),
|
||||
},
|
||||
authentication: {
|
||||
providerId: uuidv4(),
|
||||
@@ -390,6 +384,7 @@ describe("accountProvisioner", () => {
|
||||
|
||||
it("should always use existing team if self-hosted", async () => {
|
||||
const team = await buildTeam();
|
||||
const domain = faker.internet.domainName();
|
||||
const { user, isNewUser } = await accountProvisioner({
|
||||
ip,
|
||||
user: {
|
||||
@@ -402,11 +397,11 @@ describe("accountProvisioner", () => {
|
||||
name: team.name,
|
||||
avatarUrl: team.avatarUrl,
|
||||
subdomain: faker.internet.domainWord(),
|
||||
domain: "allowed-domain.com",
|
||||
domain,
|
||||
},
|
||||
authenticationProvider: {
|
||||
name: "google",
|
||||
providerId: "allowed-domain.com",
|
||||
providerId: domain,
|
||||
},
|
||||
authentication: {
|
||||
providerId: uuidv4(),
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { buildDocument, buildUser } from "@server/test/factories";
|
||||
import { findLatestEvent, setupTestDatabase } from "@server/test/support";
|
||||
import { findLatestEvent } from "@server/test/support";
|
||||
import commentCreator from "./commentCreator";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("commentCreator", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Comment } from "@server/models";
|
||||
import { buildDocument, buildUser } from "@server/test/factories";
|
||||
import { findLatestEvent, setupTestDatabase } from "@server/test/support";
|
||||
import { findLatestEvent } from "@server/test/support";
|
||||
import commentDestroyer from "./commentDestroyer";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("commentDestroyer", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
|
||||
@@ -2,13 +2,10 @@ import path from "path";
|
||||
import fs from "fs-extra";
|
||||
import Attachment from "@server/models/Attachment";
|
||||
import { buildUser } from "@server/test/factories";
|
||||
import { setupTestDatabase } from "@server/test/support";
|
||||
import documentImporter from "./documentImporter";
|
||||
|
||||
jest.mock("@server/storage/files");
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("documentImporter", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
|
||||
@@ -6,11 +6,8 @@ import {
|
||||
buildTeam,
|
||||
buildUser,
|
||||
} from "@server/test/factories";
|
||||
import { setupTestDatabase } from "@server/test/support";
|
||||
import documentMover from "./documentMover";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("documentMover", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
|
||||
@@ -2,13 +2,10 @@ import { subDays } from "date-fns";
|
||||
import { Attachment, Document } from "@server/models";
|
||||
import DeleteAttachmentTask from "@server/queues/tasks/DeleteAttachmentTask";
|
||||
import { buildAttachment, buildDocument } from "@server/test/factories";
|
||||
import { setupTestDatabase } from "@server/test/support";
|
||||
import documentPermanentDeleter from "./documentPermanentDeleter";
|
||||
|
||||
jest.mock("@server/queues/tasks/DeleteAttachmentTask");
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("documentPermanentDeleter", () => {
|
||||
it("should destroy documents", async () => {
|
||||
const document = await buildDocument({
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { sequelize } from "@server/storage/database";
|
||||
import { buildDocument, buildUser } from "@server/test/factories";
|
||||
import { findLatestEvent, setupTestDatabase } from "@server/test/support";
|
||||
import { findLatestEvent } from "@server/test/support";
|
||||
import documentUpdater from "./documentUpdater";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("documentUpdater", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import { FileOperation } from "@server/models";
|
||||
import { buildAdmin, buildFileOperation } from "@server/test/factories";
|
||||
import { setupTestDatabase } from "@server/test/support";
|
||||
import fileOperationDeleter from "./fileOperationDeleter";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("fileOperationDeleter", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
|
||||
@@ -6,11 +6,9 @@ import {
|
||||
buildDocument,
|
||||
buildCollection,
|
||||
} from "@server/test/factories";
|
||||
import { findLatestEvent, setupTestDatabase } from "@server/test/support";
|
||||
import { findLatestEvent } from "@server/test/support";
|
||||
import notificationUpdater from "./notificationUpdater";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("notificationUpdater", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
@@ -48,7 +46,7 @@ describe("notificationUpdater", () => {
|
||||
transaction,
|
||||
})
|
||||
);
|
||||
const event = await findLatestEvent({});
|
||||
const event = await findLatestEvent();
|
||||
|
||||
expect(notification.viewedAt).not.toBe(null);
|
||||
expect(notification.archivedAt).toBe(null);
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { buildDocument, buildUser } from "@server/test/factories";
|
||||
import { findLatestEvent, setupTestDatabase } from "@server/test/support";
|
||||
import { findLatestEvent } from "@server/test/support";
|
||||
import pinCreator from "./pinCreator";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("pinCreator", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Pin } from "@server/models";
|
||||
import { buildDocument, buildUser } from "@server/test/factories";
|
||||
import { findLatestEvent, setupTestDatabase } from "@server/test/support";
|
||||
import { findLatestEvent } from "@server/test/support";
|
||||
import pinDestroyer from "./pinDestroyer";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("pinCreator", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { buildDocument, buildUser } from "@server/test/factories";
|
||||
import { findLatestEvent, setupTestDatabase } from "@server/test/support";
|
||||
import { findLatestEvent } from "@server/test/support";
|
||||
import revisionCreator from "./revisionCreator";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("revisionCreator", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
@@ -18,7 +16,9 @@ describe("revisionCreator", () => {
|
||||
user,
|
||||
ip,
|
||||
});
|
||||
const event = await findLatestEvent();
|
||||
const event = await findLatestEvent({
|
||||
teamId: user.teamId,
|
||||
});
|
||||
expect(revision.documentId).toEqual(document.id);
|
||||
expect(revision.userId).toEqual(user.id);
|
||||
expect(revision.createdAt).toEqual(document.updatedAt);
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { Star, Event } from "@server/models";
|
||||
import { sequelize } from "@server/storage/database";
|
||||
import { buildDocument, buildUser } from "@server/test/factories";
|
||||
import { findLatestEvent, setupTestDatabase } from "@server/test/support";
|
||||
import { findLatestEvent } from "@server/test/support";
|
||||
import starCreator from "./starCreator";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("starCreator", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Star } from "@server/models";
|
||||
import { buildDocument, buildUser } from "@server/test/factories";
|
||||
import { findLatestEvent, setupTestDatabase } from "@server/test/support";
|
||||
import { findLatestEvent } from "@server/test/support";
|
||||
import starDestroyer from "./starDestroyer";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("starDestroyer", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Star } from "@server/models";
|
||||
import { buildDocument, buildUser } from "@server/test/factories";
|
||||
import { findLatestEvent, setupTestDatabase } from "@server/test/support";
|
||||
import { findLatestEvent } from "@server/test/support";
|
||||
import starUpdater from "./starUpdater";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("starUpdater", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import { Subscription, Event } from "@server/models";
|
||||
import { sequelize } from "@server/storage/database";
|
||||
import { buildDocument, buildUser } from "@server/test/factories";
|
||||
import { setupTestDatabase } from "@server/test/support";
|
||||
import subscriptionCreator from "./subscriptionCreator";
|
||||
import subscriptionDestroyer from "./subscriptionDestroyer";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("subscriptionCreator", () => {
|
||||
const ip = "127.0.0.1";
|
||||
const subscribedEvent = "documents.update";
|
||||
|
||||
@@ -5,11 +5,8 @@ import {
|
||||
buildSubscription,
|
||||
buildUser,
|
||||
} from "@server/test/factories";
|
||||
import { setupTestDatabase } from "@server/test/support";
|
||||
import subscriptionDestroyer from "./subscriptionDestroyer";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("subscriptionDestroyer", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
|
||||
@@ -6,11 +6,8 @@ import {
|
||||
buildTeam,
|
||||
buildDocument,
|
||||
} from "@server/test/factories";
|
||||
import { setupTestDatabase } from "@server/test/support";
|
||||
import teamPermanentDeleter from "./teamPermanentDeleter";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("teamPermanentDeleter", () => {
|
||||
it("should destroy related data", async () => {
|
||||
const team = await buildTeam({
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
import { faker } from "@faker-js/faker";
|
||||
import TeamDomain from "@server/models/TeamDomain";
|
||||
import { buildTeam, buildUser } from "@server/test/factories";
|
||||
import {
|
||||
setCloudHosted,
|
||||
setSelfHosted,
|
||||
setupTestDatabase,
|
||||
} from "@server/test/support";
|
||||
import { setCloudHosted, setSelfHosted } from "@server/test/support";
|
||||
import teamProvisioner from "./teamProvisioner";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("teamProvisioner", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
@@ -104,12 +98,14 @@ describe("teamProvisioner", () => {
|
||||
});
|
||||
|
||||
it("should error on mismatched team and authentication provider", async () => {
|
||||
const subdomain = faker.internet.domainWord();
|
||||
|
||||
const exampleTeam = await buildTeam({
|
||||
subdomain: faker.internet.domainWord(),
|
||||
subdomain,
|
||||
authenticationProviders: [
|
||||
{
|
||||
name: "google",
|
||||
providerId: "teamProvisioner3.com",
|
||||
providerId: `${subdomain}.com`,
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -215,9 +211,11 @@ describe("teamProvisioner", () => {
|
||||
const user = await buildUser({
|
||||
teamId: existing.id,
|
||||
});
|
||||
const allowedDomain = faker.internet.domainName();
|
||||
const otherDomain = faker.internet.domainName();
|
||||
await TeamDomain.create({
|
||||
teamId: existing.id,
|
||||
name: "allowed-domain.com",
|
||||
name: allowedDomain,
|
||||
createdById: user.id,
|
||||
});
|
||||
|
||||
@@ -226,11 +224,11 @@ describe("teamProvisioner", () => {
|
||||
await teamProvisioner({
|
||||
name: "Updated name",
|
||||
subdomain: faker.internet.domainWord(),
|
||||
domain: "other-domain.com",
|
||||
domain: otherDomain,
|
||||
teamId: existing.id,
|
||||
authenticationProvider: {
|
||||
name: "google",
|
||||
providerId: "other-domain.com",
|
||||
providerId: otherDomain,
|
||||
},
|
||||
ip,
|
||||
});
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import { CollectionPermission, UserRole } from "@shared/types";
|
||||
import { CollectionUser } from "@server/models";
|
||||
import { buildUser, buildAdmin, buildCollection } from "@server/test/factories";
|
||||
import { setupTestDatabase } from "@server/test/support";
|
||||
import userDemoter from "./userDemoter";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("userDemoter", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import { buildUser, buildAdmin } from "@server/test/factories";
|
||||
import { setupTestDatabase } from "@server/test/support";
|
||||
import userDestroyer from "./userDestroyer";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("userDestroyer", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import { faker } from "@faker-js/faker";
|
||||
import { UserRole } from "@shared/types";
|
||||
import { buildUser } from "@server/test/factories";
|
||||
import { setupTestDatabase } from "@server/test/support";
|
||||
import userInviter from "./userInviter";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("userInviter", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { faker } from "@faker-js/faker";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { TeamDomain } from "@server/models";
|
||||
import {
|
||||
@@ -6,11 +7,8 @@ import {
|
||||
buildInvite,
|
||||
buildAdmin,
|
||||
} from "@server/test/factories";
|
||||
import { setupTestDatabase } from "@server/test/support";
|
||||
import userProvisioner from "./userProvisioner";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("userProvisioner", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
@@ -338,17 +336,19 @@ describe("userProvisioner", () => {
|
||||
it("should create a user from allowed domain", async () => {
|
||||
const team = await buildTeam();
|
||||
const admin = await buildAdmin({ teamId: team.id });
|
||||
const domain = faker.internet.domainName();
|
||||
await TeamDomain.create({
|
||||
teamId: team.id,
|
||||
name: "example-company.com",
|
||||
name: domain,
|
||||
createdById: admin.id,
|
||||
});
|
||||
|
||||
const authenticationProviders = await team.$get("authenticationProviders");
|
||||
const authenticationProvider = authenticationProviders[0];
|
||||
const email = faker.internet.email({ provider: domain });
|
||||
const result = await userProvisioner({
|
||||
name: "Test Name",
|
||||
email: "user@example-company.com",
|
||||
name: faker.person.fullName(),
|
||||
email,
|
||||
teamId: team.id,
|
||||
ip,
|
||||
authentication: {
|
||||
@@ -363,28 +363,31 @@ describe("userProvisioner", () => {
|
||||
expect(authentication?.accessToken).toEqual("123");
|
||||
expect(authentication?.scopes.length).toEqual(1);
|
||||
expect(authentication?.scopes[0]).toEqual("read");
|
||||
expect(user.email).toEqual("user@example-company.com");
|
||||
expect(user.email).toEqual(email);
|
||||
expect(isNewUser).toEqual(true);
|
||||
});
|
||||
|
||||
it("should create a user from allowed domain with emailMatchOnly", async () => {
|
||||
const team = await buildTeam();
|
||||
const admin = await buildAdmin({ teamId: team.id });
|
||||
const domain = faker.internet.domainName();
|
||||
const email = faker.internet.email({ provider: domain });
|
||||
|
||||
await TeamDomain.create({
|
||||
teamId: team.id,
|
||||
name: "example-company.com",
|
||||
name: domain,
|
||||
createdById: admin.id,
|
||||
});
|
||||
|
||||
const result = await userProvisioner({
|
||||
name: "Test Name",
|
||||
email: "user@example-company.com",
|
||||
email,
|
||||
teamId: team.id,
|
||||
ip,
|
||||
});
|
||||
const { user, authentication, isNewUser } = result;
|
||||
expect(authentication).toBeUndefined();
|
||||
expect(user.email).toEqual("user@example-company.com");
|
||||
expect(user.email).toEqual(email);
|
||||
expect(isNewUser).toEqual(true);
|
||||
});
|
||||
|
||||
@@ -395,7 +398,7 @@ describe("userProvisioner", () => {
|
||||
try {
|
||||
await userProvisioner({
|
||||
name: "Test Name",
|
||||
email: "user@example-company.com",
|
||||
email: faker.internet.email(),
|
||||
teamId: team.id,
|
||||
ip,
|
||||
});
|
||||
@@ -411,7 +414,7 @@ describe("userProvisioner", () => {
|
||||
const admin = await buildAdmin({ teamId: team.id });
|
||||
await TeamDomain.create({
|
||||
teamId: team.id,
|
||||
name: "other.com",
|
||||
name: faker.internet.domainName(),
|
||||
createdById: admin.id,
|
||||
});
|
||||
|
||||
@@ -422,7 +425,7 @@ describe("userProvisioner", () => {
|
||||
try {
|
||||
await userProvisioner({
|
||||
name: "Bad Domain User",
|
||||
email: "user@example.com",
|
||||
email: faker.internet.domainName(),
|
||||
teamId: team.id,
|
||||
ip,
|
||||
authentication: {
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import GroupUser from "@server/models/GroupUser";
|
||||
import { buildGroup, buildAdmin, buildUser } from "@server/test/factories";
|
||||
import { setupTestDatabase } from "@server/test/support";
|
||||
import userSuspender from "./userSuspender";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("userSuspender", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import { buildAdmin, buildUser } from "@server/test/factories";
|
||||
import { setupTestDatabase } from "@server/test/support";
|
||||
import userUnsuspender from "./userUnsuspender";
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("userUnsuspender", () => {
|
||||
const ip = "127.0.0.1";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user