Skip to content

Commit

Permalink
N21-2103 wip vidis response test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
GordonNicholasCap committed Dec 19, 2024
1 parent 47684f6 commit e8b10e9
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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<SymetricKeyEncryptionService>;

beforeAll(async () => {
module = await Test.createTestingModule({
imports: [HttpModule],
providers: [
VidisSyncService,
{ provide: MediaSchoolLicenseService, useValue: createMock<MediaSchoolLicenseService>() },
{ provide: SchoolService, useValue: createMock<SchoolService>() },
{ provide: MediaSourceService, useValue: createMock<MediaSourceService>() },
{ provide: Logger, useValue: createMock<Logger>() },
{ provide: DefaultEncryptionService, useValue: createMock<EncryptionService>() },
],
}).compile();

service = module.get(VidisSyncService);
encryptionService = module.get(DefaultEncryptionService);
axiosMock = new MockAdapter(axios);
});

afterAll(async () => {
await module.close();
});

afterEach(async () => {

Check failure on line 44 in apps/server/src/infra/sync/media-licenses/service/vidis-sync-service.response.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

Async arrow function has no 'await' expression
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);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import { VidisItemResponse } from '../response';
export const vidisItemResponseFactory = Factory.define<VidisItemResponse>(({ 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,
};
});

0 comments on commit e8b10e9

Please sign in to comment.