Skip to content

Commit

Permalink
Merge branch 'THR-18-dev-feature-h5p-editor' of https://github.com/hp…
Browse files Browse the repository at this point in the history
…i-schul-cloud/schulcloud-server into THR-18-dev-feature-h5p-editor
  • Loading branch information
MajedAlaitwniCap committed Nov 1, 2023
2 parents 24f27a5 + bcffb77 commit 49899a9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Readable } from 'stream';

import { HeadObjectCommandOutput, ServiceOutputTypes } from '@aws-sdk/client-s3';
import { DeepMocked, createMock } from '@golevelup/ts-jest';
import { ILibraryMetadata, ILibraryName } from '@lumieducation/h5p-server';
import { H5pError, ILibraryMetadata, ILibraryName, LibraryName } from '@lumieducation/h5p-server';

Check failure on line 5 in apps/server/src/modules/h5p-editor/service/libraryStorage.service.spec.ts

View workflow job for this annotation

GitHub Actions / nest_lint

'LibraryName' is defined but never used
import { NotFoundException } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';

Expand Down Expand Up @@ -458,6 +458,35 @@ describe('LibraryStorage', () => {
});
});

describe('getLibraryFile', () => {
describe('when getting library.json file', () => {
const setup = async (addLibrary = true) => {
const {
names: { testingLib },
} = createTestData();

if (addLibrary) {
await storage.addLibrary(testingLib, false);
}
const ubername = 'testing-1.2';
const file = 'library.json';

return { testingLib, file, ubername };
};

it('should return library.json file', async () => {
const { testingLib, file, ubername } = await setup();
repo.findOneByNameAndVersionOrFail.mockResolvedValueOnce(testingLib);

const result = await storage.getLibraryFile(ubername, file);

expect(result).toBeDefined();
expect(result.mimetype).toBeDefined();
expect(result.mimetype).toEqual('application/json');
});
});
});

describe('When getting library dependencies', () => {
const setup = async () => {
const { libraries, names } = createTestData();
Expand Down Expand Up @@ -566,6 +595,22 @@ describe('LibraryStorage', () => {
})
);
});

describe('when s3 upload error', () => {
it('should throw H5P Error', async () => {
const { testingLib } = await setup();
const filename = 'test/abc.json';

s3ClientAdapter.create.mockImplementationOnce(() => {
throw Error('S3 Exception');
});

const addFile = () => storage.addFile(testingLib, filename, Readable.from(Buffer.from('')));
return expect(addFile).rejects.toThrow(
new H5pError(`mongo-s3-library-storage:s3-upload-error (ubername: testing-1.2, filename: test/abc.json)`)
);
});
});
});

it('should list all files', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
type ILibraryName,
type ILibraryStorage,
} from '@lumieducation/h5p-server';
import { ConflictException, Inject, Injectable, NotAcceptableException, NotFoundException } from '@nestjs/common';
import { ConflictException, Inject, Injectable, NotFoundException } from '@nestjs/common';
import { S3ClientAdapter } from '@shared/infra/s3-client';
import mime from 'mime';
import path from 'node:path/posix';
Expand Down Expand Up @@ -405,10 +405,6 @@ export class LibraryStorage implements ILibraryStorage {
}

private async getMetadata(library: ILibraryName): Promise<ILibraryMetadata> {
if (!library) {
throw new NotAcceptableException('You must pass in a library name to getLibrary.');
}

const result = await this.libraryRepo.findOneByNameAndVersionOrFail(
library.machineName,
library.majorVersion,
Expand Down

0 comments on commit 49899a9

Please sign in to comment.