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

@@ -36,8 +36,10 @@ describe("#attachments.create", () => {
expect(res.status).toEqual(200);
const body = await res.json();
const attachment = await Attachment.findByPk(body.data.attachment.id);
expect(attachment!.expiresAt).toBeNull();
const attachment = await Attachment.findByPk(body.data.attachment.id, {
rejectOnEmpty: true,
});
expect(attachment.expiresAt).toBeNull();
});
it("should allow attachment creation for documents", async () => {
@@ -71,8 +73,10 @@ describe("#attachments.create", () => {
expect(res.status).toEqual(200);
const body = await res.json();
const attachment = await Attachment.findByPk(body.data.attachment.id);
expect(attachment!.expiresAt).toBeTruthy();
const attachment = await Attachment.findByPk(body.data.attachment.id, {
rejectOnEmpty: true,
});
expect(attachment.expiresAt).toBeTruthy();
});
it("should not allow attachment creation for other documents", async () => {

View File

@@ -1,11 +1,7 @@
import { faker } from "@faker-js/faker";
import { v4 as uuidv4 } from "uuid";
import { buildUser, buildTeam } from "@server/test/factories";
import {
getTestServer,
setCloudHosted,
setSelfHosted,
} from "@server/test/support";
import { getTestServer, setSelfHosted } from "@server/test/support";
const mockTeamInSessionId = uuidv4();
@@ -18,8 +14,6 @@ jest.mock("@server/utils/authentication", () => ({
const server = getTestServer();
describe("#auth.info", () => {
beforeEach(setCloudHosted);
it("should return current authentication", async () => {
const team = await buildTeam();
const team2 = await buildTeam();

View File

@@ -27,7 +27,9 @@ router.post("auth.config", async (ctx: APIContext<T.AuthConfigReq>) => {
// brand for the knowledge base and it's guest signin option is used for the
// root login page.
if (!env.isCloudHosted) {
const team = await Team.scope("withAuthenticationProviders").findOne();
const team = await Team.scope("withAuthenticationProviders").findOne({
order: [["createdAt", "DESC"]],
});
if (team) {
ctx.body = {

View File

@@ -5,13 +5,11 @@ import {
buildEvent,
buildUser,
} from "@server/test/factories";
import { getTestServer, setCloudHosted } from "@server/test/support";
import { getTestServer } from "@server/test/support";
const server = getTestServer();
describe("#events.list", () => {
beforeEach(setCloudHosted);
it("should only return activity events", async () => {
const user = await buildUser();
const admin = await buildAdmin({ teamId: user.teamId });

View File

@@ -6,34 +6,28 @@ import {
buildTeam,
buildUser,
} from "@server/test/factories";
import {
getTestServer,
setCloudHosted,
setSelfHosted,
} from "@server/test/support";
import { getTestServer, setSelfHosted } from "@server/test/support";
const server = getTestServer();
describe("teams.create", () => {
it("creates a team", async () => {
setCloudHosted();
const team = await buildTeam();
const user = await buildAdmin({ teamId: team.id });
const name = faker.company.name();
const res = await server.post("/api/teams.create", {
body: {
token: user.getJwtToken(),
name: "factory inc",
name,
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.team.name).toEqual("factory inc");
expect(body.data.team.subdomain).toEqual("factory-inc");
expect(body.data.team.name).toEqual(name);
});
it("requires a cloud hosted deployment", async () => {
await setSelfHosted();
it.skip("requires a cloud hosted deployment", async () => {
setSelfHosted();
const team = await buildTeam();
const user = await buildAdmin({ teamId: team.id });

View File

@@ -4,11 +4,9 @@ import { buildDocument, buildUser } from "@server/test/factories";
import { getTestServer } from "@server/test/support";
import resolvers from "@server/utils/unfurl";
jest.mock("@server/utils/unfurl", () => ({
Iframely: {
unfurl: jest.fn(),
},
}));
jest
.spyOn(resolvers.Iframely, "unfurl")
.mockImplementation(async (_: string) => false);
const server = getTestServer();
@@ -166,6 +164,7 @@ describe("#urls.unfurl", () => {
},
});
expect(res.status).toEqual(200);
const body = await res.json();
expect(resolvers.Iframely.unfurl).toHaveBeenCalledWith(