share-management.test.js
3,242 bytes
| 1 | import request from "supertest"; |
|---|---|
| 2 | import { afterEach, describe, expect, it } from "vitest"; |
| 3 | import { createShare, makeHarness } from "./helpers.js"; |
| 4 | |
| 5 | describe("share management", () => { |
| 6 | let harness; |
| 7 | afterEach(() => harness.close()); |
| 8 | |
| 9 | it("lists the owner's active snapshot links", async () => { |
| 10 | harness = makeHarness(); |
| 11 | const { id } = await createShare(harness); |
| 12 | |
| 13 | const page = await harness.agent.get("/").expect(200); |
| 14 | expect(page.text).toContain("Shared snapshots"); |
| 15 | expect(page.text).toContain("atlas"); |
| 16 | expect(page.text).toContain(`http://profileshare.test/s/${id}`); |
| 17 | expect(page.text).toContain(`action="/shares/${id}/revoke"`); |
| 18 | expect(page.text).toContain("snapshot-status-active"); |
| 19 | }); |
| 20 | |
| 21 | it("revokes an owned link and removes its stored content", async () => { |
| 22 | harness = makeHarness(); |
| 23 | const { id } = await createShare(harness); |
| 24 | |
| 25 | const response = await harness.agent.post(`/shares/${id}/revoke`).expect(302); |
| 26 | expect(response.headers.location).toBe("/?notice=revoked#shared-links"); |
| 27 | expect(harness.store.getShare(id)).toMatchObject({ |
| 28 | snapshot: null, |
| 29 | revoked_at: expect.any(String), |
| 30 | }); |
| 31 | |
| 32 | const publicPage = await request(harness.app).get(`/s/${id}`).expect(410); |
| 33 | expect(publicPage.text).toContain("The owner revoked this snapshot link."); |
| 34 | expect(publicPage.text).not.toContain("atlas"); |
| 35 | |
| 36 | const dashboard = await harness.agent.get("/?notice=revoked").expect(200); |
| 37 | expect(dashboard.text).toContain("Snapshot content removed"); |
| 38 | expect(dashboard.text).toContain("snapshot-status-revoked"); |
| 39 | expect(dashboard.text).not.toContain(`action="/shares/${id}/revoke"`); |
| 40 | }); |
| 41 | |
| 42 | it("does not allow anonymous or different owners to revoke a link", async () => { |
| 43 | harness = makeHarness(); |
| 44 | const { id } = await createShare(harness); |
| 45 | |
| 46 | await request(harness.app).post(`/shares/${id}/revoke`).expect(401); |
| 47 | expect(harness.store.getShare(id).snapshot).not.toBeNull(); |
| 48 | |
| 49 | harness.store.createShare({ |
| 50 | id: "another-owner-share", |
| 51 | ownerId: 999, |
| 52 | createdAt: "2026-07-23T12:00:00.000Z", |
| 53 | expiresAt: "2026-07-30T12:00:00.000Z", |
| 54 | snapshot: { profile: {}, repositories: [] }, |
| 55 | }); |
| 56 | await harness.agent.post("/shares/another-owner-share/revoke").expect(404); |
| 57 | expect(harness.store.getShare("another-owner-share").snapshot).not.toBeNull(); |
| 58 | }); |
| 59 | |
| 60 | it("shows expired links without active controls", async () => { |
| 61 | harness = makeHarness(); |
| 62 | const { id } = await createShare(harness, [101], 1); |
| 63 | harness.setNow("2026-07-24T12:00:00.000Z"); |
| 64 | |
| 65 | const page = await harness.agent.get("/").expect(200); |
| 66 | expect(page.text).toContain("snapshot-status-expired"); |
| 67 | expect(page.text).not.toContain(`action="/shares/${id}/revoke"`); |
| 68 | }); |
| 69 | |
| 70 | it("keeps existing links manageable when GitHub is unavailable", async () => { |
| 71 | harness = makeHarness(); |
| 72 | const { id } = await createShare(harness); |
| 73 | harness.github.listRepositories = async () => { |
| 74 | throw new Error("network detail"); |
| 75 | }; |
| 76 | |
| 77 | const page = await harness.agent.get("/").expect(200); |
| 78 | expect(page.text).toContain("GitHub repositories could not be loaded."); |
| 79 | expect(page.text).toContain(`action="/shares/${id}/revoke"`); |
| 80 | }); |
| 81 | }); |
| 82 | |