Files
outline/server/models/Team.test.ts
Copilotandtommoor df5dd0b98d Fix custom team logo not appearing in link previews for public shares (#11872)
* Initial plan

* fix: resolve team avatar to signed URL for public share link previews

Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>
Agent-Logs-Url: https://github.com/outline/outline/sessions/3632734e-1bb5-4705-bdcd-a2ccbb211af8

* refactor: move avatar URL resolution to Team.publicAvatarUrl()

Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>
Agent-Logs-Url: https://github.com/outline/outline/sessions/a2191be3-0533-459a-8366-602bb798a60e

* test: add Team.publicAvatarUrl model tests; update JSDoc

Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>
Agent-Logs-Url: https://github.com/outline/outline/sessions/7609501c-a4d1-44ea-a7bf-fa6fd8e7c999

* test: fix Team.publicAvatarUrl tests to use actual attachment URLs

Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>
Agent-Logs-Url: https://github.com/outline/outline/sessions/0a768f8b-0dd8-4e7a-a50d-873af58aab28

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>
2026-03-27 19:55:15 -04:00

93 lines
3.0 KiB
TypeScript

import { randomUUID } from "node:crypto";
import { buildTeam, buildCollection, buildAttachment } from "@server/test/factories";
describe("Team", () => {
describe("collectionIds", () => {
it("should return non-private collection ids", async () => {
const team = await buildTeam();
const collection = await buildCollection({
teamId: team.id,
});
// build a collection in another team
await buildCollection();
// build a private collection
await buildCollection({
teamId: team.id,
permission: null,
});
const response = await team.collectionIds();
expect(response.length).toEqual(1);
expect(response[0]).toEqual(collection.id);
});
});
describe("previousSubdomains", () => {
it("should list the previous subdomains", async () => {
const team = await buildTeam({
subdomain: "example",
});
const subdomain = "updated";
await team.update({ subdomain });
expect(team.subdomain).toEqual(subdomain);
expect(team.previousSubdomains?.length).toEqual(1);
expect(team.previousSubdomains?.[0]).toEqual("example");
const subdomain2 = "another";
await team.update({ subdomain: subdomain2 });
expect(team.subdomain).toEqual(subdomain2);
expect(team.previousSubdomains?.length).toEqual(2);
expect(team.previousSubdomains?.[0]).toEqual("example");
expect(team.previousSubdomains?.[1]).toEqual(subdomain);
});
});
describe("publicAvatarUrl", () => {
it("should return null when no avatarUrl is set", async () => {
const team = await buildTeam({ avatarUrl: null });
const result = await team.publicAvatarUrl();
expect(result).toBeNull();
});
it("should return external URL unchanged", async () => {
const url = "https://example.com/logo.png";
const team = await buildTeam({ avatarUrl: url });
const result = await team.publicAvatarUrl();
expect(result).toEqual(url);
});
it("should return signed URL for private-bucket attachment redirect", async () => {
const team = await buildTeam();
const attachment = await buildAttachment({
teamId: team.id,
acl: "private",
});
await team.update({
avatarUrl: `/api/attachments.redirect?id=${attachment.id}`,
});
const result = await team.publicAvatarUrl();
expect(result).toEqual(await attachment.signedUrl);
});
it("should return canonical URL for public-bucket attachment redirect", async () => {
const team = await buildTeam();
const id = randomUUID();
const attachment = await buildAttachment({
id,
teamId: team.id,
key: `avatars/${team.id}/${id}/logo.png`,
acl: "public-read",
});
await team.update({
avatarUrl: `/api/attachments.redirect?id=${attachment.id}`,
});
const result = await team.publicAvatarUrl();
expect(result).toEqual(attachment.canonicalUrl);
});
});
});