Skip to content

Commit

Permalink
N21-2103 fix tests and eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
GordonNicholasCap committed Dec 20, 2024
1 parent 2a12aa9 commit ab54ba5
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 23 deletions.
1 change: 1 addition & 0 deletions apps/server/src/infra/sync/media-licenses/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './service';
export * from './strategy';
export * from './vidis-sync-config';
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe(VidisFetchService.name, () => {

const encodedBasicAuth = btoa(`${decryptedUsername}:${decryptedPassword}`);
const expectedAxiosOptions: RawAxiosRequestConfig = {
headers: { Authorization: expect.stringMatching(`Basic ${encodedBasicAuth}`) },
headers: { Authorization: expect.stringMatching(`Basic ${encodedBasicAuth}`) as string },
};

expect(vidisApiClientMock.getActivatedOffersByRegion).toBeCalledWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe(VidisSyncService.name, () => {
});

describe('syncMediaSchoolLicenses', () => {
describe('when the vidis media source and school activation items are given', () => {
describe('when the vidis media source and activated offer items are given', () => {
describe('when the school activations provided does not exist in SVS', () => {
const setup = () => {
const mediaSource = mediaSourceFactory.build();
Expand All @@ -64,9 +64,7 @@ describe(VidisSyncService.name, () => {
schoolFactory.build({ officialSchoolNumber })
);

mediaSchoolLicenseService.findMediaSchoolLicensesByMediumId
.mockResolvedValueOnce([])
.mockResolvedValueOnce([]);
mediaSchoolLicenseService.findMediaSchoolLicensesByMediumId.mockResolvedValue([]);
schoolService.getSchoolByOfficialSchoolNumber
.mockResolvedValueOnce(schools[0])
.mockResolvedValueOnce(schools[1])
Expand Down Expand Up @@ -117,9 +115,7 @@ describe(VidisSyncService.name, () => {
mediaSource,
});

mediaSchoolLicenseService.findMediaSchoolLicensesByMediumId.mockResolvedValueOnce([
existingMediaSchoolLicense,
]);
mediaSchoolLicenseService.findMediaSchoolLicensesByMediumId.mockResolvedValue([existingMediaSchoolLicense]);
schoolService.getSchoolById.mockResolvedValueOnce(school);
schoolService.getSchoolByOfficialSchoolNumber.mockResolvedValue(school);

Expand All @@ -142,7 +138,7 @@ describe(VidisSyncService.name, () => {
describe('when the school has an official school number', () => {
const setup = () => {
const mediaSource = mediaSourceFactory.build();
const items: OfferDTO[] = vidisOfferItemFactory.buildList(2, { schoolActivations: [] });
const items: OfferDTO[] = vidisOfferItemFactory.buildList(1, { schoolActivations: [] });
const school = schoolFactory.build({ officialSchoolNumber: '00100' });

const mediumId = `${items[0].offerId as number}`;
Expand All @@ -152,9 +148,9 @@ describe(VidisSyncService.name, () => {
mediaSource,
});

mediaSchoolLicenseService.findMediaSchoolLicensesByMediumId.mockResolvedValueOnce([
existingMediaSchoolLicense,
]);
mediaSchoolLicenseService.findMediaSchoolLicensesByMediumId
.mockResolvedValueOnce([existingMediaSchoolLicense])
.mockResolvedValueOnce([]);
schoolService.getSchoolById.mockResolvedValueOnce(school);
schoolService.getSchoolByOfficialSchoolNumber.mockResolvedValue(school);

Expand All @@ -177,7 +173,7 @@ describe(VidisSyncService.name, () => {
describe('when the school does not have an official school number', () => {
const setup = () => {
const mediaSource = mediaSourceFactory.build();
const items: OfferDTO[] = vidisOfferItemFactory.buildList(2, { schoolActivations: [] });
const items: OfferDTO[] = vidisOfferItemFactory.buildList(1, { schoolActivations: [] });
const school = schoolFactory.build({ officialSchoolNumber: undefined });

const mediumId = `${items[0].offerId as number}`;
Expand All @@ -187,9 +183,9 @@ describe(VidisSyncService.name, () => {
mediaSource,
});

mediaSchoolLicenseService.findMediaSchoolLicensesByMediumId.mockResolvedValueOnce([
existingMediaSchoolLicense,
]);
mediaSchoolLicenseService.findMediaSchoolLicensesByMediumId
.mockResolvedValueOnce([existingMediaSchoolLicense])
.mockResolvedValueOnce([existingMediaSchoolLicense]);
schoolService.getSchoolById.mockResolvedValueOnce(school);
schoolService.getSchoolByOfficialSchoolNumber.mockResolvedValue(null);

Expand All @@ -215,7 +211,7 @@ describe(VidisSyncService.name, () => {
const missingSchoolNumbers = ['00100', '00200'];
const items: OfferDTO[] = vidisOfferItemFactory.buildList(1, { schoolActivations: missingSchoolNumbers });

mediaSchoolLicenseService.findMediaSchoolLicensesByMediumId.mockResolvedValueOnce([]);
mediaSchoolLicenseService.findMediaSchoolLicensesByMediumId.mockResolvedValue([]);
schoolService.getSchoolByOfficialSchoolNumber.mockResolvedValue(null);

return {
Expand Down Expand Up @@ -247,7 +243,7 @@ describe(VidisSyncService.name, () => {
schoolFactory.build({ officialSchoolNumber })
);

mediaSchoolLicenseService.findMediaSchoolLicensesByMediumId.mockResolvedValueOnce([]);
mediaSchoolLicenseService.findMediaSchoolLicensesByMediumId.mockResolvedValue([]);
schoolService.getSchoolByOfficialSchoolNumber
.mockResolvedValueOnce(schools[0])
.mockResolvedValueOnce(schools[1])
Expand Down Expand Up @@ -290,7 +286,7 @@ describe(VidisSyncService.name, () => {
schoolFactory.build({ officialSchoolNumber })
);

mediaSchoolLicenseService.findMediaSchoolLicensesByMediumId.mockResolvedValueOnce([]);
mediaSchoolLicenseService.findMediaSchoolLicensesByMediumId.mockResolvedValue([]);
schoolService.getSchoolByOfficialSchoolNumber
.mockResolvedValueOnce(schools[0])
.mockResolvedValueOnce(schools[1])
Expand Down Expand Up @@ -321,6 +317,48 @@ describe(VidisSyncService.name, () => {
await expect(promise).resolves.not.toThrow();
});
});

describe('when the offer item does not has school activations', () => {
const setup = () => {
const mediaSource = mediaSourceFactory.build();
const schoolActivations = undefined;
const items: OfferDTO[] = vidisOfferItemFactory.buildList(1, { schoolActivations });

return {
mediaSource,
items,
};
};

it('should skip the offer item', async () => {
const { mediaSource, items } = setup();

await service.syncMediaSchoolLicenses(mediaSource, items);

expect(mediaSchoolLicenseService.findMediaSchoolLicensesByMediumId).not.toHaveBeenCalled();
});
});

describe('when the offer item does not has a medium id', () => {
const setup = () => {
const mediaSource = mediaSourceFactory.build();
const schoolActivations = ['00100'];
const items: OfferDTO[] = vidisOfferItemFactory.buildList(1, { schoolActivations, offerId: undefined });

return {
mediaSource,
items,
};
};

it('should skip the offer item', async () => {
const { mediaSource, items } = setup();

await service.syncMediaSchoolLicenses(mediaSource, items);

expect(mediaSchoolLicenseService.findMediaSchoolLicensesByMediumId).not.toHaveBeenCalled();
});
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ export class VidisSyncService {
if (!school) {
this.logger.info(new SchoolForSchoolMediaLicenseSyncNotFoundLoggable(schoolNumber));
} else {
const isExistingLicense = !!existingLicenses.find(
const hasSchoolExistingLicense = existingLicenses.some(
(license: MediaSchoolLicense): boolean => license.schoolId === school.id
);
if (!isExistingLicense) {
if (!hasSchoolExistingLicense) {
const newLicense: MediaSchoolLicense = new MediaSchoolLicense({
id: new ObjectId().toHexString(),
type: SchoolLicenseType.MEDIA_LICENSE,
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/modules/server/server.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import type { MailConfig } from '@infra/mail/interfaces/mail-config';
import type { SchulconnexClientConfig } from '@infra/schulconnex-client';
import { TspSyncConfig } from '@infra/sync';
import type { TspClientConfig } from '@infra/tsp-client';
import { VidisClientConfig } from '@infra/vidis-client';
import { VidisSyncConfig } from '@infra/sync/media-licenses';
import type { AccountConfig } from '@modules/account';
import { AlertConfig } from '@modules/alert';
import type { AuthenticationConfig } from '@modules/authentication';
Expand All @@ -32,8 +34,6 @@ import { SchulcloudTheme } from '@shared/domain/types';
import type { CoreModuleConfig } from '@src/core';
import { Algorithm } from 'jsonwebtoken';
import type { Timezone } from './types/timezone.enum';
import { VidisClientConfig } from '@infra/vidis-client';
import { VidisSyncConfig } from '@infra/sync/media-licenses/vidis-sync-config';

export enum NodeEnvType {
TEST = 'test',
Expand Down

0 comments on commit ab54ba5

Please sign in to comment.