Skip to content

Commit

Permalink
Add test when no site data available
Browse files Browse the repository at this point in the history
  • Loading branch information
benvinegar committed Feb 4, 2024
1 parent 1dfbfe2 commit 01560b6
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions app/routes/dashboard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,8 @@ describe("Dashboard route", () => {
test("redirects to ?site=siteId if no siteId is provided via query string", async () => {
// response for getSitesByOrderedHits
fetch.mockResolvedValueOnce(
new Promise((resolve) => {
resolve(
createFetchResponse({
data: [{ siteId: "test-siteid", count: 1 }],
}),
);
createFetchResponse({
data: [{ siteId: "test-siteid", count: 1 }],
}),
);

Expand All @@ -72,6 +68,34 @@ describe("Dashboard route", () => {
);
});

test("redirects to ?site= if no siteId is provided via query string / no site data", async () => {
// response for getSitesByOrderedHits
fetch.mockResolvedValueOnce(
createFetchResponse({
data: [],
}),
);

const response = await loader({
context: {
env: {
CF_BEARER_TOKEN: "fake",
CF_ACCOUNT_ID: "fake",
},
},
// @ts-expect-error we don't need to provide all the properties of the request object
request: {
url: "http://localhost:3000/dashboard", // no site query param
},
});

// expect redirect
expect(response.status).toBe(302);
expect(response.headers.get("Location")).toBe(
"http://localhost:3000/dashboard?site=",
);
});

test("assembles data returned from CF API", async () => {
// response for getSitesByOrderedHits
fetch.mockResolvedValueOnce(
Expand Down

0 comments on commit 01560b6

Please sign in to comment.