Skip to content

Commit

Permalink
Fix bad math/assertions in some if-modified-since tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benvinegar committed Feb 10, 2024
1 parent 9e0d734 commit aa97e2d
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions app/analytics/collect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe("collectRequestHandler", () => {
// @ts-expect-error - we're mocking the request object
generateRequestParams({
"if-modified-since": new Date(
Date.now() - 5 * 60 * 1000,
Date.now() - 5 * 60 * 1000, // 5 mins ago
).toUTCString(),
}),
);
Expand All @@ -120,8 +120,8 @@ describe("collectRequestHandler", () => {
expect((writeDataPoint as Mock).mock.calls[0][0]).toHaveProperty(
"doubles",
[
0, // new visitor
0, // new session
0, // NOT a new visitor
0, // NOT a new session
],
);
});
Expand All @@ -142,7 +142,7 @@ describe("collectRequestHandler", () => {
// @ts-expect-error - we're mocking the request object
generateRequestParams({
"if-modified-since": new Date(
Date.now() - 25 * 60 * 1000, // 25 minutes
Date.now() - 25 * 60 * 1000, // 25 minutes ago
).toUTCString(),
}),
);
Expand All @@ -155,11 +155,12 @@ describe("collectRequestHandler", () => {
[
1, // new visitor because a new day began
0, // NOT a new session because continuation of earlier session (< 30 mins)
// (session logic doesn't care if a new day began or not)
],
);
});

test("if-modified-since is over 30 ago", () => {
test("if-modified-since is over 30 days ago", () => {
const env = {
WEB_COUNTER_AE: {
writeDataPoint: vi.fn(),
Expand All @@ -170,7 +171,7 @@ describe("collectRequestHandler", () => {
// @ts-expect-error - we're mocking the request object
generateRequestParams({
"if-modified-since": new Date(
Date.now() - 31 * 60 * 1000,
Date.now() - 31 * 24 * 60 * 60 * 1000, // 31 days ago
).toUTCString(),
}),
);
Expand All @@ -181,8 +182,8 @@ describe("collectRequestHandler", () => {
expect((writeDataPoint as Mock).mock.calls[0][0]).toHaveProperty(
"doubles",
[
0, // new visitor
1, // new session
1, // new visitor because > 30 days passed
1, // new session because > 30 minutes passed
],
);
});
Expand All @@ -198,7 +199,7 @@ describe("collectRequestHandler", () => {
// @ts-expect-error - we're mocking the request object
generateRequestParams({
"if-modified-since": new Date(
Date.now() - 60 * 24 * 60 * 1000,
Date.now() - 24 * 60 * 60 * 1000, // 24 hours ago
).toUTCString(),
}),
);
Expand All @@ -209,8 +210,8 @@ describe("collectRequestHandler", () => {
expect((writeDataPoint as Mock).mock.calls[0][0]).toHaveProperty(
"doubles",
[
1, // new visitor
1, // new session
1, // new visitor because > 24 hours passed
1, // new session because > 30 minutes passed
],
);
});
Expand Down

0 comments on commit aa97e2d

Please sign in to comment.