profileShare

rasmusjy / profileshare

Read-only snapshot

No repository description.

main default branch 54 files Expires Sep 13, 2026, 9:06 AM
refs.test.js 4,125 bytes
1 import { afterEach, describe, expect, it } from "vitest";
2 import { authenticate, createShare, makeHarness } from "./helpers.js";
3
4 describe("branches and tags", () => {
5 let harness;
6 afterEach(() => harness.close());
7
8 it("switches between frozen branch and tag contents", async () => {
9 harness = makeHarness();
10 const { id } = await createShare(harness);
11
12 const defaultView = await harness.agent.get(`/s/${id}/repositories/101`).expect(200);
13 expect(defaultView.text).toContain("Switch branches or tags");
14 expect(defaultView.text).toContain("review-notes");
15 expect(defaultView.text).toContain("v1.0.0");
16
17 const branchView = await harness.agent
18 .get(`/s/${id}/repositories/101?ref=review-notes&refType=branch`)
19 .expect(200);
20 expect(branchView.text).toContain("path=src");
21 expect(branchView.text).toContain("Add atlas review notes");
22 expect(branchView.text).toContain('name="ref" value="review-notes"');
23
24 const branchFolder = await harness.agent
25 .get(`/s/${id}/repositories/101?ref=review-notes&refType=branch&path=src`)
26 .expect(200);
27 expect(branchFolder.text).toContain("preview.js");
28 expect(branchFolder.text).not.toContain(">index.js</strong>");
29 expect(branchFolder.text).toContain("?ref=review-notes&amp;refType=branch&amp;path=src&amp;file=src%2Fpreview.js");
30
31 const tagView = await harness.agent
32 .get(`/s/${id}/repositories/101?ref=v1.0.0&refType=tag`)
33 .expect(200);
34 expect(tagView.text).toContain("CHANGELOG.md");
35 expect(tagView.text).toContain("Release atlas v1.0.0");
36 expect(tagView.text).not.toContain(">preview.js</strong>");
37 });
38
39 it("keeps file, commit, and search navigation on the selected branch", async () => {
40 harness = makeHarness();
41 const { id } = await createShare(harness);
42
43 const file = await harness.agent
44 .get(`/s/${id}/repositories/101?ref=review-notes&refType=branch&file=src%2Fpreview.js`)
45 .expect(200);
46 expect(file.text).toContain('export const branch = &#34;review-notes&#34;;');
47 expect(file.text).toContain("?ref=review-notes&amp;refType=branch&amp;history=src%2Fpreview.js");
48
49 const commits = await harness.agent
50 .get(`/s/${id}/repositories/101?ref=review-notes&refType=branch&tab=commits`)
51 .expect(200);
52 expect(commits.text).toContain("Add atlas review notes");
53 expect(commits.text).not.toContain("Finish atlas viewer");
54
55 const search = await harness.agent
56 .get(`/s/${id}/search?q=Review+notes&repository=101&ref=review-notes&refType=branch`)
57 .expect(200);
58 expect(search.text).toContain("README.md");
59 expect(search.text).toContain("?ref=review-notes&amp;refType=branch&amp;file=README.md&amp;view=source#L3");
60 });
61
62 it("rejects references that were not included in the snapshot", async () => {
63 harness = makeHarness();
64 const { id } = await createShare(harness);
65 const page = await harness.agent
66 .get(`/s/${id}/repositories/101?ref=missing&refType=branch`)
67 .expect(404);
68 expect(page.text).toContain("This branch or tag is not part of the snapshot.");
69 });
70
71 it("keeps snapshots created before ref support browsable", async () => {
72 harness = makeHarness();
73 await authenticate(harness);
74 harness.store.createShare({
75 id: "legacy-share",
76 ownerId: 77,
77 createdAt: "2026-07-23T12:00:00.000Z",
78 expiresAt: "2026-07-30T12:00:00.000Z",
79 snapshot: {
80 profile: { login: "rasmus", name: "Rasmus", avatarUrl: "", bio: "" },
81 repositories: [{
82 id: 303,
83 name: "legacy",
84 fullName: "rasmus/legacy",
85 description: "Older snapshot",
86 language: "JavaScript",
87 defaultBranch: "main",
88 headSha: "abc123",
89 files: [{ path: "legacy.js", size: 12, content: "const old = 1;", truncated: false }],
90 commits: [],
91 }],
92 },
93 });
94
95 const page = await harness.agent.get("/s/legacy-share/repositories/303").expect(200);
96 expect(page.text).toContain("legacy.js");
97 expect(page.text).toContain("<strong>main</strong> default branch");
98 });
99 });
100