Skip to content

Commit ffe7e37

Browse files
committed
fix: comments
1 parent 55be572 commit ffe7e37

File tree

6 files changed

+32
-31
lines changed

6 files changed

+32
-31
lines changed

apps/dashboard/src/components/forms/components/form-import.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ export function FormImport({
273273
<Input placeholder="e.g. clx1abc2def3" {...field} />
274274
</FormControl>
275275
<FormDescription>
276-
Import a specific page. Leave empty to import the
277-
first page.
276+
Import a specific page. Leave empty to import all
277+
pages.
278278
</FormDescription>
279279
</FormItem>
280280
)}

packages/importers/src/providers/instatus/client.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,11 @@ describe("InstatusClient", () => {
104104
});
105105

106106
test("sends correct Bearer auth header", async () => {
107-
mockFetch(MOCK_PAGES);
107+
mockFetchPaginated(MOCK_PAGES);
108108
await client.getPages();
109109
const fetchMock = globalThis.fetch as unknown as ReturnType<typeof mock>;
110-
expect(fetchMock).toHaveBeenCalledTimes(1);
111110
const [url, options] = fetchMock.mock.calls[0] as [string, RequestInit];
112-
expect(url).toBe("https://api.instatus.com/v2/pages");
111+
expect(url).toBe("https://api.instatus.com/v2/pages?page=1&per_page=100");
113112
expect((options.headers as Record<string, string>).Authorization).toBe(
114113
"Bearer test-api-key",
115114
);

packages/importers/src/providers/instatus/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function createInstatusClient(
6565
}
6666

6767
return {
68-
getPages: () => request("/v2/pages", z.array(InstatusPageSchema)),
68+
getPages: () => requestAllPages("/v2/pages", InstatusPageSchema),
6969
getPage: (pageId) => request(`/v2/${pageId}`, InstatusPageSchema),
7070
getComponents: (pageId) =>
7171
requestAllPages(`/v2/${pageId}/components`, InstatusComponentSchema),

packages/importers/src/providers/instatus/mapper.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@ export function mapMaintenanceToMaintenance(
164164

165165
const from = new Date(m.start);
166166
const duration = m.duration ?? 0;
167-
const to = duration > 0 ? new Date(from.getTime() + duration * 60_000) : from;
167+
const to =
168+
duration > 0
169+
? new Date(from.getTime() + duration * 60_000)
170+
: new Date(from);
168171

169172
return {
170173
title: m.name,

packages/importers/src/providers/instatus/provider.test.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ function createMockFetch(options?: { failAuth?: boolean }) {
2121
);
2222
}
2323

24-
if (url.match(/\/v2\/pages$/)) {
25-
return Promise.resolve(Response.json(MOCK_PAGES));
24+
if (url.match(/\/v2\/pages(\?|$)/)) {
25+
const pageParam = new URL(url).searchParams.get("page");
26+
return Promise.resolve(
27+
Response.json(pageParam === "1" || !pageParam ? MOCK_PAGES : []),
28+
);
2629
}
2730
if (url.match(/\/v2\/[^/]+\/components(\?|$)/)) {
2831
const pageParam = new URL(url).searchParams.get("page");
@@ -145,25 +148,15 @@ describe("InstatusImportProvider", () => {
145148
matching.phases.find((p) => p.phase === name);
146149
expect(findPhase("page")?.resources).toHaveLength(1);
147150

148-
// Filter by non-existent page ID — should return empty phases
151+
// Filter by non-existent page ID — should return failed with error
149152
const nonMatching = await provider.run({
150153
apiKey: "test-key",
151154
workspaceId: 1,
152155
dryRun: true,
153156
instatusPageId: "nonexistent",
154157
});
155-
expect(nonMatching.phases).toHaveLength(0);
156-
});
157-
158-
it("reports skipped non-email subscribers", async () => {
159-
const provider = createInstatusProvider();
160-
const summary = await provider.run({
161-
apiKey: "test-key",
162-
workspaceId: 1,
163-
dryRun: true,
164-
});
165-
166-
expect(summary.errors).toHaveLength(1);
167-
expect(summary.errors[0]).toContain("3 non-email subscribers were skipped");
158+
expect(nonMatching.status).toBe("failed");
159+
expect(nonMatching.errors).toHaveLength(1);
160+
expect(nonMatching.errors[0]).toContain("nonexistent");
168161
});
169162
});

packages/importers/src/providers/instatus/provider.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,21 @@ export function createInstatusProvider(): ImportProvider<InstatusImportConfig> {
4949
let pages = await client.getPages();
5050
if (config.instatusPageId) {
5151
pages = pages.filter((p) => p.id === config.instatusPageId);
52+
if (pages.length === 0) {
53+
return {
54+
provider: "instatus",
55+
status: "failed",
56+
startedAt: new Date(),
57+
completedAt: new Date(),
58+
phases: [],
59+
errors: [
60+
`No page found with ID "${config.instatusPageId}". Check the page ID and try again.`,
61+
],
62+
};
63+
}
5264
}
5365

5466
let skippedSubscribers = 0;
55-
const allWarnings: string[] = [];
5667

5768
for (const pg of pages) {
5869
const [allComponents, incidents, maintenances, subscribers] =
@@ -63,12 +74,7 @@ export function createInstatusProvider(): ImportProvider<InstatusImportConfig> {
6374
client.getSubscribers(pg.id),
6475
]);
6576

66-
const {
67-
groups,
68-
components,
69-
warnings: partitionWarnings,
70-
} = partitionComponents(allComponents);
71-
allWarnings.push(...partitionWarnings);
77+
const { groups, components } = partitionComponents(allComponents);
7278

7379
// Page phase
7480
const mappedPage = mapPage(pg, config.workspaceId);
@@ -169,7 +175,7 @@ export function createInstatusProvider(): ImportProvider<InstatusImportConfig> {
169175
});
170176
}
171177

172-
const errors: string[] = [...allWarnings];
178+
const errors: string[] = [];
173179
if (skippedSubscribers > 0) {
174180
errors.push(
175181
`Only email subscribers are supported. ${skippedSubscribers} non-email subscriber${skippedSubscribers === 1 ? " was" : "s were"} skipped.`,

0 commit comments

Comments
 (0)