Skip to content

Commit

Permalink
fix saveFile mockImplementation
Browse files Browse the repository at this point in the history
  • Loading branch information
casparneumann-cap committed Nov 1, 2023
1 parent aef7727 commit 2d4c71d
Showing 1 changed file with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { ServiceOutputTypes } from '@aws-sdk/client-s3';
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { IUser } from '@lumieducation/h5p-server';
import { Test, TestingModule } from '@nestjs/testing';
import { S3ClientAdapter } from '@shared/infra/s3-client';
import { FileDto } from '@src/modules/files-storage/dto';
import { File, S3ClientAdapter } from '@shared/infra/s3-client';
import { GetFileResponse } from '@src/modules/files-storage/interface';
import { ReadStream } from 'fs';
import { Readable } from 'node:stream';
Expand Down Expand Up @@ -249,7 +248,6 @@ describe('TemporaryFileStorage', () => {
});
});
});

describe('saveFile is called', () => {
describe('WHEN file exists', () => {
it('should overwrite file', async () => {
Expand All @@ -259,7 +257,7 @@ describe('TemporaryFileStorage', () => {
const readStream = Readable.from(newData) as ReadStream;
repo.findByUserAndFilename.mockResolvedValueOnce(file1);
let savedData = Buffer.alloc(0);
s3clientAdapter.create.mockImplementation(async (path: string, file: FileDto) => {
s3clientAdapter.create.mockImplementation(async (path: string, file: File) => {
savedData += file.data.read();
return Promise.resolve({} as ServiceOutputTypes);
});
Expand All @@ -278,7 +276,7 @@ describe('TemporaryFileStorage', () => {
const newData = 'This is new fake H5P content.';
const readStream = Readable.from(newData) as ReadStream;
let savedData = Buffer.alloc(0);
s3clientAdapter.create.mockImplementation(async (path: string, file: FileDto) => {
s3clientAdapter.create.mockImplementation(async (path: string, file: File) => {
savedData += file.data.read();
return Promise.resolve({} as ServiceOutputTypes);
});
Expand Down

0 comments on commit 2d4c71d

Please sign in to comment.