-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathchanges_test.ts
More file actions
157 lines (142 loc) Β· 4.44 KB
/
Copy pathchanges_test.ts
File metadata and controls
157 lines (142 loc) Β· 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import { assertEquals, assertRejects, assertStringIncludes } from "@std/assert";
import {
buildCompanyChangeSet,
hasCompanyChanges,
renderCompanyChangesMarkdown,
writeCompanyChangeFiles,
} from "./changes.ts";
const baseCompany = {
id: 1,
name: "Acme AI",
slug: "acme-ai",
batch: "S24",
one_liner: "Builds agents for invoices",
website: "https://acme.example",
url: "https://www.ycombinator.com/companies/acme-ai",
isHiring: false,
};
Deno.test("buildCompanyChangeSet detects added, removed, and updated companies", () => {
const removedCompany = {
...baseCompany,
id: 2,
name: "Old Co",
slug: "old-co",
};
const addedCompany = {
...baseCompany,
id: 3,
name: "New Co",
slug: "new-co",
one_liner: "Newly launched",
};
const changeSet = buildCompanyChangeSet({
previousCompanies: [baseCompany, removedCompany],
currentCompanies: [
{
...baseCompany,
one_liner: "Builds agents for receipts",
isHiring: true,
},
addedCompany,
],
generatedAt: "2026-06-30T00:00:00.000Z",
});
assertEquals(changeSet.summary, {
previous_total: 2,
current_total: 2,
added: 1,
removed: 1,
updated: 1,
});
assertEquals(changeSet.added.map((company) => company.slug), ["new-co"]);
assertEquals(changeSet.removed.map((company) => company.slug), ["old-co"]);
assertEquals(changeSet.updated.map((company) => company.slug), ["acme-ai"]);
assertEquals(changeSet.updated[0].changed_fields, ["isHiring", "one_liner"]);
assertEquals(changeSet.updated[0].changes.one_liner, {
before: "Builds agents for invoices",
after: "Builds agents for receipts",
});
assertEquals(hasCompanyChanges(changeSet), true);
});
Deno.test("renderCompanyChangesMarkdown summarizes the daily diff", () => {
const changeSet = buildCompanyChangeSet({
previousCompanies: [baseCompany],
currentCompanies: [
{
...baseCompany,
one_liner: "Builds agents for receipts",
isHiring: true,
},
{
...baseCompany,
id: 3,
name: "New Co",
slug: "new-co",
url: "https://www.ycombinator.com/companies/new-co",
},
],
generatedAt: "2026-06-30T00:00:00.000Z",
});
const markdown = renderCompanyChangesMarkdown(changeSet);
assertStringIncludes(markdown, "# YC company changes for 2026-06-30");
assertStringIncludes(markdown, "- Added: 1");
assertStringIncludes(markdown, "## Added companies");
assertStringIncludes(
markdown,
"[New Co](https://www.ycombinator.com/companies/new-co)",
);
assertStringIncludes(markdown, "## Updated companies");
assertStringIncludes(
markdown,
"`one_liner`: Builds agents for invoices β Builds agents for receipts",
);
});
Deno.test("renderCompanyChangesMarkdown handles days with no company changes", () => {
const changeSet = buildCompanyChangeSet({
previousCompanies: [baseCompany],
currentCompanies: [baseCompany],
generatedAt: "2026-06-30T00:00:00.000Z",
});
assertEquals(hasCompanyChanges(changeSet), false);
assertStringIncludes(
renderCompanyChangesMarkdown(changeSet),
"No company records changed.",
);
});
Deno.test("writeCompanyChangeFiles writes dated and latest change files", async () => {
const directory = await Deno.makeTempDir();
const changeSet = buildCompanyChangeSet({
previousCompanies: [baseCompany],
currentCompanies: [{ ...baseCompany, isHiring: true }],
generatedAt: "2026-06-30T00:00:00.000Z",
});
const { written } = await writeCompanyChangeFiles({ directory, changeSet });
assertEquals(written.sort(), [
"2026-06-30.json",
"2026-06-30.md",
"latest.json",
"latest.md",
]);
const latestJson = JSON.parse(
await Deno.readTextFile(`${directory}/latest.json`),
);
assertEquals(latestJson.summary.updated, 1);
assertStringIncludes(
await Deno.readTextFile(`${directory}/latest.md`),
"`isHiring`: false β true",
);
});
Deno.test("writeCompanyChangeFiles skips no-change days to avoid noisy commits", async () => {
const directory = await Deno.makeTempDir();
const changeSet = buildCompanyChangeSet({
previousCompanies: [baseCompany],
currentCompanies: [baseCompany],
generatedAt: "2026-06-30T00:00:00.000Z",
});
const { written } = await writeCompanyChangeFiles({ directory, changeSet });
assertEquals(written, []);
await assertRejects(
() => Deno.stat(`${directory}/latest.json`),
Deno.errors.NotFound,
);
});