chore: More flakey test improvements (#5801)
This commit is contained in:
@@ -18,6 +18,8 @@ env.OIDC_USERINFO_URI = "http://localhost/userinfo";
|
||||
|
||||
env.RATE_LIMITER_ENABLED = false;
|
||||
|
||||
env.IFRAMELY_API_KEY = "123";
|
||||
|
||||
if (process.env.DATABASE_URL_TEST) {
|
||||
env.DATABASE_URL = process.env.DATABASE_URL_TEST;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { faker } from "@faker-js/faker";
|
||||
import isNil from "lodash/isNil";
|
||||
import isNull from "lodash/isNull";
|
||||
import randomstring from "randomstring";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import {
|
||||
CollectionPermission,
|
||||
@@ -23,7 +24,6 @@ import {
|
||||
Attachment,
|
||||
IntegrationAuthentication,
|
||||
Integration,
|
||||
AuthenticationProvider,
|
||||
FileOperation,
|
||||
WebhookSubscription,
|
||||
WebhookDelivery,
|
||||
@@ -77,7 +77,9 @@ export async function buildStar(overrides: Partial<Star> = {}) {
|
||||
let user;
|
||||
|
||||
if (overrides.userId) {
|
||||
user = await User.findByPk(overrides.userId);
|
||||
user = await User.findByPk(overrides.userId, {
|
||||
rejectOnEmpty: true,
|
||||
});
|
||||
} else {
|
||||
user = await buildUser();
|
||||
overrides.userId = user.id;
|
||||
@@ -86,7 +88,7 @@ export async function buildStar(overrides: Partial<Star> = {}) {
|
||||
if (!overrides.documentId) {
|
||||
const document = await buildDocument({
|
||||
createdById: overrides.userId,
|
||||
teamId: user?.teamId,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
overrides.documentId = document.id;
|
||||
}
|
||||
@@ -101,7 +103,9 @@ export async function buildSubscription(overrides: Partial<Subscription> = {}) {
|
||||
let user;
|
||||
|
||||
if (overrides.userId) {
|
||||
user = await User.findByPk(overrides.userId);
|
||||
user = await User.findByPk(overrides.userId, {
|
||||
rejectOnEmpty: true,
|
||||
});
|
||||
} else {
|
||||
user = await buildUser();
|
||||
overrides.userId = user.id;
|
||||
@@ -110,7 +114,7 @@ export async function buildSubscription(overrides: Partial<Subscription> = {}) {
|
||||
if (!overrides.documentId) {
|
||||
const document = await buildDocument({
|
||||
createdById: overrides.userId,
|
||||
teamId: user?.teamId,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
overrides.documentId = document.id;
|
||||
}
|
||||
@@ -129,7 +133,7 @@ export function buildTeam(overrides: Record<string, any> = {}) {
|
||||
authenticationProviders: [
|
||||
{
|
||||
name: "slack",
|
||||
providerId: uuidv4().replace(/-/g, ""),
|
||||
providerId: randomstring.generate(32),
|
||||
},
|
||||
],
|
||||
...overrides,
|
||||
@@ -170,14 +174,14 @@ export async function buildUser(overrides: Partial<User> = {}) {
|
||||
team = await buildTeam();
|
||||
overrides.teamId = team.id;
|
||||
} else {
|
||||
team = await Team.findByPk(overrides.teamId);
|
||||
team = await Team.findByPk(overrides.teamId, {
|
||||
include: "authenticationProviders",
|
||||
rejectOnEmpty: true,
|
||||
paranoid: false,
|
||||
});
|
||||
}
|
||||
|
||||
const authenticationProvider = await AuthenticationProvider.findOne({
|
||||
where: {
|
||||
teamId: overrides.teamId,
|
||||
},
|
||||
});
|
||||
const authenticationProvider = team.authenticationProviders[0];
|
||||
const user = await User.create(
|
||||
{
|
||||
email: faker.internet.email().toLowerCase(),
|
||||
@@ -185,12 +189,14 @@ export async function buildUser(overrides: Partial<User> = {}) {
|
||||
createdAt: new Date("2018-01-01T00:00:00.000Z"),
|
||||
updatedAt: new Date("2018-01-02T00:00:00.000Z"),
|
||||
lastActiveAt: new Date("2018-01-03T00:00:00.000Z"),
|
||||
authentications: [
|
||||
{
|
||||
authenticationProviderId: authenticationProvider!.id,
|
||||
providerId: uuidv4().replace(/-/g, ""),
|
||||
},
|
||||
],
|
||||
authentications: authenticationProvider
|
||||
? [
|
||||
{
|
||||
authenticationProviderId: authenticationProvider.id,
|
||||
providerId: randomstring.generate(32),
|
||||
},
|
||||
]
|
||||
: [],
|
||||
...overrides,
|
||||
},
|
||||
{
|
||||
@@ -244,7 +250,7 @@ export async function buildIntegration(overrides: Partial<Integration> = {}) {
|
||||
service: IntegrationService.Slack,
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
token: "fake-access-token",
|
||||
token: randomstring.generate(32),
|
||||
scopes: ["example", "scopes", "here"],
|
||||
});
|
||||
return Integration.create({
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import sharedEnv from "@shared/env";
|
||||
import env from "@server/env";
|
||||
import Redis from "@server/storage/redis";
|
||||
|
||||
require("@server/storage/database");
|
||||
@@ -22,3 +24,7 @@ jest.mock("aws-sdk", () => {
|
||||
});
|
||||
|
||||
afterAll(() => Redis.defaultClient.disconnect());
|
||||
|
||||
beforeEach(() => {
|
||||
env.URL = sharedEnv.URL = "https://app.outline.dev";
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { faker } from "@faker-js/faker";
|
||||
import TestServer from "fetch-test-server";
|
||||
import { WhereOptions } from "sequelize";
|
||||
import sharedEnv from "@shared/env";
|
||||
import env from "@server/env";
|
||||
import { Event, Team } from "@server/models";
|
||||
import onerror from "@server/onerror";
|
||||
import webService from "@server/services/web";
|
||||
import { sequelize } from "@server/storage/database";
|
||||
@@ -18,32 +17,13 @@ export function getTestServer() {
|
||||
};
|
||||
|
||||
afterAll(server.disconnect);
|
||||
return server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the environment to be cloud hosted.
|
||||
*/
|
||||
export function setCloudHosted() {
|
||||
return (env.URL = sharedEnv.URL = "https://app.outline.dev");
|
||||
return server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the environment to be self hosted.
|
||||
*/
|
||||
export async function setSelfHosted() {
|
||||
env.URL = sharedEnv.URL = "https://wiki.example.com";
|
||||
|
||||
// Self hosted deployments only have one team, to ensure behavior is correct
|
||||
// we need to delete all teams before running tests
|
||||
return Team.destroy({
|
||||
truncate: true,
|
||||
});
|
||||
}
|
||||
|
||||
export function findLatestEvent(where: WhereOptions<Event> = {}) {
|
||||
return Event.findOne({
|
||||
where,
|
||||
order: [["createdAt", "DESC"]],
|
||||
});
|
||||
export function setSelfHosted() {
|
||||
env.URL = sharedEnv.URL = `https://${faker.internet.domainName()}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user