chore: Reduce test boilerplate (#4300)

* chore: Reduce test boilerplate

* mo
This commit is contained in:
Tom Moor
2022-10-15 22:40:21 -04:00
committed by GitHub
parent 1915a453db
commit 1fbc000e03
72 changed files with 134 additions and 439 deletions

View File

@@ -7,17 +7,14 @@ import {
buildTeam,
buildDocument,
} from "@server/test/factories";
import { getTestDatabase, seed } from "@server/test/support";
import { setupTestDatabase, seed } from "@server/test/support";
import slugify from "@server/utils/slugify";
import Collection from "./Collection";
import Document from "./Document";
const db = getTestDatabase();
setupTestDatabase();
afterAll(db.disconnect);
beforeEach(async () => {
await db.flush();
beforeEach(() => {
jest.resetAllMocks();
});

View File

@@ -6,15 +6,12 @@ import {
buildUser,
buildShare,
} from "@server/test/factories";
import { getTestDatabase, seed } from "@server/test/support";
import { setupTestDatabase, seed } from "@server/test/support";
import slugify from "@server/utils/slugify";
const db = getTestDatabase();
setupTestDatabase();
afterAll(db.disconnect);
beforeEach(async () => {
await db.flush();
beforeEach(() => {
jest.resetAllMocks();
});

View File

@@ -1,14 +1,11 @@
import { buildUser, buildGroup, buildCollection } from "@server/test/factories";
import { getTestDatabase } from "@server/test/support";
import { setupTestDatabase } from "@server/test/support";
import CollectionGroup from "./CollectionGroup";
import GroupUser from "./GroupUser";
const db = getTestDatabase();
afterAll(db.disconnect);
setupTestDatabase();
beforeEach(async () => {
await db.flush();
jest.resetAllMocks();
});

View File

@@ -1,15 +1,8 @@
import { buildDocument } from "@server/test/factories";
import { getTestDatabase } from "@server/test/support";
import { setupTestDatabase } from "@server/test/support";
import Revision from "./Revision";
const db = getTestDatabase();
afterAll(db.disconnect);
beforeEach(async () => {
await db.flush();
jest.resetAllMocks();
});
setupTestDatabase();
describe("#findLatest", () => {
test("should return latest revision", async () => {

View File

@@ -1,14 +1,7 @@
import { buildTeam, buildCollection } from "@server/test/factories";
import { getTestDatabase } from "@server/test/support";
import { setupTestDatabase } from "@server/test/support";
const db = getTestDatabase();
afterAll(db.disconnect);
beforeEach(async () => {
await db.flush();
jest.resetAllMocks();
});
setupTestDatabase();
describe("collectionIds", () => {
it("should return non-private collection ids", async () => {

View File

@@ -1,16 +1,9 @@
import env from "@server/env";
import { buildAdmin, buildTeam } from "@server/test/factories";
import { getTestDatabase } from "@server/test/support";
import { setupTestDatabase } from "@server/test/support";
import TeamDomain from "./TeamDomain";
const db = getTestDatabase();
afterAll(db.disconnect);
beforeEach(async () => {
await db.flush();
jest.resetAllMocks();
});
setupTestDatabase();
describe("team domain model", () => {
describe("create", () => {

View File

@@ -1,10 +1,10 @@
import { CollectionPermission } from "@shared/types";
import { buildUser, buildTeam, buildCollection } from "@server/test/factories";
import { getTestDatabase } from "@server/test/support";
import { setupTestDatabase } from "@server/test/support";
import CollectionUser from "./CollectionUser";
import UserAuthentication from "./UserAuthentication";
const db = getTestDatabase();
setupTestDatabase();
beforeAll(() => {
jest.useFakeTimers().setSystemTime(new Date("2018-01-02T00:00:00.000Z"));
@@ -12,11 +12,8 @@ beforeAll(() => {
afterAll(() => {
jest.useRealTimers();
db.disconnect();
});
beforeEach(db.flush);
describe("user model", () => {
describe("destroy", () => {
it("should delete user authentications", async () => {