Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
improve typing for mockings of logged runs
Browse files Browse the repository at this point in the history
  • Loading branch information
zimeg committed Sep 27, 2023
1 parent 08b6546 commit 8365131
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
17 changes: 9 additions & 8 deletions functions/collect_runner_stats_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ import * as mf from "mock-fetch/mod.ts";
import { SlackFunctionTester } from "deno-slack-sdk/mod.ts";
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import CollectRunnerStatsFunction from "./collect_runner_stats.ts";
import { DatastoreItem } from "deno-slack-api/types.ts";
import RunningDatastore from "../datastores/run_data.ts";

// Mocked date for stable testing
Date.now = () => new Date("2023-01-04").getTime();

// Collection of runs stored in the mocked datastore
// let mockRuns: DatastoreItem<typeof RunningDatastore.definition>[];
const mockRuns = [
{ runner: "U0123456", distance: 4, rundate: "2023-01-04" },
{ runner: "U0123456", distance: 2, rundate: "2023-01-04" },
{ runner: "U7777777", distance: 2, rundate: "2023-01-02" },
{ runner: "U0123456", distance: 4, rundate: "2023-01-02" },
{ runner: "U7777777", distance: 1, rundate: "2022-12-10" },
{ runner: "U0123456", distance: 2, rundate: "2022-11-11" },
const mockRuns: DatastoreItem<typeof RunningDatastore.definition>[] = [
{ id: "R006", runner: "U0123456", distance: 4, rundate: "2023-01-04" },
{ id: "R005", runner: "U0123456", distance: 2, rundate: "2023-01-04" },
{ id: "R004", runner: "U7777777", distance: 2, rundate: "2023-01-02" },
{ id: "R003", runner: "U0123456", distance: 4, rundate: "2023-01-02" },
{ id: "R002", runner: "U7777777", distance: 1, rundate: "2022-12-10" },
{ id: "R001", runner: "U0123456", distance: 2, rundate: "2022-11-11" },
];

// Replaces globalThis.fetch with the mocked copy
Expand Down
10 changes: 5 additions & 5 deletions functions/collect_team_stats_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ Deno.test("Retrieve the empty set", async () => {

Deno.test("Count only runs from the past week", async () => {
mockRuns = [
{ id: "R000", runner: "U0123456", distance: 8, rundate: "2023-01-05" },
{ id: "R001", runner: "U0123456", distance: 4, rundate: "2023-01-04" },
{ id: "R002", runner: "U7777777", distance: 2, rundate: "2023-01-02" },
{ id: "R006", runner: "U0123456", distance: 8, rundate: "2023-01-05" },
{ id: "R005", runner: "U0123456", distance: 4, rundate: "2023-01-04" },
{ id: "R004", runner: "U7777777", distance: 2, rundate: "2023-01-02" },
{ id: "R003", runner: "U0123456", distance: 4, rundate: "2022-12-31" },
{ id: "R004", runner: "U7777777", distance: 6, rundate: "2022-12-29" },
{ id: "R005", runner: "U8888888", distance: 1, rundate: "2022-12-28" },
{ id: "R002", runner: "U7777777", distance: 6, rundate: "2022-12-29" },
{ id: "R001", runner: "U8888888", distance: 1, rundate: "2022-12-28" },
];
const { outputs, error } = await CollectTeamStatsFunction(
createContext({ inputs: {} }),
Expand Down

0 comments on commit 8365131

Please sign in to comment.