import { Test, TestingModule } from '@nestjs/testing'; import { seasons } from '@prisma/client'; import { DatabaseService } from './database.service'; import { mockReset, MockProxy, mockDeep } from 'jest-mock-extended'; import { SeasonInfo } from '../models/aliases'; import { PrismaService } from '../prisma/prisma.service'; import { TimeTrackerPredicate } from './timetracking.predicate'; import { mocked } from 'ts-jest'; describe('DatabaseService', () => { let service: DatabaseService; const mockedPrismaService: MockProxy = mockDeep(); beforeEach(async () => { mockReset(mockedPrismaService); const module: TestingModule = await Test.createTestingModule({ providers: [DatabaseService, PrismaService, TimeTrackerPredicate], }) .overrideProvider(PrismaService) .useValue(mockedPrismaService) .compile(); service = module.get(DatabaseService); }); it('should be defined', () => { expect(service).toBeDefined(); }); // TODO This will be skipped as Prisma__#client can barely be mocked. // it('fetch season info with season ID given', async () => { // const seasonIdToBeTested = 1; // const mockedValue: seasons = { // season_id: 2, // start_date: new Date('1995-12-17T03:24:00'), // end_date: null // }; // const mockedMaxSeasonId = { // max: { // season_id: 2 // } // }; // // mockedPrismaService.seasons.findUnique.calledWith({ // where: { // season_id: Number(seasonIdToBeTested) // } // }).mockImplementation((subset) => { // return new Promise(resolve => resolve(mockedValue)); // }); // // mockedPrismaService.seasons.aggregate.calledWith({ // max: { // season_id: true // } // }).mockImplementation(() => Promise.resolve(mockedMaxSeasonId)); // // const expected: SeasonInfo = { // season_id: 2, // maxSeasonId: 2, // start_date: new Date('1995-12-17T03:24:00'), // end_date: null // } // const actual = service.fetchSeasonInfos(); // // await expect(actual).resolves.toEqual(expected); // }); });