chore: Reduce test boilerplate (#4300)
* chore: Reduce test boilerplate * mo
This commit is contained in:
@@ -6,17 +6,12 @@ import {
|
||||
buildAttachment,
|
||||
buildDocument,
|
||||
} from "@server/test/factories";
|
||||
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||
import { getTestServer } from "@server/test/support";
|
||||
|
||||
jest.mock("@server/utils/s3");
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
afterAll(server.disconnect);
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("#attachments.create", () => {
|
||||
it("should require authentication", async () => {
|
||||
const res = await server.post("/api/attachments.create");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import sharedEnv from "@shared/env";
|
||||
import env from "@server/env";
|
||||
import { buildUser, buildTeam } from "@server/test/factories";
|
||||
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||
import { getTestServer } from "@server/test/support";
|
||||
|
||||
const mockTeamInSessionId = "1e023d05-951c-41c6-9012-c9fa0402e1c3";
|
||||
|
||||
@@ -13,13 +13,8 @@ jest.mock("@server/utils/authentication", () => {
|
||||
};
|
||||
});
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
afterAll(server.disconnect);
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("#auth.info", () => {
|
||||
it("should return current authentication", async () => {
|
||||
const team = await buildTeam();
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { buildUser, buildAdmin, buildTeam } from "@server/test/factories";
|
||||
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||
import { getTestServer } from "@server/test/support";
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
afterAll(server.disconnect);
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("#authenticationProviders.info", () => {
|
||||
it("should return auth provider", async () => {
|
||||
const team = await buildTeam();
|
||||
|
||||
@@ -8,15 +8,10 @@ import {
|
||||
buildCollection,
|
||||
buildDocument,
|
||||
} from "@server/test/factories";
|
||||
import { seed, getTestDatabase, getTestServer } from "@server/test/support";
|
||||
import { seed, getTestServer } from "@server/test/support";
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
afterAll(server.disconnect);
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("#collections.list", () => {
|
||||
it("should require authentication", async () => {
|
||||
const res = await server.post("/api/collections.list");
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||
import { getTestServer } from "@server/test/support";
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
afterAll(server.disconnect);
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("#cron.daily", () => {
|
||||
it("should require authentication", async () => {
|
||||
const res = await server.post("/api/cron.daily");
|
||||
|
||||
@@ -16,15 +16,10 @@ import {
|
||||
buildDocument,
|
||||
buildViewer,
|
||||
} from "@server/test/factories";
|
||||
import { seed, getTestDatabase, getTestServer } from "@server/test/support";
|
||||
import { seed, getTestServer } from "@server/test/support";
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
afterAll(server.disconnect);
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("#documents.info", () => {
|
||||
it("should return published document", async () => {
|
||||
const { user, document } = await seed();
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import { buildEvent, buildUser } from "@server/test/factories";
|
||||
import { seed, getTestDatabase, getTestServer } from "@server/test/support";
|
||||
import { seed, getTestServer } from "@server/test/support";
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
afterAll(server.disconnect);
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("#events.list", () => {
|
||||
it("should only return activity events", async () => {
|
||||
const { user, admin, document, collection } = await seed();
|
||||
|
||||
@@ -11,17 +11,12 @@ import {
|
||||
buildUser,
|
||||
} from "@server/test/factories";
|
||||
|
||||
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||
import { getTestServer } from "@server/test/support";
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
jest.mock("@server/utils/s3");
|
||||
|
||||
afterAll(server.disconnect);
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("#fileOperations.info", () => {
|
||||
it("should return fileOperation", async () => {
|
||||
const team = await buildTeam();
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
import { Event } from "@server/models";
|
||||
import { buildUser, buildAdmin, buildGroup } from "@server/test/factories";
|
||||
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||
import { getTestServer } from "@server/test/support";
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
afterAll(server.disconnect);
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("#groups.create", () => {
|
||||
it("should create a group", async () => {
|
||||
const name = "hello I am a group";
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
import env from "@server/env";
|
||||
import { IntegrationAuthentication, SearchQuery } from "@server/models";
|
||||
import { buildDocument, buildIntegration } from "@server/test/factories";
|
||||
import { seed, getTestDatabase, getTestServer } from "@server/test/support";
|
||||
import { seed, getTestServer } from "@server/test/support";
|
||||
import * as Slack from "@server/utils/slack";
|
||||
|
||||
jest.mock("../../utils/slack", () => ({
|
||||
post: jest.fn(),
|
||||
}));
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
afterAll(server.disconnect);
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("#hooks.unfurl", () => {
|
||||
it("should return documents", async () => {
|
||||
const { user, document } = await seed();
|
||||
|
||||
@@ -2,8 +2,6 @@ import { getTestServer } from "@server/test/support";
|
||||
|
||||
const server = getTestServer();
|
||||
|
||||
afterAll(server.disconnect);
|
||||
|
||||
describe("POST unknown endpoint", () => {
|
||||
it("should be not found", async () => {
|
||||
const res = await server.post("/api/blah");
|
||||
|
||||
@@ -4,16 +4,10 @@ import {
|
||||
buildUser,
|
||||
buildIntegration,
|
||||
} from "@server/test/factories";
|
||||
import { getTestServer } from "@server/test/support";
|
||||
|
||||
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
afterAll(server.disconnect);
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("#integrations.update", () => {
|
||||
it("should allow updating integration events", async () => {
|
||||
const team = await buildTeam();
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { seed, getTestDatabase, getTestServer } from "@server/test/support";
|
||||
import { seed, getTestServer } from "@server/test/support";
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
afterAll(server.disconnect);
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("#pagination", () => {
|
||||
it("should allow offset and limit", async () => {
|
||||
const { user } = await seed();
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
import { Revision } from "@server/models";
|
||||
import { buildDocument, buildUser } from "@server/test/factories";
|
||||
import { seed, getTestDatabase, getTestServer } from "@server/test/support";
|
||||
import { seed, getTestServer } from "@server/test/support";
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
afterAll(server.disconnect);
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("#revisions.info", () => {
|
||||
it("should return a document revision", async () => {
|
||||
const { user, document } = await seed();
|
||||
|
||||
@@ -8,15 +8,10 @@ import {
|
||||
buildCollection,
|
||||
} from "@server/test/factories";
|
||||
|
||||
import { seed, getTestDatabase, getTestServer } from "@server/test/support";
|
||||
import { seed, getTestServer } from "@server/test/support";
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
afterAll(server.disconnect);
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("#shares.list", () => {
|
||||
it("should only return shares created by user", async () => {
|
||||
const { user, admin, document } = await seed();
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import { buildUser, buildStar, buildDocument } from "@server/test/factories";
|
||||
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||
import { getTestServer } from "@server/test/support";
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
afterAll(server.disconnect);
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("#stars.create", () => {
|
||||
it("should create a star", async () => {
|
||||
const user = await buildUser();
|
||||
|
||||
@@ -4,15 +4,10 @@ import {
|
||||
buildSubscription,
|
||||
buildDocument,
|
||||
} from "@server/test/factories";
|
||||
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||
import { getTestServer } from "@server/test/support";
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
afterAll(server.disconnect);
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("#subscriptions.create", () => {
|
||||
it("should create a subscription", async () => {
|
||||
const user = await buildUser();
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
import { TeamDomain } from "@server/models";
|
||||
import { buildAdmin, buildCollection, buildTeam } from "@server/test/factories";
|
||||
import { seed, getTestDatabase, getTestServer } from "@server/test/support";
|
||||
import { seed, getTestServer } from "@server/test/support";
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
afterAll(server.disconnect);
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("#team.update", () => {
|
||||
it("should update team details", async () => {
|
||||
const { admin } = await seed();
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { buildTeam, buildAdmin, buildUser } from "@server/test/factories";
|
||||
import { seed, getTestDatabase, getTestServer } from "@server/test/support";
|
||||
import { seed, getTestServer } from "@server/test/support";
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
beforeAll(() => {
|
||||
@@ -9,11 +8,8 @@ beforeAll(() => {
|
||||
});
|
||||
afterAll(() => {
|
||||
jest.useRealTimers();
|
||||
server.disconnect();
|
||||
});
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("#users.list", () => {
|
||||
it("should allow filtering by user name", async () => {
|
||||
const user = await buildUser({
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
import { CollectionPermission } from "@shared/types";
|
||||
import { View, CollectionUser } from "@server/models";
|
||||
import { buildUser } from "@server/test/factories";
|
||||
import { seed, getTestDatabase, getTestServer } from "@server/test/support";
|
||||
import { seed, getTestServer } from "@server/test/support";
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
afterAll(server.disconnect);
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("#views.list", () => {
|
||||
it("should return views for a document", async () => {
|
||||
const { user, document } = await seed();
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import { buildUser, buildCollection } from "@server/test/factories";
|
||||
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||
import { getTestServer } from "@server/test/support";
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
afterAll(server.disconnect);
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("auth/redirect", () => {
|
||||
it("should redirect to home", async () => {
|
||||
const user = await buildUser();
|
||||
|
||||
@@ -3,15 +3,10 @@ import SigninEmail from "@server/emails/templates/SigninEmail";
|
||||
import WelcomeEmail from "@server/emails/templates/WelcomeEmail";
|
||||
import env from "@server/env";
|
||||
import { buildUser, buildGuestUser, buildTeam } from "@server/test/factories";
|
||||
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||
import { getTestServer } from "@server/test/support";
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
afterAll(server.disconnect);
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("email", () => {
|
||||
it("should require email param", async () => {
|
||||
const res = await server.post("/auth/email", {
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import { buildShare, buildDocument } from "@server/test/factories";
|
||||
import { getTestDatabase, getTestServer } from "@server/test/support";
|
||||
import { getTestServer } from "@server/test/support";
|
||||
|
||||
const db = getTestDatabase();
|
||||
const server = getTestServer();
|
||||
|
||||
afterAll(server.disconnect);
|
||||
|
||||
beforeEach(db.flush);
|
||||
|
||||
describe("/s/:id", () => {
|
||||
it("should return standard title in html when loading unpublished share", async () => {
|
||||
const share = await buildShare({
|
||||
|
||||
Reference in New Issue
Block a user