Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fiskus committed May 17, 2024
1 parent 293bc35 commit fad10e9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
35 changes: 34 additions & 1 deletion catalog/app/components/Preview/loaders/useSignObjectUrls.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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',
})
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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<LogicalKeyResolver.S3SummarizeHandle>) =>
Expand Down

0 comments on commit fad10e9

Please sign in to comment.