Skip to content

Commit

Permalink
Fix remaining tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benvinegar committed Dec 12, 2024
1 parent 8479b18 commit 47af390
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
29 changes: 15 additions & 14 deletions app/routes/__tests__/resources.paths.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,29 @@ describe("Resources/Paths route", () => {
});
describe("loader", () => {
test("returns valid json", async () => {
// first request for visitors
fetch.mockResolvedValueOnce(
createFetchResponse({
data: [
{ blob3: "/", isVisitor: 0, isVisit: 0, count: "5" },
{ blob3: "/", isVisitor: 0, isVisit: 1, count: "1" },
{ blob3: "/", isVisitor: 1, isVisit: 1, count: "2" },
{ blob3: "/", isVisitor: 1, count: "2" },
{
blob3: "/example",
isVisitor: 0,
isVisit: 0,
isVisitor: 1,
count: "4",
},
],
}),
);
// second request for views
fetch.mockResolvedValueOnce(
createFetchResponse({
data: [
{ blob3: "/", isVisitor: 0, count: "5" },
{
blob3: "/example",
isVisitor: 0,
isVisit: 1,
count: "6",
},
{
blob3: "/example",
isVisitor: 1,
isVisit: 1,
count: "2",
},
],
}),
);
Expand All @@ -63,12 +62,14 @@ describe("Resources/Paths route", () => {

// expect redirect
expect(response.status).toBe(200);
expect(fetch).toHaveBeenCalledTimes(2);

const json = await response.json();

expect(json).toEqual({
countsByProperty: [
["/", 2, 8],
["/example", 2, 12],
["/example", 4, 10],
["/", 2, 7],
],
page: 1,
});
Expand Down
23 changes: 15 additions & 8 deletions app/routes/__tests__/resources.referrer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,28 @@ describe("Resources/Referrer route", () => {

describe("loader", () => {
test("returns valid json", async () => {
// first request for visitors
fetch.mockResolvedValueOnce(
createFetchResponse({
data: [
{ blob5: "/", isVisitor: 0, isVisit: 0, count: "5" },
{ blob5: "/", isVisitor: 1, isVisit: 1, count: "1" },
{ blob5: "/", isVisitor: 1, count: "1" },
{
blob5: "/example",
isVisitor: 0,
isVisit: 1,
count: "2",
isVisitor: 1,
count: "1",
},
],
}),
);
// second request for views
fetch.mockResolvedValueOnce(
createFetchResponse({
data: [
{ blob5: "/", isVisitor: 0, count: "5" },
{
blob5: "/example",
isVisitor: 1,
isVisit: 1,
count: "1",
isVisitor: 0,
count: "2",
},
],
}),
Expand All @@ -57,6 +63,7 @@ describe("Resources/Referrer route", () => {

// expect redirect
expect(response.status).toBe(200);
expect(fetch).toHaveBeenCalledTimes(2);

const json = await response.json();
expect(json).toEqual({
Expand Down

0 comments on commit 47af390

Please sign in to comment.