add mocking functions for tests

This commit is contained in:
2025-01-07 14:24:21 -08:00
parent d10ad92907
commit 440bdc9edd
2 changed files with 42 additions and 4 deletions

View File

@@ -1,16 +1,14 @@
import { GetterRepository } from "./GetterRepository"; import { GetterRepository } from "./GetterRepository";
import { IEta } from "../entities/entities"; import { IEta } from "../entities/entities";
export class ApiBasedRepository implements GetterRepository {
public async getEtaForShuttleAndStopId(shuttleId: string, stopId: string): Promise<IEta | null> {
// TODO: implement // TODO: implement
export class ApiBasedRepository implements GetterRepository {
public async getEtaForShuttleAndStopId(shuttleId: string, stopId: string): Promise<IEta | null> {
return null; return null;
} }
public async getEtasForShuttleId(shuttleId: string): Promise<[]> { public async getEtasForShuttleId(shuttleId: string): Promise<[]> {
// TODO: implement
return []; return [];
} }

View File

@@ -0,0 +1,40 @@
import { beforeEach, describe, jest, test } from "@jest/globals";
/**
* Update the global fetch function to return a specific object.
* @param obj
*/
function updateGlobalFetchMockJson(obj: any) {
// @ts-ignore
global.fetch = jest.fn(() => {
return Promise.resolve({
json: () => Promise.resolve(obj)
})
}) as jest.Mock;
}
/**
* Reset the global fetch function mock's JSON to return an empty object.
* @param obj
*/
function resetGlobalFetchMockJson() {
updateGlobalFetchMockJson({})
}
beforeEach(() => {
resetGlobalFetchMockJson();
})
describe("getEtaForShuttleAndStopId", () => {
test("getEtaForShuttleAndStopId returns correct ETA data", async () => {
});
test("getEtaForShuttleAndStopId returns null if API call is invalid", async () => {
});
});
describe("getEtasForShuttleId", () => {
})