mirror of
https://github.com/outline/outline.git
synced 2026-11-25 23:24:06 +03:00
* chore: Rename APIContext to Context and flatten its fields Auth and transaction now live directly on the context instead of in ctx.state and a nested ctx.context, and model helpers read them directly. APIContext remains as a deprecated alias. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf * chore: Remove deprecated APIContext alias Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf * fix: Read auth from context in OAuth provider callbacks Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf * chore: Add withUser and withTransaction context helpers Replaces manual createContext rebuilds that copy fields from an existing context. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf * chore: Remove arbitrary property access from Koa context types AppContext and Context no longer inherit the any index signature from Koa's DefaultContext, custom fields are declared explicitly, and importing Koa's loose Context type is disallowed by lint. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf --------- Co-authored-by: Claude <noreply@anthropic.com>
147 lines
3.7 KiB
TypeScript
147 lines
3.7 KiB
TypeScript
import { faker } from "@faker-js/faker";
|
|
import { UserRole } from "@shared/types";
|
|
import { buildTeam, buildUser } from "@server/test/factories";
|
|
import userInviter from "./userInviter";
|
|
import { withContext } from "@server/test/support";
|
|
import { TeamDomain } from "@server/models";
|
|
|
|
describe("userInviter", () => {
|
|
it("should return sent invites", async () => {
|
|
const user = await buildUser();
|
|
const response = await withContext(user, (ctx) =>
|
|
userInviter(ctx, {
|
|
invites: [
|
|
{
|
|
role: UserRole.Member,
|
|
email: faker.internet.email(),
|
|
name: "Test",
|
|
},
|
|
],
|
|
})
|
|
);
|
|
expect(response.sent.length).toEqual(1);
|
|
});
|
|
|
|
it("should filter empty invites", async () => {
|
|
const user = await buildUser();
|
|
const response = await withContext(user, (ctx) =>
|
|
userInviter(ctx, {
|
|
invites: [
|
|
{
|
|
role: UserRole.Member,
|
|
email: " ",
|
|
name: "Test",
|
|
},
|
|
],
|
|
})
|
|
);
|
|
expect(response.sent.length).toEqual(0);
|
|
});
|
|
|
|
it("should error on non allowed domains", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
|
|
await TeamDomain.create({
|
|
teamId: team.id,
|
|
name: faker.internet.domainName(),
|
|
createdById: user.id,
|
|
});
|
|
|
|
await withContext(user, (ctx) =>
|
|
expect(
|
|
userInviter(ctx, {
|
|
invites: [
|
|
{
|
|
role: UserRole.Member,
|
|
email: "test@example.com",
|
|
name: "Test",
|
|
},
|
|
],
|
|
})
|
|
).rejects.toThrow("The domain is not allowed for this workspace")
|
|
);
|
|
});
|
|
|
|
it("should allow invites for allowed domains", async () => {
|
|
const team = await buildTeam();
|
|
const user = await buildUser({ teamId: team.id });
|
|
const allowedDomain = "google.com";
|
|
|
|
await TeamDomain.create({
|
|
teamId: team.id,
|
|
name: allowedDomain,
|
|
createdById: user.id,
|
|
});
|
|
|
|
const response = await withContext(user, (ctx) =>
|
|
userInviter(ctx, {
|
|
invites: [
|
|
{
|
|
role: UserRole.Member,
|
|
email: `test@${allowedDomain}`,
|
|
name: "Test User",
|
|
},
|
|
],
|
|
})
|
|
);
|
|
|
|
expect(response.sent.length).toEqual(1);
|
|
expect(response.sent[0].email).toEqual(`test@${allowedDomain}`);
|
|
});
|
|
|
|
it("should filter obviously bunk emails", async () => {
|
|
const user = await buildUser();
|
|
const response = await withContext(user, (ctx) =>
|
|
userInviter(ctx, {
|
|
invites: [
|
|
{
|
|
role: UserRole.Member,
|
|
email: "notanemail",
|
|
name: "Test",
|
|
},
|
|
],
|
|
})
|
|
);
|
|
expect(response.sent.length).toEqual(0);
|
|
});
|
|
|
|
it("should not send duplicates", async () => {
|
|
const user = await buildUser();
|
|
const response = await withContext(user, (ctx) =>
|
|
userInviter(ctx, {
|
|
invites: [
|
|
{
|
|
role: UserRole.Member,
|
|
email: "the@same.com",
|
|
name: "Test",
|
|
},
|
|
{
|
|
role: UserRole.Member,
|
|
email: "the@SAME.COM",
|
|
name: "Test",
|
|
},
|
|
],
|
|
})
|
|
);
|
|
expect(response.sent.length).toEqual(1);
|
|
});
|
|
|
|
it("should not send invites to existing team members", async () => {
|
|
const email = faker.internet.email().toLowerCase();
|
|
const user = await buildUser({ email });
|
|
const response = await withContext(user, (ctx) =>
|
|
userInviter(ctx, {
|
|
invites: [
|
|
{
|
|
role: UserRole.Member,
|
|
email,
|
|
name: user.name,
|
|
},
|
|
],
|
|
})
|
|
);
|
|
expect(response.sent.length).toEqual(0);
|
|
});
|
|
});
|