chore: More flakey test improvements (#5801)

This commit is contained in:
Tom Moor
2023-09-09 18:30:19 -04:00
committed by GitHub
parent 7270e65f0c
commit 80ef0a38d6
37 changed files with 245 additions and 210 deletions

View File

@@ -5,18 +5,16 @@ 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 { setCloudHosted, setSelfHosted } from "@server/test/support";
import { setSelfHosted } from "@server/test/support";
import accountProvisioner from "./accountProvisioner";
describe("accountProvisioner", () => {
const ip = "127.0.0.1";
describe("hosted", () => {
beforeEach(setCloudHosted);
it("should create a new user and team", async () => {
const spy = jest.spyOn(WelcomeEmail.prototype, "schedule");
const email = faker.internet.email();
const email = faker.internet.email().toLowerCase();
const { user, team, isNewTeam, isNewUser } = await accountProvisioner({
ip,
user: {
@@ -69,7 +67,7 @@ describe("accountProvisioner", () => {
});
const authentications = await existing.$get("authentications");
const authentication = authentications[0];
const newEmail = faker.internet.email();
const newEmail = faker.internet.email().toLowerCase();
const { user, isNewUser, isNewTeam } = await accountProvisioner({
ip,
user: {
@@ -104,14 +102,15 @@ describe("accountProvisioner", () => {
spy.mockRestore();
});
it.skip("should allow authentication by email matching", async () => {
it("should allow authentication by email matching", async () => {
const subdomain = faker.internet.domainWord();
const existingTeam = await buildTeam({
subdomain,
});
const providers = await existingTeam.$get("authenticationProviders");
const authenticationProvider = providers[0];
const email = faker.internet.email();
const email = faker.internet.email().toLowerCase();
const userWithoutAuth = await buildUser({
email,
teamId: existingTeam.id,
@@ -196,7 +195,7 @@ describe("accountProvisioner", () => {
const admin = await buildAdmin({ teamId: existingTeam.id });
const providers = await existingTeam.$get("authenticationProviders");
const authenticationProvider = providers[0];
const email = faker.internet.email();
const email = faker.internet.email().toLowerCase();
await TeamDomain.create({
teamId: existingTeam.id,
@@ -299,7 +298,7 @@ describe("accountProvisioner", () => {
"authenticationProviders"
);
const authenticationProvider = authenticationProviders[0];
const email = faker.internet.email();
const email = faker.internet.email().toLowerCase();
const { user, isNewUser } = await accountProvisioner({
ip,
user: {

View File

@@ -1,5 +1,5 @@
import { Event } from "@server/models";
import { buildDocument, buildUser } from "@server/test/factories";
import { findLatestEvent } from "@server/test/support";
import commentCreator from "./commentCreator";
describe("commentCreator", () => {
@@ -32,7 +32,9 @@ describe("commentCreator", () => {
ip,
});
const event = await findLatestEvent();
const event = await Event.findLatest({
teamId: user.teamId,
});
expect(comment.documentId).toEqual(document.id);
expect(comment.createdById).toEqual(user.id);
expect(event!.name).toEqual("comments.create");

View File

@@ -1,6 +1,5 @@
import { Comment } from "@server/models";
import { Comment, Event } from "@server/models";
import { buildDocument, buildUser } from "@server/test/factories";
import { findLatestEvent } from "@server/test/support";
import commentDestroyer from "./commentDestroyer";
describe("commentDestroyer", () => {
@@ -46,7 +45,9 @@ describe("commentDestroyer", () => {
});
expect(count).toEqual(0);
const event = await findLatestEvent();
const event = await Event.findLatest({
teamId: user.teamId,
});
expect(event!.name).toEqual("comments.delete");
expect(event!.modelId).toEqual(comment.id);
});

View File

@@ -1,6 +1,6 @@
import { Event } from "@server/models";
import { sequelize } from "@server/storage/database";
import { buildDocument, buildUser } from "@server/test/factories";
import { findLatestEvent } from "@server/test/support";
import documentUpdater from "./documentUpdater";
describe("documentUpdater", () => {
@@ -22,7 +22,9 @@ describe("documentUpdater", () => {
})
);
const event = await findLatestEvent();
const event = await Event.findLatest({
teamId: user.teamId,
});
expect(document.lastModifiedById).toEqual(user.id);
expect(event!.name).toEqual("documents.update");
expect(event!.documentId).toEqual(document.id);

View File

@@ -1,4 +1,5 @@
import { NotificationEventType } from "@shared/types";
import { Event } from "@server/models";
import { sequelize } from "@server/storage/database";
import {
buildUser,
@@ -6,7 +7,6 @@ import {
buildDocument,
buildCollection,
} from "@server/test/factories";
import { findLatestEvent } from "@server/test/support";
import notificationUpdater from "./notificationUpdater";
describe("notificationUpdater", () => {
@@ -46,7 +46,9 @@ describe("notificationUpdater", () => {
transaction,
})
);
const event = await findLatestEvent();
const event = await Event.findLatest({
teamId: user.teamId,
});
expect(notification.viewedAt).not.toBe(null);
expect(notification.archivedAt).toBe(null);
@@ -89,7 +91,9 @@ describe("notificationUpdater", () => {
transaction,
})
);
const event = await findLatestEvent();
const event = await Event.findLatest({
teamId: user.teamId,
});
expect(notification.viewedAt).toBe(null);
expect(notification.archivedAt).toBe(null);
@@ -131,7 +135,9 @@ describe("notificationUpdater", () => {
transaction,
})
);
const event = await findLatestEvent();
const event = await Event.findLatest({
teamId: user.teamId,
});
expect(notification.viewedAt).toBe(null);
expect(notification.archivedAt).not.toBe(null);
@@ -174,7 +180,9 @@ describe("notificationUpdater", () => {
transaction,
})
);
const event = await findLatestEvent();
const event = await Event.findLatest({
teamId: user.teamId,
});
expect(notification.viewedAt).toBe(null);
expect(notification.archivedAt).toBeNull();

View File

@@ -1,5 +1,5 @@
import { Event } from "@server/models";
import { buildDocument, buildUser } from "@server/test/factories";
import { findLatestEvent } from "@server/test/support";
import pinCreator from "./pinCreator";
describe("pinCreator", () => {
@@ -18,7 +18,9 @@ describe("pinCreator", () => {
ip,
});
const event = await findLatestEvent();
const event = await Event.findLatest({
teamId: user.teamId,
});
expect(pin.documentId).toEqual(document.id);
expect(pin.collectionId).toEqual(null);
expect(pin.createdById).toEqual(user.id);
@@ -41,7 +43,9 @@ describe("pinCreator", () => {
ip,
});
const event = await findLatestEvent();
const event = await Event.findLatest({
teamId: user.teamId,
});
expect(pin.documentId).toEqual(document.id);
expect(pin.collectionId).toEqual(document.collectionId);
expect(pin.createdById).toEqual(user.id);

View File

@@ -1,6 +1,5 @@
import { Pin } from "@server/models";
import { Event, Pin } from "@server/models";
import { buildDocument, buildUser } from "@server/test/factories";
import { findLatestEvent } from "@server/test/support";
import pinDestroyer from "./pinDestroyer";
describe("pinCreator", () => {
@@ -34,7 +33,9 @@ describe("pinCreator", () => {
});
expect(count).toEqual(0);
const event = await findLatestEvent();
const event = await Event.findLatest({
teamId: user.teamId,
});
expect(event!.name).toEqual("pins.delete");
expect(event!.modelId).toEqual(pin.id);
});

View File

@@ -1,5 +1,5 @@
import { Event } from "@server/models";
import { buildDocument, buildUser } from "@server/test/factories";
import { findLatestEvent } from "@server/test/support";
import revisionCreator from "./revisionCreator";
describe("revisionCreator", () => {
@@ -16,7 +16,7 @@ describe("revisionCreator", () => {
user,
ip,
});
const event = await findLatestEvent({
const event = await Event.findLatest({
teamId: user.teamId,
});
expect(revision.documentId).toEqual(document.id);

View File

@@ -1,7 +1,6 @@
import { Star, Event } from "@server/models";
import { sequelize } from "@server/storage/database";
import { buildDocument, buildUser } from "@server/test/factories";
import { findLatestEvent } from "@server/test/support";
import starCreator from "./starCreator";
describe("starCreator", () => {
@@ -23,7 +22,9 @@ describe("starCreator", () => {
})
);
const event = await findLatestEvent();
const event = await Event.findLatest({
teamId: user.teamId,
});
expect(star.documentId).toEqual(document.id);
expect(star.userId).toEqual(user.id);
expect(star.index).toEqual("P");

View File

@@ -1,6 +1,5 @@
import { Star } from "@server/models";
import { Event, Star } from "@server/models";
import { buildDocument, buildUser } from "@server/test/factories";
import { findLatestEvent } from "@server/test/support";
import starDestroyer from "./starDestroyer";
describe("starDestroyer", () => {
@@ -34,7 +33,9 @@ describe("starDestroyer", () => {
});
expect(count).toEqual(0);
const event = await findLatestEvent();
const event = await Event.findLatest({
teamId: user.teamId,
});
expect(event!.name).toEqual("stars.delete");
expect(event!.modelId).toEqual(star.id);
});

View File

@@ -1,6 +1,5 @@
import { Star } from "@server/models";
import { Event, Star } from "@server/models";
import { buildDocument, buildUser } from "@server/test/factories";
import { findLatestEvent } from "@server/test/support";
import starUpdater from "./starUpdater";
describe("starUpdater", () => {
@@ -28,7 +27,9 @@ describe("starUpdater", () => {
ip,
});
const event = await findLatestEvent();
const event = await Event.findLatest({
teamId: user.teamId,
});
expect(star.documentId).toEqual(document.id);
expect(star.userId).toEqual(user.id);
expect(star.index).toEqual("h");

View File

@@ -1,15 +1,13 @@
import { faker } from "@faker-js/faker";
import TeamDomain from "@server/models/TeamDomain";
import { buildTeam, buildUser } from "@server/test/factories";
import { setCloudHosted, setSelfHosted } from "@server/test/support";
import { setSelfHosted } from "@server/test/support";
import teamProvisioner from "./teamProvisioner";
describe("teamProvisioner", () => {
const ip = "127.0.0.1";
describe("hosted", () => {
beforeEach(setCloudHosted);
it("should create team and authentication provider", async () => {
const subdomain = faker.internet.domainWord();
const result = await teamProvisioner({