import app from "../app";
import supertest from "supertest";
import { googleSheetsService } from "../services/";
import { RaceCalendarEvent } from "../services/googleSheetsUtils";
const api = supertest(app);
const mockData: RaceCalendarEvent[] = [
{
eventId: "0401",
isReady: true,
isCompleted: true,
date: "20200101",
trackName: "Test Track",
qLaps: 5,
raceLaps: 4,
},
{
eventId: "0402",
isReady: true,
isCompleted: true,
date: "20200101",
trackName: "Test Track",
qLaps: 5,
raceLaps: 4,
},
];
describe("GET /api/calendar", () => {
let mockGoogleSheetService: jest.SpyInstance;
beforeAll(() => {
mockGoogleSheetService = jest
.spyOn(googleSheetsService, "getRaceCalendar")
.mockImplementation(
() =>
new Promise((resolve, _reject) => {
resolve(mockData);
})
);
});
afterAll(() => {
mockGoogleSheetService.mockRestore();
});
it("should return json", async () => {
await api
.get("/api/calendar")
.expect(200)
.expect("Content-Type", /application\/json/);
});
it("calls getRaceCalendar from googleSheetService", async () => {
await api.get("/api/calendar").expect(200);
expect(mockGoogleSheetService).toHaveBeenCalled;
});