chore: Improve perf of server tests (#5785)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { faker } from "@faker-js/faker";
|
||||
import SigninEmail from "@server/emails/templates/SigninEmail";
|
||||
import WelcomeEmail from "@server/emails/templates/WelcomeEmail";
|
||||
import { AuthenticationProvider } from "@server/models";
|
||||
@@ -21,18 +22,15 @@ describe("email", () => {
|
||||
|
||||
it("should respond with redirect location when user is SSO enabled", async () => {
|
||||
const spy = jest.spyOn(WelcomeEmail.prototype, "schedule");
|
||||
const team = await buildTeam({
|
||||
subdomain: "example",
|
||||
});
|
||||
const user = await buildUser({
|
||||
teamId: team.id,
|
||||
});
|
||||
const subdomain = faker.internet.domainWord();
|
||||
const team = await buildTeam({ subdomain });
|
||||
const user = await buildUser({ teamId: team.id });
|
||||
const res = await server.post("/auth/email", {
|
||||
body: {
|
||||
email: user.email,
|
||||
},
|
||||
headers: {
|
||||
host: "example.outline.dev",
|
||||
host: `${subdomain}.outline.dev`,
|
||||
},
|
||||
});
|
||||
const body = await res.json();
|
||||
@@ -44,16 +42,14 @@ describe("email", () => {
|
||||
|
||||
it("should respond with success and email to be sent when user has SSO but disabled", async () => {
|
||||
const spy = jest.spyOn(SigninEmail.prototype, "schedule");
|
||||
const team = await buildTeam({
|
||||
subdomain: "example",
|
||||
});
|
||||
const user = await buildUser({
|
||||
teamId: team.id,
|
||||
});
|
||||
const subdomain = faker.internet.domainWord();
|
||||
const team = await buildTeam({ subdomain });
|
||||
const user = await buildUser({ teamId: team.id });
|
||||
|
||||
// Disable all the auth providers
|
||||
await AuthenticationProvider.update(
|
||||
{
|
||||
teamId: team.id,
|
||||
enabled: false,
|
||||
},
|
||||
{
|
||||
@@ -68,7 +64,7 @@ describe("email", () => {
|
||||
email: user.email,
|
||||
},
|
||||
headers: {
|
||||
host: "example.outline.dev",
|
||||
host: `${subdomain}.outline.dev`,
|
||||
},
|
||||
});
|
||||
const body = await res.json();
|
||||
@@ -81,15 +77,14 @@ describe("email", () => {
|
||||
it("should not send email when user is on another subdomain but respond with success", async () => {
|
||||
const user = await buildUser();
|
||||
const spy = jest.spyOn(WelcomeEmail.prototype, "schedule");
|
||||
await buildTeam({
|
||||
subdomain: "example",
|
||||
});
|
||||
const subdomain = faker.internet.domainWord();
|
||||
await buildTeam({ subdomain });
|
||||
const res = await server.post("/auth/email", {
|
||||
body: {
|
||||
email: user.email,
|
||||
},
|
||||
headers: {
|
||||
host: "example.outline.dev",
|
||||
host: `${subdomain}.outline.dev`,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -102,9 +97,8 @@ describe("email", () => {
|
||||
|
||||
it("should respond with success and email to be sent when user is not SSO enabled", async () => {
|
||||
const spy = jest.spyOn(SigninEmail.prototype, "schedule");
|
||||
const team = await buildTeam({
|
||||
subdomain: "example",
|
||||
});
|
||||
const subdomain = faker.internet.domainWord();
|
||||
const team = await buildTeam({ subdomain });
|
||||
const user = await buildGuestUser({
|
||||
teamId: team.id,
|
||||
});
|
||||
@@ -113,7 +107,7 @@ describe("email", () => {
|
||||
email: user.email,
|
||||
},
|
||||
headers: {
|
||||
host: "example.outline.dev",
|
||||
host: `${subdomain}.outline.dev`,
|
||||
},
|
||||
});
|
||||
const body = await res.json();
|
||||
@@ -125,15 +119,14 @@ describe("email", () => {
|
||||
|
||||
it("should respond with success regardless of whether successful to prevent crawling email logins", async () => {
|
||||
const spy = jest.spyOn(WelcomeEmail.prototype, "schedule");
|
||||
await buildTeam({
|
||||
subdomain: "example",
|
||||
});
|
||||
const subdomain = faker.internet.domainWord();
|
||||
await buildTeam({ subdomain });
|
||||
const res = await server.post("/auth/email", {
|
||||
body: {
|
||||
email: "user@example.com",
|
||||
},
|
||||
headers: {
|
||||
host: "example.outline.dev",
|
||||
host: `${subdomain}.outline.dev`,
|
||||
},
|
||||
});
|
||||
const body = await res.json();
|
||||
@@ -147,8 +140,9 @@ describe("email", () => {
|
||||
it("should default to current subdomain with SSO", async () => {
|
||||
const spy = jest.spyOn(SigninEmail.prototype, "schedule");
|
||||
const email = "sso-user@example.org";
|
||||
const subdomain = faker.internet.domainWord();
|
||||
const team = await buildTeam({
|
||||
subdomain: "example",
|
||||
subdomain,
|
||||
});
|
||||
await buildGuestUser({
|
||||
email,
|
||||
@@ -162,7 +156,7 @@ describe("email", () => {
|
||||
email,
|
||||
},
|
||||
headers: {
|
||||
host: "example.outline.dev",
|
||||
host: `${subdomain}.outline.dev`,
|
||||
},
|
||||
});
|
||||
const body = await res.json();
|
||||
@@ -175,8 +169,9 @@ describe("email", () => {
|
||||
it("should default to current subdomain with guest email", async () => {
|
||||
const spy = jest.spyOn(SigninEmail.prototype, "schedule");
|
||||
const email = "guest-user@example.org";
|
||||
const subdomain = faker.internet.domainWord();
|
||||
const team = await buildTeam({
|
||||
subdomain: "example",
|
||||
subdomain,
|
||||
});
|
||||
await buildUser({
|
||||
email,
|
||||
@@ -190,7 +185,7 @@ describe("email", () => {
|
||||
email,
|
||||
},
|
||||
headers: {
|
||||
host: "example.outline.dev",
|
||||
host: `${subdomain}.outline.dev`,
|
||||
},
|
||||
});
|
||||
const body = await res.json();
|
||||
@@ -203,8 +198,9 @@ describe("email", () => {
|
||||
it("should default to custom domain with SSO", async () => {
|
||||
const spy = jest.spyOn(WelcomeEmail.prototype, "schedule");
|
||||
const email = "sso-user-2@example.org";
|
||||
const domain = faker.internet.domainName();
|
||||
const team = await buildTeam({
|
||||
domain: "docs.mycompany.com",
|
||||
domain,
|
||||
});
|
||||
await buildGuestUser({
|
||||
email,
|
||||
@@ -218,7 +214,7 @@ describe("email", () => {
|
||||
email,
|
||||
},
|
||||
headers: {
|
||||
host: "docs.mycompany.com",
|
||||
host: domain,
|
||||
},
|
||||
});
|
||||
const body = await res.json();
|
||||
@@ -231,8 +227,9 @@ describe("email", () => {
|
||||
it("should default to custom domain with guest email", async () => {
|
||||
const spy = jest.spyOn(SigninEmail.prototype, "schedule");
|
||||
const email = "guest-user-2@example.org";
|
||||
const domain = faker.internet.domainName();
|
||||
const team = await buildTeam({
|
||||
domain: "docs.mycompany.com",
|
||||
domain,
|
||||
});
|
||||
await buildUser({
|
||||
email,
|
||||
@@ -246,7 +243,7 @@ describe("email", () => {
|
||||
email,
|
||||
},
|
||||
headers: {
|
||||
host: "docs.mycompany.com",
|
||||
host: domain,
|
||||
},
|
||||
});
|
||||
const body = await res.json();
|
||||
|
||||
Reference in New Issue
Block a user