-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
N21-2103 wip tests, mark some code for changes
- Loading branch information
1 parent
847dc2a
commit 31b4d37
Showing
8 changed files
with
196 additions
and
8 deletions.
There are no files selected for viewing
54 changes: 53 additions & 1 deletion
54
apps/server/src/infra/sync/media-licenses/mapper/vidis-item.mapper.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,53 @@ | ||
// TODO: tests | ||
import { VidisItemDto } from '@src/modules/school-license/dto'; | ||
import { vidisItemResponseFactory } from '../testing/vidis-item.response.factory'; | ||
import { VidisItemResponse } from '../response/vidis-item.response'; | ||
import { VidisItemMapper } from './vidis-item.mapper'; | ||
|
||
describe(VidisItemMapper.name, () => { | ||
describe('mapToVidisItem', () => { | ||
describe('when a VIDIS item response is given', () => { | ||
const setup = () => { | ||
const vidisItemResponse = vidisItemResponseFactory.build(); | ||
|
||
return { vidisItemResponse }; | ||
}; | ||
|
||
it('should return a mapped VidisItemDto', () => { | ||
const { vidisItemResponse } = setup(); | ||
|
||
const result: VidisItemDto = VidisItemMapper.mapToVidisItem(vidisItemResponse); | ||
|
||
expect(result).toEqual( | ||
expect.objectContaining({ | ||
offerId: vidisItemResponse.offerId, | ||
schoolActivations: vidisItemResponse.schoolActivations, | ||
} as VidisItemDto) | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('mapToVidisItems', () => { | ||
const setup = () => { | ||
const vidisItemResponses = vidisItemResponseFactory.buildList(3); | ||
const expectedItemDtos: VidisItemDto[] = vidisItemResponses.map( | ||
(response: VidisItemResponse) => | ||
({ | ||
offerId: response.offerId, | ||
schoolActivations: response.schoolActivations, | ||
} as VidisItemDto) | ||
); | ||
|
||
return { vidisItemResponses, expectedItemDtos }; | ||
}; | ||
|
||
it('should return a mapped VidisItemDto', () => { | ||
const { vidisItemResponses, expectedItemDtos } = setup(); | ||
|
||
const results: VidisItemDto[] = VidisItemMapper.mapToVidisItems(vidisItemResponses); | ||
|
||
expect(results.length).toEqual(vidisItemResponses.length); | ||
expect(results).toEqual(expect.arrayContaining(expectedItemDtos)); | ||
}); | ||
}); | ||
}); |
6 changes: 3 additions & 3 deletions
6
apps/server/src/infra/sync/media-licenses/mapper/vidis-item.mapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 71 additions & 1 deletion
72
apps/server/src/infra/sync/media-licenses/service/vidis-sync.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,71 @@ | ||
// TODO: tests | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { HttpService } from '@nestjs/axios'; | ||
import { createMock, DeepMocked } from '@golevelup/ts-jest'; | ||
import { MediaSourceService } from '@modules/mediasource/service'; | ||
import { MediaSchoolLicenseService } from '@modules/school-license/service/media-school-license.service'; | ||
import { DefaultEncryptionService, EncryptionService, SymetricKeyEncryptionService } from '@infra/encryption'; | ||
import { VidisSyncService } from './vidis-sync.service'; | ||
|
||
describe(VidisSyncService.name, () => { | ||
let module: TestingModule; | ||
let httpService: DeepMocked<HttpService>; | ||
let mediaSourceService: DeepMocked<MediaSourceService>; | ||
let mediaSchoolLicenseService: DeepMocked<MediaSchoolLicenseService>; | ||
let encryptionService: DeepMocked<SymetricKeyEncryptionService>; | ||
|
||
beforeAll(async () => { | ||
module = await Test.createTestingModule({ | ||
providers: [ | ||
VidisSyncService, | ||
{ | ||
provide: HttpService, | ||
useValue: createMock<HttpService>(), | ||
}, | ||
{ | ||
provide: MediaSourceService, | ||
useValue: createMock<MediaSourceService>(), | ||
}, | ||
{ | ||
provide: MediaSchoolLicenseService, | ||
useValue: createMock<MediaSchoolLicenseService>(), | ||
}, | ||
{ | ||
provide: DefaultEncryptionService, | ||
useValue: createMock<EncryptionService>(), | ||
}, | ||
], | ||
}).compile(); | ||
|
||
httpService = module.get(HttpService); | ||
mediaSourceService = module.get(MediaSourceService); | ||
mediaSchoolLicenseService = module.get(MediaSchoolLicenseService); | ||
encryptionService = module.get(DefaultEncryptionService); | ||
}); | ||
|
||
afterAll(async () => { | ||
await module.close(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
// TODO: implementation | ||
describe('syncMediaSchoolLicenses', () => { | ||
describe('when the media source with correct configs is found', () => { | ||
const setup = () => {}; | ||
|
||
it('should not throw any error', () => { | ||
setup(); | ||
}); | ||
}); | ||
|
||
describe('when there is an error fetching data from media source', () => { | ||
const setup = () => {}; | ||
|
||
it('should throw an error', () => { | ||
setup(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
apps/server/src/infra/sync/media-licenses/testing/vidis-item.response.factory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Factory } from 'fishery'; | ||
import { VidisItemResponse } from '@infra/sync/media-licenses/response/vidis-item.response'; | ||
|
||
export const vidisItemResponseFactory = Factory.define<VidisItemResponse>(({ sequence }) => { | ||
return { | ||
offerId: `${sequence}`, | ||
offerTitle: 'VIDIS Test Response', | ||
offerVersion: 1, | ||
schoolActivations: ['00100', '00200', '00300'], | ||
}; | ||
}); |
57 changes: 55 additions & 2 deletions
57
apps/server/src/modules/school-license/service/media-school-license.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,56 @@ | ||
describe('MediaSchoolLicenseService', () => { | ||
// TODO: write tests | ||
import { MediaSchoolLicenseService } from '@modules/school-license/service/media-school-license.service'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { MediaSchoolLicenseRepo } from '@modules/school-license/repo'; | ||
import { createMock, DeepMocked } from '@golevelup/ts-jest'; | ||
import { SchoolService } from '@modules/school'; | ||
import { Logger } from '@src/core/logger'; | ||
|
||
describe(MediaSchoolLicenseService.name, () => { | ||
let module: TestingModule; | ||
let mediaSchoolLicenseRepo: DeepMocked<MediaSchoolLicenseRepo>; | ||
let schoolService: DeepMocked<SchoolService>; | ||
let logger: DeepMocked<Logger>; | ||
|
||
beforeAll(async () => { | ||
module = await Test.createTestingModule({ | ||
providers: [ | ||
MediaSchoolLicenseService, | ||
{ | ||
provide: MediaSchoolLicenseRepo, | ||
useValue: createMock<MediaSchoolLicenseRepo>, | ||
}, | ||
{ | ||
provide: SchoolService, | ||
useValue: createMock<SchoolService>, | ||
}, | ||
{ | ||
provide: Logger, | ||
useValue: createMock<Logger>, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
mediaSchoolLicenseRepo = module.get(MediaSchoolLicenseRepo); | ||
schoolService = module.get(SchoolService); | ||
logger = module.get(Logger); | ||
}); | ||
|
||
afterAll(async () => { | ||
await module.close(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
// TODO: implementation | ||
describe('syncMediaSchoolLicenses', () => { | ||
describe('when a media source and items are given', () => { | ||
const setup = () => {}; | ||
|
||
it('it should save the school licenses', () => { | ||
setup(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters