diff --git a/apps/server/src/infra/sync/media-licenses/service/vidis-sync-service.response.spec.ts b/apps/server/src/infra/sync/media-licenses/service/vidis-sync-service.response.spec.ts new file mode 100644 index 0000000000..d877302236 --- /dev/null +++ b/apps/server/src/infra/sync/media-licenses/service/vidis-sync-service.response.spec.ts @@ -0,0 +1,71 @@ +import { HttpStatus } from '@nestjs/common'; +import { Test, TestingModule } from '@nestjs/testing'; +import { HttpModule } from '@nestjs/axios'; +import { createMock, DeepMocked } from '@golevelup/ts-jest'; +import { Logger } from '@src/core/logger'; +import { DefaultEncryptionService, EncryptionService, SymetricKeyEncryptionService } from '@infra/encryption'; +import { mediaSourceFactory } from '@modules/media-source/testing'; +import { MediaSourceDataFormat, MediaSourceService } from '@modules/media-source'; +import { MediaSchoolLicenseService } from '@modules/school-license'; +import { SchoolService } from '@modules/school'; +import MockAdapter from 'axios-mock-adapter'; +import axios from 'axios'; +import { vidisResponseFactory } from '../testing'; +import { VidisSyncService } from './vidis-sync.service'; + +describe(`${VidisSyncService.name} Integration`, () => { + let module: TestingModule; + let axiosMock: MockAdapter; + let service: VidisSyncService; + let encryptionService: DeepMocked; + + beforeAll(async () => { + module = await Test.createTestingModule({ + imports: [HttpModule], + providers: [ + VidisSyncService, + { provide: MediaSchoolLicenseService, useValue: createMock() }, + { provide: SchoolService, useValue: createMock() }, + { provide: MediaSourceService, useValue: createMock() }, + { provide: Logger, useValue: createMock() }, + { provide: DefaultEncryptionService, useValue: createMock() }, + ], + }).compile(); + + service = module.get(VidisSyncService); + encryptionService = module.get(DefaultEncryptionService); + axiosMock = new MockAdapter(axios); + }); + + afterAll(async () => { + await module.close(); + }); + + afterEach(async () => { + jest.clearAllMocks(); + }); + + describe('getSchoolActivationsFromVidis', () => { + describe('when the vidis media source is passed', () => { + const setup = () => { + const mediaSource = mediaSourceFactory.withBasicAuthConfig().build({ format: MediaSourceDataFormat.VIDIS }); + const vidisResponse = vidisResponseFactory.build(); + + encryptionService.decrypt.mockReturnValueOnce('username'); + encryptionService.decrypt.mockReturnValueOnce('password'); + + axiosMock.onGet().replyOnce(HttpStatus.OK, vidisResponse); + + return { mediaSource, vidisResponse }; + }; + + it('should return the school activation items from vidis', async () => { + const { mediaSource, vidisResponse } = setup(); + + const items = await service.getSchoolActivationsFromVidis(mediaSource); + + expect(items).toEqual(vidisResponse.items); + }); + }); + }); +}); diff --git a/apps/server/src/infra/sync/media-licenses/testing/vidis-item.response.factory.ts b/apps/server/src/infra/sync/media-licenses/testing/vidis-item.response.factory.ts index 939650ecb4..08241b9b3d 100644 --- a/apps/server/src/infra/sync/media-licenses/testing/vidis-item.response.factory.ts +++ b/apps/server/src/infra/sync/media-licenses/testing/vidis-item.response.factory.ts @@ -4,8 +4,13 @@ import { VidisItemResponse } from '../response'; export const vidisItemResponseFactory = Factory.define(({ sequence }) => { return { offerId: `${sequence}`, - offerTitle: 'VIDIS Test Response', - offerVersion: 1, schoolActivations: ['00100', '00200', '00300'], + educationProviderOrganizationName: 'Test Org', + offerDescription: 'Test Description', + offerLink: 'https://test-link.com/offer', + offerLogo: 'https://test-link.com/offer/logo.svg', + offerTitle: 'VIDIS Test', + offerLongTitle: 'VIDIS Test Response', + offerVersion: 1, }; });