Skip to content

Commit

Permalink
test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
GordonNicholasCap committed Dec 20, 2024
1 parent b693121 commit b88a030
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 88 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { HttpService } from '@nestjs/axios';
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { of, throwError } from 'rxjs';
import { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios';
import { VidisResponse } from '../response';
import { VidisItemResponse, VidisResponse } from '../response';
import { vidisResponseFactory, vidisItemResponseFactory } from '../testing';
import { VidisSyncService } from './vidis-sync.service';

Expand Down Expand Up @@ -134,8 +134,15 @@ describe(VidisSyncService.name, () => {
const setup = () => {
const mediaSource = mediaSourceFactory.withBasicAuthConfig().build();
const basicAuthConfig = mediaSource.basicAuthConfig as MediaSourceBasicAuthConfig;

const vidisItemResponse: VidisItemResponse[] = vidisItemResponseFactory.buildList(3);
vidisItemResponse[0].offerTitle = 'Other Title';

const vidisResponse: VidisResponse = vidisResponseFactory.build();
vidisResponse.items = vidisItemResponse;

const axiosResponse: AxiosResponse<VidisResponse> = axiosResponseFactory.build({
data: vidisResponseFactory.build(),
data: vidisResponse,
});

httpService.get.mockReturnValueOnce(of(axiosResponse));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ export class VidisSyncService {
if (!school) {
this.logger.info(new SchoolForSchoolMediaLicenseSyncNotFoundLoggable(schoolNumber));
} else {
const isExistingLicense: boolean = existingLicenses.some((license: MediaSchoolLicense): boolean => {
return license.schoolId === school.id;
});
const isExistingLicense = !!existingLicenses.find(
(license: MediaSchoolLicense): boolean => license.schoolId === school.id
);
if (!isExistingLicense) {
const newLicense: MediaSchoolLicense = new MediaSchoolLicense({
id: new ObjectId().toHexString(),
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/modules/school-license/domain/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { MediaSchoolLicense } from './media-school-license';
export { MediaSchoolLicense, MediaSchoolLicenseProps } from './media-school-license';
export { SchoolLicense } from './school-license';
2 changes: 1 addition & 1 deletion apps/server/src/modules/school-license/entity/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { MediaSchoolLicenseEntity } from './media-school-license.entity';
export { MediaSchoolLicenseEntity, MediaSchoolLicenseEntityProps } from './media-school-license.entity';
export { SchoolLicenseEntity } from './school-license.entity';
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe(MediaSchoolLicenseEntityMapper.name, () => {
it('should return the domain object of the entity', () => {
const { mediaSchoolLicenseEntity, expectedDomainObject } = setup();

const domainObject: MediaSchoolLicense = MediaSchoolLicenseEntityMapper.mapEntityToDo(mediaSchoolLicenseEntity);
const domainObject: MediaSchoolLicense = MediaSchoolLicenseEntityMapper.mapEntityToDO(mediaSchoolLicenseEntity);

expect(domainObject).toEqual(expectedDomainObject);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { MediaSchoolLicense } from '../../domain';
import { SchoolLicenseType } from '../../enum';

export class MediaSchoolLicenseEntityMapper {
public static mapEntityToDo(entity: MediaSchoolLicenseEntity): MediaSchoolLicense {
public static mapEntityToDO(entity: MediaSchoolLicenseEntity): MediaSchoolLicense {
let mediaSource: MediaSource | undefined;

if (entity.mediaSource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe(MediaSchoolLicenseMikroOrmRepo.name, () => {
em.clear();

const expectedDOs: MediaSchoolLicense[] = mediaSchoolLicenses.map(
(entity: MediaSchoolLicenseEntity): MediaSchoolLicense => MediaSchoolLicenseEntityMapper.mapEntityToDo(entity)
(entity: MediaSchoolLicenseEntity): MediaSchoolLicense => MediaSchoolLicenseEntityMapper.mapEntityToDO(entity)
);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class MediaSchoolLicenseMikroOrmRepo
}

private mapEntityToDomainObject(entity: MediaSchoolLicenseEntity): MediaSchoolLicense {
const schoolLicense: MediaSchoolLicense = MediaSchoolLicenseEntityMapper.mapEntityToDo(entity);
const schoolLicense: MediaSchoolLicense = MediaSchoolLicenseEntityMapper.mapEntityToDO(entity);

return schoolLicense;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { BaseFactory, schoolEntityFactory } from '@shared/testing';
import { mediaSourceEntityFactory } from '@src/modules/media-source/testing/media-source-entity.factory';
import { MediaSchoolLicenseEntity } from '../entity';
import { mediaSourceEntityFactory } from '@modules/media-source/testing';
import { ObjectId } from '@mikro-orm/mongodb';
import { MediaSchoolLicenseEntity, MediaSchoolLicenseEntityProps } from '../entity';
import { SchoolLicenseType } from '../enum';
import { MediaSchoolLicenseEntityProps } from '../entity/media-school-license.entity';

export const mediaSchoolLicenseEntityFactory = BaseFactory.define<
MediaSchoolLicenseEntity,
MediaSchoolLicenseEntityProps
>(MediaSchoolLicenseEntity, ({ sequence }) => {
return {
id: new ObjectId().toHexString(),
school: schoolEntityFactory.build(),
type: SchoolLicenseType.MEDIA_LICENSE,
mediumId: `medium-${sequence}`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ObjectId } from '@mikro-orm/mongodb';
import { BaseFactory } from '@shared/testing';
import { mediaSourceFactory } from '@src/modules/media-source/testing/media-source.factory';
import { MediaSchoolLicense } from '../domain';
import { MediaSchoolLicenseProps } from '../domain/media-school-license';
import { mediaSourceFactory } from '@modules/media-source/testing';
import { MediaSchoolLicense, MediaSchoolLicenseProps } from '../domain';
import { SchoolLicenseType } from '../enum';

export const mediaSchoolLicenseFactory = BaseFactory.define<MediaSchoolLicense, MediaSchoolLicenseProps>(
Expand Down

0 comments on commit b88a030

Please sign in to comment.