perf: reduce memory usage upon running server tests (#3949)
* perf: reduce memory usage upon running server tests * perf: plug leaks in server/routes * perf: plug leaks in server/scripts * perf: plug leaks in server/policies * perf: plug leaks in server/models * perf: plug leaks in server/middlewares * perf: plug leaks in server/commands * fix: missing await on db.flush * perf: plug leaks in server/queues * chore: remove unused legacy funcs * fix: await on db.flush * perf: await on GC to run in between tests * fix: remove db refs * fix: revert embeds * perf: plug leaks in shared/i18n
This commit is contained in:
@@ -15,7 +15,8 @@
|
|||||||
"<rootDir>/server/test/setup.ts"
|
"<rootDir>/server/test/setup.ts"
|
||||||
],
|
],
|
||||||
"testEnvironment": "node",
|
"testEnvironment": "node",
|
||||||
"runner": "@getoutline/jest-runner-serial"
|
"runner": "@getoutline/jest-runner-serial",
|
||||||
|
"detectLeaks": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"displayName": "app",
|
"displayName": "app",
|
||||||
@@ -56,6 +57,9 @@
|
|||||||
"setupFiles": [
|
"setupFiles": [
|
||||||
"<rootDir>/__mocks__/console.js"
|
"<rootDir>/__mocks__/console.js"
|
||||||
],
|
],
|
||||||
|
"setupFilesAfterEnv": [
|
||||||
|
"<rootDir>/shared/test/setup.ts"
|
||||||
|
],
|
||||||
"testEnvironment": "node"
|
"testEnvironment": "node"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -79,4 +83,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,14 @@ import { TeamDomain } from "@server/models";
|
|||||||
import Collection from "@server/models/Collection";
|
import Collection from "@server/models/Collection";
|
||||||
import UserAuthentication from "@server/models/UserAuthentication";
|
import UserAuthentication from "@server/models/UserAuthentication";
|
||||||
import { buildUser, buildTeam } from "@server/test/factories";
|
import { buildUser, buildTeam } from "@server/test/factories";
|
||||||
import { flushdb, seed } from "@server/test/support";
|
import { getTestDatabase, seed } from "@server/test/support";
|
||||||
import accountProvisioner from "./accountProvisioner";
|
import accountProvisioner from "./accountProvisioner";
|
||||||
|
|
||||||
beforeEach(() => {
|
const db = getTestDatabase();
|
||||||
return flushdb();
|
|
||||||
});
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("accountProvisioner", () => {
|
describe("accountProvisioner", () => {
|
||||||
const ip = "127.0.0.1";
|
const ip = "127.0.0.1";
|
||||||
|
|||||||
@@ -2,11 +2,16 @@ import path from "path";
|
|||||||
import fs from "fs-extra";
|
import fs from "fs-extra";
|
||||||
import Attachment from "@server/models/Attachment";
|
import Attachment from "@server/models/Attachment";
|
||||||
import { buildUser } from "@server/test/factories";
|
import { buildUser } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import documentImporter from "./documentImporter";
|
import documentImporter from "./documentImporter";
|
||||||
|
|
||||||
jest.mock("../utils/s3");
|
jest.mock("../utils/s3");
|
||||||
beforeEach(() => flushdb());
|
|
||||||
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("documentImporter", () => {
|
describe("documentImporter", () => {
|
||||||
const ip = "127.0.0.1";
|
const ip = "127.0.0.1";
|
||||||
|
|||||||
@@ -5,10 +5,14 @@ import {
|
|||||||
buildCollection,
|
buildCollection,
|
||||||
buildUser,
|
buildUser,
|
||||||
} from "@server/test/factories";
|
} from "@server/test/factories";
|
||||||
import { flushdb, seed } from "@server/test/support";
|
import { getTestDatabase, seed } from "@server/test/support";
|
||||||
import documentMover from "./documentMover";
|
import documentMover from "./documentMover";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("documentMover", () => {
|
describe("documentMover", () => {
|
||||||
const ip = "127.0.0.1";
|
const ip = "127.0.0.1";
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
import { subDays } from "date-fns";
|
import { subDays } from "date-fns";
|
||||||
import { Attachment, Document } from "@server/models";
|
import { Attachment, Document } from "@server/models";
|
||||||
import { buildAttachment, buildDocument } from "@server/test/factories";
|
import { buildAttachment, buildDocument } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import documentPermanentDeleter from "./documentPermanentDeleter";
|
import documentPermanentDeleter from "./documentPermanentDeleter";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("documentPermanentDeleter", () => {
|
describe("documentPermanentDeleter", () => {
|
||||||
it("should destroy documents", async () => {
|
it("should destroy documents", async () => {
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
import { sequelize } from "@server/database/sequelize";
|
import { sequelize } from "@server/database/sequelize";
|
||||||
import { Event } from "@server/models";
|
import { Event } from "@server/models";
|
||||||
import { buildDocument, buildUser } from "@server/test/factories";
|
import { buildDocument, buildUser } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import documentUpdater from "./documentUpdater";
|
import documentUpdater from "./documentUpdater";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("documentUpdater", () => {
|
describe("documentUpdater", () => {
|
||||||
const ip = "127.0.0.1";
|
const ip = "127.0.0.1";
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import { FileOperation } from "@server/models";
|
import { FileOperation } from "@server/models";
|
||||||
import { buildAdmin, buildFileOperation } from "@server/test/factories";
|
import { buildAdmin, buildFileOperation } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import fileOperationDeleter from "./fileOperationDeleter";
|
import fileOperationDeleter from "./fileOperationDeleter";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("fileOperationDeleter", () => {
|
describe("fileOperationDeleter", () => {
|
||||||
const ip = "127.0.0.1";
|
const ip = "127.0.0.1";
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
import { Event } from "@server/models";
|
import { Event } from "@server/models";
|
||||||
import { buildDocument, buildUser } from "@server/test/factories";
|
import { buildDocument, buildUser } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import pinCreator from "./pinCreator";
|
import pinCreator from "./pinCreator";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("pinCreator", () => {
|
describe("pinCreator", () => {
|
||||||
const ip = "127.0.0.1";
|
const ip = "127.0.0.1";
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
import { Pin, Event } from "@server/models";
|
import { Pin, Event } from "@server/models";
|
||||||
import { buildDocument, buildUser } from "@server/test/factories";
|
import { buildDocument, buildUser } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import pinDestroyer from "./pinDestroyer";
|
import pinDestroyer from "./pinDestroyer";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("pinCreator", () => {
|
describe("pinCreator", () => {
|
||||||
const ip = "127.0.0.1";
|
const ip = "127.0.0.1";
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import { Event } from "@server/models";
|
import { Event } from "@server/models";
|
||||||
import { buildDocument, buildUser } from "@server/test/factories";
|
import { buildDocument, buildUser } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import revisionCreator from "./revisionCreator";
|
import revisionCreator from "./revisionCreator";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("revisionCreator", () => {
|
describe("revisionCreator", () => {
|
||||||
const ip = "127.0.0.1";
|
const ip = "127.0.0.1";
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
import { sequelize } from "@server/database/sequelize";
|
import { sequelize } from "@server/database/sequelize";
|
||||||
import { Star, Event } from "@server/models";
|
import { Star, Event } from "@server/models";
|
||||||
import { buildDocument, buildUser } from "@server/test/factories";
|
import { buildDocument, buildUser } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import starCreator from "./starCreator";
|
import starCreator from "./starCreator";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("starCreator", () => {
|
describe("starCreator", () => {
|
||||||
const ip = "127.0.0.1";
|
const ip = "127.0.0.1";
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import { Star, Event } from "@server/models";
|
import { Star, Event } from "@server/models";
|
||||||
import { buildDocument, buildUser } from "@server/test/factories";
|
import { buildDocument, buildUser } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import starDestroyer from "./starDestroyer";
|
import starDestroyer from "./starDestroyer";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("starDestroyer", () => {
|
describe("starDestroyer", () => {
|
||||||
const ip = "127.0.0.1";
|
const ip = "127.0.0.1";
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import { Star, Event } from "@server/models";
|
import { Star, Event } from "@server/models";
|
||||||
import { buildDocument, buildUser } from "@server/test/factories";
|
import { buildDocument, buildUser } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import starUpdater from "./starUpdater";
|
import starUpdater from "./starUpdater";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("starUpdater", () => {
|
describe("starUpdater", () => {
|
||||||
const ip = "127.0.0.1";
|
const ip = "127.0.0.1";
|
||||||
|
|||||||
@@ -6,10 +6,14 @@ import {
|
|||||||
buildTeam,
|
buildTeam,
|
||||||
buildDocument,
|
buildDocument,
|
||||||
} from "@server/test/factories";
|
} from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import teamPermanentDeleter from "./teamPermanentDeleter";
|
import teamPermanentDeleter from "./teamPermanentDeleter";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("teamPermanentDeleter", () => {
|
describe("teamPermanentDeleter", () => {
|
||||||
it("should destroy related data", async () => {
|
it("should destroy related data", async () => {
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
import env from "@server/env";
|
import env from "@server/env";
|
||||||
import TeamDomain from "@server/models/TeamDomain";
|
import TeamDomain from "@server/models/TeamDomain";
|
||||||
import { buildTeam, buildUser } from "@server/test/factories";
|
import { buildTeam, buildUser } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import teamProvisioner from "./teamProvisioner";
|
import teamProvisioner from "./teamProvisioner";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("teamProvisioner", () => {
|
describe("teamProvisioner", () => {
|
||||||
const ip = "127.0.0.1";
|
const ip = "127.0.0.1";
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
import { buildUser, buildAdmin } from "@server/test/factories";
|
import { buildUser, buildAdmin } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import userDestroyer from "./userDestroyer";
|
import userDestroyer from "./userDestroyer";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("userDestroyer", () => {
|
describe("userDestroyer", () => {
|
||||||
const ip = "127.0.0.1";
|
const ip = "127.0.0.1";
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
import { buildUser } from "@server/test/factories";
|
import { buildUser } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import userInviter from "./userInviter";
|
import userInviter from "./userInviter";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("userInviter", () => {
|
describe("userInviter", () => {
|
||||||
const ip = "127.0.0.1";
|
const ip = "127.0.0.1";
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
import { TeamDomain } from "@server/models";
|
import { TeamDomain } from "@server/models";
|
||||||
import { buildUser, buildTeam, buildInvite } from "@server/test/factories";
|
import { buildUser, buildTeam, buildInvite } from "@server/test/factories";
|
||||||
import { flushdb, seed } from "@server/test/support";
|
import { getTestDatabase, seed } from "@server/test/support";
|
||||||
import userProvisioner from "./userProvisioner";
|
import userProvisioner from "./userProvisioner";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("userProvisioner", () => {
|
describe("userProvisioner", () => {
|
||||||
const ip = "127.0.0.1";
|
const ip = "127.0.0.1";
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import GroupUser from "@server/models/GroupUser";
|
import GroupUser from "@server/models/GroupUser";
|
||||||
import { buildGroup, buildAdmin, buildUser } from "@server/test/factories";
|
import { buildGroup, buildAdmin, buildUser } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import userSuspender from "./userSuspender";
|
import userSuspender from "./userSuspender";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("userSuspender", () => {
|
describe("userSuspender", () => {
|
||||||
const ip = "127.0.0.1";
|
const ip = "127.0.0.1";
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
import randomstring from "randomstring";
|
import randomstring from "randomstring";
|
||||||
import ApiKey from "@server/models/ApiKey";
|
import ApiKey from "@server/models/ApiKey";
|
||||||
import { buildUser, buildTeam } from "@server/test/factories";
|
import { buildUser, buildTeam } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import auth from "./authentication";
|
import auth from "./authentication";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("Authentication middleware", () => {
|
describe("Authentication middleware", () => {
|
||||||
describe("with JWT", () => {
|
describe("with JWT", () => {
|
||||||
|
|||||||
@@ -7,13 +7,19 @@ import {
|
|||||||
buildTeam,
|
buildTeam,
|
||||||
buildDocument,
|
buildDocument,
|
||||||
} from "@server/test/factories";
|
} from "@server/test/factories";
|
||||||
import { flushdb, seed } from "@server/test/support";
|
import { getTestDatabase, seed } from "@server/test/support";
|
||||||
import slugify from "@server/utils/slugify";
|
import slugify from "@server/utils/slugify";
|
||||||
import Collection from "./Collection";
|
import Collection from "./Collection";
|
||||||
import Document from "./Document";
|
import Document from "./Document";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
beforeEach(jest.resetAllMocks);
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await db.flush();
|
||||||
|
jest.resetAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
describe("#url", () => {
|
describe("#url", () => {
|
||||||
test("should return correct url for the collection", () => {
|
test("should return correct url for the collection", () => {
|
||||||
|
|||||||
@@ -6,11 +6,17 @@ import {
|
|||||||
buildUser,
|
buildUser,
|
||||||
buildShare,
|
buildShare,
|
||||||
} from "@server/test/factories";
|
} from "@server/test/factories";
|
||||||
import { flushdb, seed } from "@server/test/support";
|
import { getTestDatabase, seed } from "@server/test/support";
|
||||||
import slugify from "@server/utils/slugify";
|
import slugify from "@server/utils/slugify";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
beforeEach(jest.resetAllMocks);
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await db.flush();
|
||||||
|
jest.resetAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
describe("#getSummary", () => {
|
describe("#getSummary", () => {
|
||||||
test("should strip markdown", async () => {
|
test("should strip markdown", async () => {
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
import { buildUser, buildGroup, buildCollection } from "@server/test/factories";
|
import { buildUser, buildGroup, buildCollection } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import CollectionGroup from "./CollectionGroup";
|
import CollectionGroup from "./CollectionGroup";
|
||||||
import GroupUser from "./GroupUser";
|
import GroupUser from "./GroupUser";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
beforeEach(jest.resetAllMocks);
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await db.flush();
|
||||||
|
jest.resetAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
describe("afterDestroy hook", () => {
|
describe("afterDestroy hook", () => {
|
||||||
test("should destroy associated group and collection join relations", async () => {
|
test("should destroy associated group and collection join relations", async () => {
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
import { buildDocument } from "@server/test/factories";
|
import { buildDocument } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import Revision from "./Revision";
|
import Revision from "./Revision";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
beforeEach(jest.resetAllMocks);
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await db.flush();
|
||||||
|
jest.resetAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
describe("#findLatest", () => {
|
describe("#findLatest", () => {
|
||||||
test("should return latest revision", async () => {
|
test("should return latest revision", async () => {
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
import { buildTeam, buildCollection } from "@server/test/factories";
|
import { buildTeam, buildCollection } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await db.flush();
|
||||||
|
jest.resetAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
describe("collectionIds", () => {
|
describe("collectionIds", () => {
|
||||||
it("should return non-private collection ids", async () => {
|
it("should return non-private collection ids", async () => {
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
import { buildAdmin, buildTeam } from "@server/test/factories";
|
import { buildAdmin, buildTeam } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import TeamDomain from "./TeamDomain";
|
import TeamDomain from "./TeamDomain";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await db.flush();
|
||||||
|
jest.resetAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
describe("team domain model", () => {
|
describe("team domain model", () => {
|
||||||
describe("create", () => {
|
describe("create", () => {
|
||||||
|
|||||||
@@ -1,16 +1,21 @@
|
|||||||
import { buildUser, buildTeam, buildCollection } from "@server/test/factories";
|
import { buildUser, buildTeam, buildCollection } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import CollectionUser from "./CollectionUser";
|
import CollectionUser from "./CollectionUser";
|
||||||
import UserAuthentication from "./UserAuthentication";
|
import UserAuthentication from "./UserAuthentication";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
jest.useFakeTimers().setSystemTime(new Date("2018-01-02T00:00:00.000Z"));
|
jest.useFakeTimers().setSystemTime(new Date("2018-01-02T00:00:00.000Z"));
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
jest.useRealTimers();
|
jest.useRealTimers();
|
||||||
|
db.disconnect();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("user model", () => {
|
describe("user model", () => {
|
||||||
describe("destroy", () => {
|
describe("destroy", () => {
|
||||||
it("should delete user authentications", async () => {
|
it("should delete user authentications", async () => {
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import { CollectionUser, Collection } from "@server/models";
|
import { CollectionUser, Collection } from "@server/models";
|
||||||
import { buildUser, buildTeam, buildCollection } from "@server/test/factories";
|
import { buildUser, buildTeam, buildCollection } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import { serialize } from "./index";
|
import { serialize } from "./index";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("read_write permission", () => {
|
describe("read_write permission", () => {
|
||||||
it("should allow read write permissions for team member", async () => {
|
it("should allow read write permissions for team member", async () => {
|
||||||
|
|||||||
@@ -4,10 +4,14 @@ import {
|
|||||||
buildDocument,
|
buildDocument,
|
||||||
buildCollection,
|
buildCollection,
|
||||||
} from "@server/test/factories";
|
} from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import { serialize } from "./index";
|
import { serialize } from "./index";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("read_write collection", () => {
|
describe("read_write collection", () => {
|
||||||
it("should allow read write permissions for team member", async () => {
|
it("should allow read write permissions for team member", async () => {
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
import { buildUser, buildTeam } from "@server/test/factories";
|
import { buildUser, buildTeam } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import { serialize } from "./index";
|
import { serialize } from "./index";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
it("should serialize policy", async () => {
|
it("should serialize policy", async () => {
|
||||||
const user = await buildUser();
|
const user = await buildUser();
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
import { buildUser, buildTeam, buildAdmin } from "@server/test/factories";
|
import { buildUser, buildTeam, buildAdmin } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import { serialize } from "./index";
|
import { serialize } from "./index";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
it("should allow reading only", async () => {
|
it("should allow reading only", async () => {
|
||||||
const team = await buildTeam();
|
const team = await buildTeam();
|
||||||
const user = await buildUser({
|
const user = await buildUser({
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
import { Backlink } from "@server/models";
|
import { Backlink } from "@server/models";
|
||||||
import { buildDocument } from "@server/test/factories";
|
import { buildDocument } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import BacklinksProcessor from "./BacklinksProcessor";
|
import BacklinksProcessor from "./BacklinksProcessor";
|
||||||
|
|
||||||
const ip = "127.0.0.1";
|
const ip = "127.0.0.1";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
beforeEach(jest.resetAllMocks);
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await db.flush();
|
||||||
|
jest.resetAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
describe("documents.publish", () => {
|
describe("documents.publish", () => {
|
||||||
test("should create new backlink records", async () => {
|
test("should create new backlink records", async () => {
|
||||||
@@ -161,7 +167,7 @@ describe("documents.update", () => {
|
|||||||
ip,
|
ip,
|
||||||
});
|
});
|
||||||
document.text = `First link is gone
|
document.text = `First link is gone
|
||||||
|
|
||||||
[this is a another link](${yetAnotherDocument.url})`;
|
[this is a another link](${yetAnotherDocument.url})`;
|
||||||
await document.save();
|
await document.save();
|
||||||
|
|
||||||
|
|||||||
@@ -5,14 +5,20 @@ import {
|
|||||||
buildCollection,
|
buildCollection,
|
||||||
buildUser,
|
buildUser,
|
||||||
} from "@server/test/factories";
|
} from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import NotificationsProcessor from "./NotificationsProcessor";
|
import NotificationsProcessor from "./NotificationsProcessor";
|
||||||
|
|
||||||
jest.mock("@server/emails/templates/DocumentNotificationEmail");
|
jest.mock("@server/emails/templates/DocumentNotificationEmail");
|
||||||
const ip = "127.0.0.1";
|
const ip = "127.0.0.1";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
beforeEach(jest.resetAllMocks);
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await db.flush();
|
||||||
|
jest.resetAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
describe("documents.publish", () => {
|
describe("documents.publish", () => {
|
||||||
test("should not send a notification to author", async () => {
|
test("should not send a notification to author", async () => {
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
import { Revision } from "@server/models";
|
import { Revision } from "@server/models";
|
||||||
import { buildDocument } from "@server/test/factories";
|
import { buildDocument } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import RevisionsProcessor from "./RevisionsProcessor";
|
import RevisionsProcessor from "./RevisionsProcessor";
|
||||||
|
|
||||||
const ip = "127.0.0.1";
|
const ip = "127.0.0.1";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
beforeEach(jest.resetAllMocks);
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await db.flush();
|
||||||
|
jest.resetAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
describe("documents.update.debounced", () => {
|
describe("documents.update.debounced", () => {
|
||||||
test("should create a revision", async () => {
|
test("should create a revision", async () => {
|
||||||
|
|||||||
@@ -1,18 +1,21 @@
|
|||||||
import { buildUser, buildWebhookSubscription } from "@server/test/factories";
|
import { buildUser, buildWebhookSubscription } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import { UserEvent } from "@server/types";
|
import { UserEvent } from "@server/types";
|
||||||
import DeliverWebhookTask from "../tasks/DeliverWebhookTask";
|
import DeliverWebhookTask from "../tasks/DeliverWebhookTask";
|
||||||
import WebhookProcessor from "./WebhookProcessor";
|
import WebhookProcessor from "./WebhookProcessor";
|
||||||
|
|
||||||
jest.mock("@server/queues/tasks/DeliverWebhookTask");
|
jest.mock("@server/queues/tasks/DeliverWebhookTask");
|
||||||
|
const ip = "127.0.0.1";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
beforeEach(() => {
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await db.flush();
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
const ip = "127.0.0.1";
|
|
||||||
|
|
||||||
describe("WebhookProcessor", () => {
|
describe("WebhookProcessor", () => {
|
||||||
test("it schedules a delivery for the event", async () => {
|
test("it schedules a delivery for the event", async () => {
|
||||||
const subscription = await buildWebhookSubscription({
|
const subscription = await buildWebhookSubscription({
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
import { subDays } from "date-fns";
|
import { subDays } from "date-fns";
|
||||||
import { Document } from "@server/models";
|
import { Document } from "@server/models";
|
||||||
import { buildDocument } from "@server/test/factories";
|
import { buildDocument } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import CleanupDeletedDocumentsTask from "./CleanupDeletedDocumentsTask";
|
import CleanupDeletedDocumentsTask from "./CleanupDeletedDocumentsTask";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("CleanupDeletedDocumentsTask", () => {
|
describe("CleanupDeletedDocumentsTask", () => {
|
||||||
it("should not destroy documents not deleted", async () => {
|
it("should not destroy documents not deleted", async () => {
|
||||||
|
|||||||
@@ -6,10 +6,14 @@ import {
|
|||||||
buildWebhookSubscription,
|
buildWebhookSubscription,
|
||||||
buildViewer,
|
buildViewer,
|
||||||
} from "@server/test/factories";
|
} from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import CleanupDemotedUserTask from "./CleanupDemotedUserTask";
|
import CleanupDemotedUserTask from "./CleanupDemotedUserTask";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("CleanupDemotedUserTask", () => {
|
describe("CleanupDemotedUserTask", () => {
|
||||||
it("should delete api keys for suspended user", async () => {
|
it("should delete api keys for suspended user", async () => {
|
||||||
|
|||||||
@@ -5,10 +5,14 @@ import {
|
|||||||
FileOperationType,
|
FileOperationType,
|
||||||
} from "@server/models/FileOperation";
|
} from "@server/models/FileOperation";
|
||||||
import { buildFileOperation } from "@server/test/factories";
|
import { buildFileOperation } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import CleanupExpiredFileOperationsTask from "./CleanupExpiredFileOperationsTask";
|
import CleanupExpiredFileOperationsTask from "./CleanupExpiredFileOperationsTask";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("CleanupExpiredFileOperationsTask", () => {
|
describe("CleanupExpiredFileOperationsTask", () => {
|
||||||
it("should expire exports older than 15 days ago", async () => {
|
it("should expire exports older than 15 days ago", async () => {
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
import { subDays } from "date-fns";
|
import { subDays } from "date-fns";
|
||||||
import { WebhookDelivery } from "@server/models";
|
import { WebhookDelivery } from "@server/models";
|
||||||
import { buildWebhookDelivery } from "@server/test/factories";
|
import { buildWebhookDelivery } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import CleanupWebhookDeliveriesTask from "./CleanupWebhookDeliveriesTask";
|
import CleanupWebhookDeliveriesTask from "./CleanupWebhookDeliveriesTask";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
const deliveryExists = async (delivery: WebhookDelivery) => {
|
const deliveryExists = async (delivery: WebhookDelivery) => {
|
||||||
const results = await WebhookDelivery.findOne({ where: { id: delivery.id } });
|
const results = await WebhookDelivery.findOne({ where: { id: delivery.id } });
|
||||||
|
|||||||
@@ -6,12 +6,16 @@ import {
|
|||||||
buildWebhookDelivery,
|
buildWebhookDelivery,
|
||||||
buildWebhookSubscription,
|
buildWebhookSubscription,
|
||||||
} from "@server/test/factories";
|
} from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import { UserEvent } from "@server/types";
|
import { UserEvent } from "@server/types";
|
||||||
import DeliverWebhookTask from "./DeliverWebhookTask";
|
import DeliverWebhookTask from "./DeliverWebhookTask";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
beforeEach(() => {
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await db.flush();
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
fetchMock.resetMocks();
|
fetchMock.resetMocks();
|
||||||
fetchMock.doMock();
|
fetchMock.doMock();
|
||||||
|
|||||||
@@ -2,10 +2,14 @@ import fs from "fs";
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import { FileOperation } from "@server/models";
|
import { FileOperation } from "@server/models";
|
||||||
import { buildFileOperation } from "@server/test/factories";
|
import { buildFileOperation } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import ImportMarkdownZipTask from "./ImportMarkdownZipTask";
|
import ImportMarkdownZipTask from "./ImportMarkdownZipTask";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("ImportMarkdownZipTask", () => {
|
describe("ImportMarkdownZipTask", () => {
|
||||||
it("should import the documents, attachments", async () => {
|
it("should import the documents, attachments", async () => {
|
||||||
|
|||||||
@@ -2,10 +2,14 @@ import fs from "fs";
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import { FileOperation } from "@server/models";
|
import { FileOperation } from "@server/models";
|
||||||
import { buildFileOperation } from "@server/test/factories";
|
import { buildFileOperation } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import ImportNotionTask from "./ImportNotionTask";
|
import ImportNotionTask from "./ImportNotionTask";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("ImportNotionTask", () => {
|
describe("ImportNotionTask", () => {
|
||||||
it("should import successfully from a Markdown export", async () => {
|
it("should import successfully from a Markdown export", async () => {
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
import { subDays } from "date-fns";
|
import { subDays } from "date-fns";
|
||||||
import InviteReminderEmail from "@server/emails/templates/InviteReminderEmail";
|
import InviteReminderEmail from "@server/emails/templates/InviteReminderEmail";
|
||||||
import { buildInvite } from "@server/test/factories";
|
import { buildInvite } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import InviteReminderTask from "./InviteReminderTask";
|
import InviteReminderTask from "./InviteReminderTask";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("InviteReminderTask", () => {
|
describe("InviteReminderTask", () => {
|
||||||
it("should not destroy documents not deleted", async () => {
|
it("should not destroy documents not deleted", async () => {
|
||||||
|
|||||||
@@ -6,13 +6,16 @@ import {
|
|||||||
buildAttachment,
|
buildAttachment,
|
||||||
buildDocument,
|
buildDocument,
|
||||||
} from "@server/test/factories";
|
} from "@server/test/factories";
|
||||||
import { flushdb, getTestServer } from "@server/test/support";
|
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||||
|
|
||||||
const server = getTestServer();
|
|
||||||
|
|
||||||
jest.mock("@server/utils/s3");
|
jest.mock("@server/utils/s3");
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
const server = getTestServer();
|
||||||
|
|
||||||
|
afterAll(server.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("#attachments.create", () => {
|
describe("#attachments.create", () => {
|
||||||
it("should require authentication", async () => {
|
it("should require authentication", async () => {
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
import sharedEnv from "@shared/env";
|
import sharedEnv from "@shared/env";
|
||||||
import env from "@server/env";
|
import env from "@server/env";
|
||||||
import { buildUser, buildTeam } from "@server/test/factories";
|
import { buildUser, buildTeam } from "@server/test/factories";
|
||||||
import { flushdb, getTestServer } from "@server/test/support";
|
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||||
|
|
||||||
|
const db = getTestDatabase();
|
||||||
const server = getTestServer();
|
const server = getTestServer();
|
||||||
beforeEach(() => flushdb());
|
|
||||||
|
afterAll(server.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("#auth.info", () => {
|
describe("#auth.info", () => {
|
||||||
it("should return current authentication", async () => {
|
it("should return current authentication", async () => {
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
import { buildUser, buildAdmin, buildTeam } from "@server/test/factories";
|
import { buildUser, buildAdmin, buildTeam } from "@server/test/factories";
|
||||||
import { flushdb, getTestServer } from "@server/test/support";
|
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||||
|
|
||||||
|
const db = getTestDatabase();
|
||||||
const server = getTestServer();
|
const server = getTestServer();
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
afterAll(server.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("#authenticationProviders.info", () => {
|
describe("#authenticationProviders.info", () => {
|
||||||
it("should return auth provider", async () => {
|
it("should return auth provider", async () => {
|
||||||
|
|||||||
@@ -7,10 +7,14 @@ import {
|
|||||||
buildCollection,
|
buildCollection,
|
||||||
buildDocument,
|
buildDocument,
|
||||||
} from "@server/test/factories";
|
} from "@server/test/factories";
|
||||||
import { flushdb, seed, getTestServer } from "@server/test/support";
|
import { seed, getTestDatabase, getTestServer } from "@server/test/support";
|
||||||
|
|
||||||
|
const db = getTestDatabase();
|
||||||
const server = getTestServer();
|
const server = getTestServer();
|
||||||
beforeEach(() => flushdb());
|
|
||||||
|
afterAll(server.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("#collections.list", () => {
|
describe("#collections.list", () => {
|
||||||
it("should require authentication", async () => {
|
it("should require authentication", async () => {
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
import { flushdb, getTestServer } from "@server/test/support";
|
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||||
|
|
||||||
|
const db = getTestDatabase();
|
||||||
const server = getTestServer();
|
const server = getTestServer();
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
afterAll(server.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("#cron.daily", () => {
|
describe("#cron.daily", () => {
|
||||||
it("should require authentication", async () => {
|
it("should require authentication", async () => {
|
||||||
|
|||||||
@@ -15,10 +15,14 @@ import {
|
|||||||
buildDocument,
|
buildDocument,
|
||||||
buildViewer,
|
buildViewer,
|
||||||
} from "@server/test/factories";
|
} from "@server/test/factories";
|
||||||
import { flushdb, seed, getTestServer } from "@server/test/support";
|
import { seed, getTestDatabase, getTestServer } from "@server/test/support";
|
||||||
|
|
||||||
|
const db = getTestDatabase();
|
||||||
const server = getTestServer();
|
const server = getTestServer();
|
||||||
beforeEach(() => flushdb());
|
|
||||||
|
afterAll(server.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("#documents.info", () => {
|
describe("#documents.info", () => {
|
||||||
it("should return published document", async () => {
|
it("should return published document", async () => {
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
import { buildEvent, buildUser } from "@server/test/factories";
|
import { buildEvent, buildUser } from "@server/test/factories";
|
||||||
import { flushdb, seed, getTestServer } from "@server/test/support";
|
import { seed, getTestDatabase, getTestServer } from "@server/test/support";
|
||||||
|
|
||||||
|
const db = getTestDatabase();
|
||||||
const server = getTestServer();
|
const server = getTestServer();
|
||||||
beforeEach(() => flushdb());
|
|
||||||
|
afterAll(server.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("#events.list", () => {
|
describe("#events.list", () => {
|
||||||
it("should only return activity events", async () => {
|
it("should only return activity events", async () => {
|
||||||
|
|||||||
@@ -10,13 +10,17 @@ import {
|
|||||||
buildTeam,
|
buildTeam,
|
||||||
buildUser,
|
buildUser,
|
||||||
} from "@server/test/factories";
|
} from "@server/test/factories";
|
||||||
import { flushdb, getTestServer } from "@server/test/support";
|
|
||||||
|
|
||||||
|
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||||
|
|
||||||
|
const db = getTestDatabase();
|
||||||
const server = getTestServer();
|
const server = getTestServer();
|
||||||
|
|
||||||
jest.mock("@server/utils/s3");
|
jest.mock("@server/utils/s3");
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
afterAll(server.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("#fileOperations.info", () => {
|
describe("#fileOperations.info", () => {
|
||||||
it("should return fileOperation", async () => {
|
it("should return fileOperation", async () => {
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import { Event } from "@server/models";
|
import { Event } from "@server/models";
|
||||||
import { buildUser, buildAdmin, buildGroup } from "@server/test/factories";
|
import { buildUser, buildAdmin, buildGroup } from "@server/test/factories";
|
||||||
import { flushdb, getTestServer } from "@server/test/support";
|
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||||
|
|
||||||
|
const db = getTestDatabase();
|
||||||
const server = getTestServer();
|
const server = getTestServer();
|
||||||
beforeEach(() => flushdb());
|
|
||||||
|
afterAll(server.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("#groups.create", () => {
|
describe("#groups.create", () => {
|
||||||
it("should create a group", async () => {
|
it("should create a group", async () => {
|
||||||
|
|||||||
@@ -1,16 +1,20 @@
|
|||||||
import env from "@server/env";
|
import env from "@server/env";
|
||||||
import { IntegrationAuthentication, SearchQuery } from "@server/models";
|
import { IntegrationAuthentication, SearchQuery } from "@server/models";
|
||||||
import { buildDocument, buildIntegration } from "@server/test/factories";
|
import { buildDocument, buildIntegration } from "@server/test/factories";
|
||||||
import { flushdb, seed, getTestServer } from "@server/test/support";
|
import { seed, getTestDatabase, getTestServer } from "@server/test/support";
|
||||||
import * as Slack from "@server/utils/slack";
|
import * as Slack from "@server/utils/slack";
|
||||||
|
|
||||||
const server = getTestServer();
|
|
||||||
beforeEach(() => flushdb());
|
|
||||||
|
|
||||||
jest.mock("../../utils/slack", () => ({
|
jest.mock("../../utils/slack", () => ({
|
||||||
post: jest.fn(),
|
post: jest.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const db = getTestDatabase();
|
||||||
|
const server = getTestServer();
|
||||||
|
|
||||||
|
afterAll(server.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("#hooks.unfurl", () => {
|
describe("#hooks.unfurl", () => {
|
||||||
it("should return documents", async () => {
|
it("should return documents", async () => {
|
||||||
const { user, document } = await seed();
|
const { user, document } = await seed();
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { flushdb, getTestServer } from "@server/test/support";
|
import { getTestServer } from "@server/test/support";
|
||||||
|
|
||||||
const server = getTestServer();
|
const server = getTestServer();
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
afterAll(server.disconnect);
|
||||||
|
|
||||||
describe("POST unknown endpoint", () => {
|
describe("POST unknown endpoint", () => {
|
||||||
it("should be not found", async () => {
|
it("should be not found", async () => {
|
||||||
|
|||||||
@@ -4,11 +4,15 @@ import {
|
|||||||
buildUser,
|
buildUser,
|
||||||
buildIntegration,
|
buildIntegration,
|
||||||
} from "@server/test/factories";
|
} from "@server/test/factories";
|
||||||
import { flushdb, getTestServer } from "@server/test/support";
|
|
||||||
|
|
||||||
|
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||||
|
|
||||||
|
const db = getTestDatabase();
|
||||||
const server = getTestServer();
|
const server = getTestServer();
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
afterAll(server.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("#integrations.update", () => {
|
describe("#integrations.update", () => {
|
||||||
it("should allow updating integration events", async () => {
|
it("should allow updating integration events", async () => {
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
import { flushdb, seed, getTestServer } from "@server/test/support";
|
import { seed, getTestDatabase, getTestServer } from "@server/test/support";
|
||||||
|
|
||||||
|
const db = getTestDatabase();
|
||||||
const server = getTestServer();
|
const server = getTestServer();
|
||||||
beforeEach(() => flushdb());
|
|
||||||
|
afterAll(server.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("#pagination", () => {
|
describe("#pagination", () => {
|
||||||
it("should allow offset and limit", async () => {
|
it("should allow offset and limit", async () => {
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import { Revision } from "@server/models";
|
import { Revision } from "@server/models";
|
||||||
import { buildDocument, buildUser } from "@server/test/factories";
|
import { buildDocument, buildUser } from "@server/test/factories";
|
||||||
import { flushdb, seed, getTestServer } from "@server/test/support";
|
import { seed, getTestDatabase, getTestServer } from "@server/test/support";
|
||||||
|
|
||||||
|
const db = getTestDatabase();
|
||||||
const server = getTestServer();
|
const server = getTestServer();
|
||||||
beforeEach(() => flushdb());
|
|
||||||
|
afterAll(server.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("#revisions.info", () => {
|
describe("#revisions.info", () => {
|
||||||
it("should return a document revision", async () => {
|
it("should return a document revision", async () => {
|
||||||
|
|||||||
@@ -6,10 +6,15 @@ import {
|
|||||||
buildAdmin,
|
buildAdmin,
|
||||||
buildCollection,
|
buildCollection,
|
||||||
} from "@server/test/factories";
|
} from "@server/test/factories";
|
||||||
import { flushdb, seed, getTestServer } from "@server/test/support";
|
|
||||||
|
|
||||||
|
import { seed, getTestDatabase, getTestServer } from "@server/test/support";
|
||||||
|
|
||||||
|
const db = getTestDatabase();
|
||||||
const server = getTestServer();
|
const server = getTestServer();
|
||||||
beforeEach(() => flushdb());
|
|
||||||
|
afterAll(server.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("#shares.list", () => {
|
describe("#shares.list", () => {
|
||||||
it("should only return shares created by user", async () => {
|
it("should only return shares created by user", async () => {
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
import { buildUser, buildStar, buildDocument } from "@server/test/factories";
|
import { buildUser, buildStar, buildDocument } from "@server/test/factories";
|
||||||
import { flushdb, getTestServer } from "@server/test/support";
|
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||||
|
|
||||||
|
const db = getTestDatabase();
|
||||||
const server = getTestServer();
|
const server = getTestServer();
|
||||||
beforeEach(() => flushdb());
|
|
||||||
|
afterAll(server.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("#stars.create", () => {
|
describe("#stars.create", () => {
|
||||||
it("should create a star", async () => {
|
it("should create a star", async () => {
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import { TeamDomain } from "@server/models";
|
import { TeamDomain } from "@server/models";
|
||||||
import { buildAdmin, buildCollection, buildTeam } from "@server/test/factories";
|
import { buildAdmin, buildCollection, buildTeam } from "@server/test/factories";
|
||||||
import { flushdb, seed, getTestServer } from "@server/test/support";
|
import { seed, getTestDatabase, getTestServer } from "@server/test/support";
|
||||||
|
|
||||||
|
const db = getTestDatabase();
|
||||||
const server = getTestServer();
|
const server = getTestServer();
|
||||||
beforeEach(() => flushdb());
|
|
||||||
|
afterAll(server.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("#team.update", () => {
|
describe("#team.update", () => {
|
||||||
it("should update team details", async () => {
|
it("should update team details", async () => {
|
||||||
|
|||||||
@@ -1,20 +1,19 @@
|
|||||||
import TestServer from "fetch-test-server";
|
|
||||||
import webService from "@server/services/web";
|
|
||||||
import { buildTeam, buildAdmin, buildUser } from "@server/test/factories";
|
import { buildTeam, buildAdmin, buildUser } from "@server/test/factories";
|
||||||
import { flushdb, seed } from "@server/test/support";
|
import { seed, getTestDatabase, getTestServer } from "@server/test/support";
|
||||||
|
|
||||||
const app = webService();
|
const db = getTestDatabase();
|
||||||
const server = new TestServer(app.callback());
|
const server = getTestServer();
|
||||||
beforeEach(() => flushdb());
|
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
jest.useFakeTimers().setSystemTime(new Date("2018-01-02T00:00:00.000Z"));
|
jest.useFakeTimers().setSystemTime(new Date("2018-01-02T00:00:00.000Z"));
|
||||||
});
|
});
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
jest.useRealTimers();
|
jest.useRealTimers();
|
||||||
return server.close();
|
server.disconnect();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("#users.list", () => {
|
describe("#users.list", () => {
|
||||||
it("should allow filtering by user name", async () => {
|
it("should allow filtering by user name", async () => {
|
||||||
const user = await buildUser({
|
const user = await buildUser({
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import { View, CollectionUser } from "@server/models";
|
import { View, CollectionUser } from "@server/models";
|
||||||
import { buildUser } from "@server/test/factories";
|
import { buildUser } from "@server/test/factories";
|
||||||
import { flushdb, seed, getTestServer } from "@server/test/support";
|
import { seed, getTestDatabase, getTestServer } from "@server/test/support";
|
||||||
|
|
||||||
|
const db = getTestDatabase();
|
||||||
const server = getTestServer();
|
const server = getTestServer();
|
||||||
beforeEach(() => flushdb());
|
|
||||||
|
afterAll(server.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("#views.list", () => {
|
describe("#views.list", () => {
|
||||||
it("should return views for a document", async () => {
|
it("should return views for a document", async () => {
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
import { buildUser, buildCollection } from "@server/test/factories";
|
import { buildUser, buildCollection } from "@server/test/factories";
|
||||||
import { flushdb, getTestServer } from "@server/test/support";
|
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||||
|
|
||||||
|
const db = getTestDatabase();
|
||||||
const server = getTestServer();
|
const server = getTestServer();
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
afterAll(server.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("auth/redirect", () => {
|
describe("auth/redirect", () => {
|
||||||
it("should redirect to home", async () => {
|
it("should redirect to home", async () => {
|
||||||
|
|||||||
@@ -3,11 +3,14 @@ import SigninEmail from "@server/emails/templates/SigninEmail";
|
|||||||
import WelcomeEmail from "@server/emails/templates/WelcomeEmail";
|
import WelcomeEmail from "@server/emails/templates/WelcomeEmail";
|
||||||
import env from "@server/env";
|
import env from "@server/env";
|
||||||
import { buildUser, buildGuestUser, buildTeam } from "@server/test/factories";
|
import { buildUser, buildGuestUser, buildTeam } from "@server/test/factories";
|
||||||
import { flushdb, getTestServer } from "@server/test/support";
|
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||||
|
|
||||||
|
const db = getTestDatabase();
|
||||||
const server = getTestServer();
|
const server = getTestServer();
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
afterAll(server.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("email", () => {
|
describe("email", () => {
|
||||||
it("should require email param", async () => {
|
it("should require email param", async () => {
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
import { buildShare, buildDocument } from "@server/test/factories";
|
import { buildShare, buildDocument } from "@server/test/factories";
|
||||||
import { flushdb, getTestServer } from "@server/test/support";
|
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||||
|
|
||||||
|
const db = getTestDatabase();
|
||||||
const server = getTestServer();
|
const server = getTestServer();
|
||||||
beforeEach(() => flushdb());
|
|
||||||
|
afterAll(server.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("/share/:id", () => {
|
describe("/share/:id", () => {
|
||||||
it("should return standard title in html when loading unpublished share", async () => {
|
it("should return standard title in html when loading unpublished share", async () => {
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import { Revision, Event } from "@server/models";
|
import { Revision, Event } from "@server/models";
|
||||||
import { buildDocument } from "@server/test/factories";
|
import { buildDocument } from "@server/test/factories";
|
||||||
import { flushdb } from "@server/test/support";
|
import { getTestDatabase } from "@server/test/support";
|
||||||
import script from "./20210716000000-backfill-revisions";
|
import script from "./20210716000000-backfill-revisions";
|
||||||
|
|
||||||
beforeEach(() => flushdb());
|
const db = getTestDatabase();
|
||||||
|
|
||||||
|
afterAll(db.disconnect);
|
||||||
|
|
||||||
|
beforeEach(db.flush);
|
||||||
|
|
||||||
describe("#work", () => {
|
describe("#work", () => {
|
||||||
it("should create events for revisions", async () => {
|
it("should create events for revisions", async () => {
|
||||||
|
|||||||
@@ -1,24 +1,11 @@
|
|||||||
import TestServer from "fetch-test-server";
|
import TestServer from "fetch-test-server";
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
import { sequelize } from "@server/database/sequelize";
|
import { sequelize as db } from "@server/database/sequelize";
|
||||||
import { User, Document, Collection, Team } from "@server/models";
|
import { User, Document, Collection, Team } from "@server/models";
|
||||||
import webService from "@server/services/web";
|
import webService from "@server/services/web";
|
||||||
|
|
||||||
const sql = sequelize.getQueryInterface();
|
|
||||||
const tables = Object.keys(sequelize.models).map((model) => {
|
|
||||||
const n = sequelize.models[model].getTableName();
|
|
||||||
return (sql.queryGenerator as any).quoteTable(
|
|
||||||
typeof n === "string" ? n : n.tableName
|
|
||||||
);
|
|
||||||
});
|
|
||||||
const flushQuery = `TRUNCATE ${tables.join(", ")} CASCADE`;
|
|
||||||
|
|
||||||
export function flushdb() {
|
|
||||||
return sequelize.query(flushQuery);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const seed = async () => {
|
export const seed = async () => {
|
||||||
return sequelize.transaction(async (transaction) => {
|
return db.transaction(async (transaction) => {
|
||||||
const team = await Team.create(
|
const team = await Team.create(
|
||||||
{
|
{
|
||||||
name: "Team",
|
name: "Team",
|
||||||
@@ -112,14 +99,35 @@ export const seed = async () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
let testServer: typeof TestServer | undefined;
|
|
||||||
|
|
||||||
export function getTestServer() {
|
export function getTestServer() {
|
||||||
if (testServer) {
|
|
||||||
return testServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
const app = webService();
|
const app = webService();
|
||||||
testServer = new TestServer(app.callback());
|
const server = new TestServer(app.callback());
|
||||||
return testServer;
|
|
||||||
|
server.disconnect = async () => {
|
||||||
|
await db.close();
|
||||||
|
server.close();
|
||||||
|
};
|
||||||
|
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getTestDatabase() {
|
||||||
|
const flush = async () => {
|
||||||
|
const sql = db.getQueryInterface();
|
||||||
|
const tables = Object.keys(db.models).map((model) => {
|
||||||
|
const n = db.models[model].getTableName();
|
||||||
|
return (sql.queryGenerator as any).quoteTable(
|
||||||
|
typeof n === "string" ? n : n.tableName
|
||||||
|
);
|
||||||
|
});
|
||||||
|
const flushQuery = `TRUNCATE ${tables.join(", ")} CASCADE`;
|
||||||
|
|
||||||
|
await db.query(flushQuery);
|
||||||
|
};
|
||||||
|
|
||||||
|
const disconnect = async () => {
|
||||||
|
await db.close();
|
||||||
|
};
|
||||||
|
|
||||||
|
return { flush, disconnect };
|
||||||
}
|
}
|
||||||
|
|||||||
3
shared/test/setup.ts
Normal file
3
shared/test/setup.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
jest.mock("i18next-http-backend");
|
||||||
|
|
||||||
|
export {};
|
||||||
Reference in New Issue
Block a user