From fad10e972bbd76351ff048ebdd727ddd3cd725c2 Mon Sep 17 00:00:00 2001 From: Maksim Chervonnyi Date: Fri, 17 May 2024 19:00:29 +0200 Subject: [PATCH] add tests --- .../Preview/loaders/useSignObjectUrls.spec.ts | 35 ++++++++++++++++++- .../Preview/loaders/useSignObjectUrls.ts | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/catalog/app/components/Preview/loaders/useSignObjectUrls.spec.ts b/catalog/app/components/Preview/loaders/useSignObjectUrls.spec.ts index a2e5ed511f6..ae525e6de1f 100644 --- a/catalog/app/components/Preview/loaders/useSignObjectUrls.spec.ts +++ b/catalog/app/components/Preview/loaders/useSignObjectUrls.spec.ts @@ -3,7 +3,11 @@ import * as R from 'ramda' import type * as Model from 'model' import type { JsonRecord } from 'utils/types' -import { createObjectUrlsSigner, createUrlProcessor } from './useSignObjectUrls' +import { + createObjectUrlsSigner, + createPathResolver, + createUrlProcessor, +} from './useSignObjectUrls' describe('components/Preview/loaders/useSignObjectUrls', () => { describe('createObjectUrlsSigner', () => { @@ -79,4 +83,33 @@ describe('components/Preview/loaders/useSignObjectUrls', () => { ) }) }) + + describe('createPathResolver', () => { + test('Join keys if no logical key', () => { + const resolveKey = (key: string) => ({ + bucket: 'foo/bar', + key: `CCC/${key}`, + }) + let resolve = createPathResolver(resolveKey, { bucket: 'foo/bar', key: 'AAA/' }) + expect(resolve('BBB')).resolves.toEqual({ + bucket: 'foo/bar', + key: 'AAA/BBB', + }) + }) + test('Resovle logical key', () => { + const resolveLogicalKey = (key: string) => ({ + bucket: 'foo/bar', + key: `CCC/${key}`, + }) + let resolve = createPathResolver(resolveLogicalKey, { + bucket: 'foo/bar', + key: 'AAA/', + logicalKey: 'AAA/', + }) + expect(resolve('BBB')).resolves.toEqual({ + bucket: 'foo/bar', + key: 'CCC/AAA/BBB', + }) + }) + }) }) diff --git a/catalog/app/components/Preview/loaders/useSignObjectUrls.ts b/catalog/app/components/Preview/loaders/useSignObjectUrls.ts index 803377b6e25..f8c37984d2b 100644 --- a/catalog/app/components/Preview/loaders/useSignObjectUrls.ts +++ b/catalog/app/components/Preview/loaders/useSignObjectUrls.ts @@ -10,7 +10,7 @@ import type { JsonRecord } from 'utils/types' import { PreviewError } from '../types' -const createPathResolver = ( +export const createPathResolver = ( resolveLogicalKey: LogicalKeyResolver.LogicalKeyResolver | null, handle: LogicalKeyResolver.S3SummarizeHandle, ): ((path: string) => Promise) =>