diff --git a/src/useCases/PreLoadUseCase.ts b/src/useCases/PreLoadUseCase.ts index 5f2b23ea..c6c5549f 100644 --- a/src/useCases/PreLoadUseCase.ts +++ b/src/useCases/PreLoadUseCase.ts @@ -17,10 +17,11 @@ export const PreLoadUseCase = (apiKey: ApiKey) => (body: PreLoadRequestBody): TE.TaskEither => { const input = { apiKey, body }; - const url = uploadToS3URL.href; + const baseURL = uploadToS3URL.href; const returned = body.map((req) => { // TODO: Move into an adapter const [key, secret] = [crypto.randomUUID(), crypto.randomUUID()]; + const url = `${baseURL}/${key}`; return makePreLoadResponse(key, secret, url, req); }); const output = onValidApiKey(apiKey)({ statusCode: 200 as const, returned }); diff --git a/src/useCases/__tests__/PreLoadUseCase.test.ts b/src/useCases/__tests__/PreLoadUseCase.test.ts new file mode 100644 index 00000000..4604636e --- /dev/null +++ b/src/useCases/__tests__/PreLoadUseCase.test.ts @@ -0,0 +1,37 @@ +import * as E from 'fp-ts/Either'; +import * as RA from 'fp-ts/ReadonlyArray'; +import { makeLogger } from '../../logger'; +import { PreLoadUseCase } from '../PreLoadUseCase'; +import { config } from '../../__tests__/data'; +import * as inMemory from '../../adapters/inMemory'; +import { pipe } from 'fp-ts/lib/function'; + +// TODO: Remove this hardcoded value; the valid api-key at some point will be taken from envs +const apiKey = 'key-value'; +const logger = makeLogger(); +const repository = inMemory.makeRepository(logger)([]); +const body = [ + { + preloadIdx: '0', + contentType: 'application/pdf', + sha256: 'sha-value', + }, +]; + +describe('PreLoadUseCase', () => { + it('should return the key into url for each elements', async () => { + const actual = await PreLoadUseCase(logger, config.server.uploadToS3URL, repository)(apiKey)(body)(); + const checkKey = pipe( + actual, + E.exists( + (element) => + element.statusCode === 200 && + pipe( + element.returned, + RA.every((_) => _.url.endsWith(_.key)) + ) + ) + ); + expect(checkKey).toBeTruthy(); + }); +});