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

@@ -1,4 +1,4 @@
import type { SaveOptions } from "sequelize";
import type { SaveOptions, WhereOptions } from "sequelize";
import {
ForeignKey,
AfterSave,
@@ -111,6 +111,19 @@ class Event extends IdModel {
);
}
/**
* Find the latest event matching the where clause
*
* @param where The options to match against
* @returns A promise resolving to the latest event or null
*/
static findLatest(where: WhereOptions) {
return this.findOne({
where,
order: [["createdAt", "DESC"]],
});
}
static ACTIVITY_EVENTS: TEvent["name"][] = [
"collections.create",
"collections.delete",

View File

@@ -1,10 +1,7 @@
import { buildAdmin, buildTeam } from "@server/test/factories";
import { setCloudHosted } from "@server/test/support";
import TeamDomain from "./TeamDomain";
describe("team domain model", () => {
beforeEach(setCloudHosted);
describe("create", () => {
it("should allow creation of domains", async () => {
const team = await buildTeam();

View File

@@ -1,3 +1,4 @@
import { faker } from "@faker-js/faker";
import { CollectionPermission } from "@shared/types";
import { buildUser, buildTeam, buildCollection } from "@server/test/factories";
import CollectionUser from "./CollectionUser";
@@ -42,10 +43,11 @@ describe("user model", () => {
describe("availableTeams", () => {
it("should return teams where another user with the same email exists", async () => {
const email = faker.internet.email().toLowerCase();
const user = await buildUser({
email: "user-available-teams@example.com",
email,
});
const anotherUser = await buildUser({ email: user.email });
const anotherUser = await buildUser({ email });
const response = await user.availableTeams();
expect(response.length).toEqual(2);