Skip to content

Commit

Permalink
create library.repo.spec test setup and first test
Browse files Browse the repository at this point in the history
  • Loading branch information
casparneumann-cap committed Oct 26, 2023
1 parent 9d5f27e commit 3079af6
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions apps/server/src/modules/h5p-editor/repo/libary.repo.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { EntityManager } from '@mikro-orm/mongodb';
import { Test, TestingModule } from '@nestjs/testing';
import { cleanupCollections } from '@shared/testing';
import { MongoMemoryDatabaseModule } from '@shared/infra/database';

import { ILibraryMetadata } from '@lumieducation/h5p-server';
import { LibraryRepo } from './library.repo';
import { FileMetadata, InstalledLibrary } from '../entity';

describe('LibraryRepo', () => {
let module: TestingModule;
let libraryRepo: LibraryRepo;
let addonLib: InstalledLibrary;
let em: EntityManager;

beforeAll(async () => {
module = await Test.createTestingModule({
imports: [MongoMemoryDatabaseModule.forRoot({ entities: [InstalledLibrary] })],
providers: [LibraryRepo],
}).compile();
libraryRepo = module.get(LibraryRepo);
em = module.get(EntityManager);

const testingLibMetadata: ILibraryMetadata = {
runnable: false,
title: '',
patchVersion: 3,
machineName: 'testing',
majorVersion: 1,
minorVersion: 2,
};
const testingLib = new InstalledLibrary(testingLibMetadata);
testingLib.files.push(
new FileMetadata('file1', new Date(), 2),
new FileMetadata('file2', new Date(), 4),
new FileMetadata('file3', new Date(), 6)
);

const addonLibMetadata: ILibraryMetadata = {
runnable: false,
title: '',
patchVersion: 3,
machineName: 'addon',
majorVersion: 1,
minorVersion: 2,
};
addonLib = new InstalledLibrary(addonLibMetadata);
addonLib.addTo = { player: { machineNames: [testingLib.machineName] } };
});

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

afterEach(async () => {
await cleanupCollections(em);
});

it('should save a Library', async () => {
const saveSpy = jest.spyOn(libraryRepo, 'save').mockResolvedValueOnce(undefined);
await libraryRepo.createLibrary(addonLib);
expect(saveSpy).toHaveBeenCalledWith(addonLib);
saveSpy.mockRestore();
});
});

0 comments on commit 3079af6

Please sign in to comment.