Skip to content

Commit

Permalink
test createUrlProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
fiskus committed May 17, 2024
1 parent ae76554 commit 293bc35
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
31 changes: 30 additions & 1 deletion catalog/app/components/Preview/loaders/useSignObjectUrls.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as R from 'ramda'

import type * as Model from 'model'
import type { JsonRecord } from 'utils/types'

import { createObjectUrlsSigner } from './useSignObjectUrls'
import { createObjectUrlsSigner, createUrlProcessor } from './useSignObjectUrls'

describe('components/Preview/loaders/useSignObjectUrls', () => {
describe('createObjectUrlsSigner', () => {
Expand Down Expand Up @@ -50,4 +51,32 @@ describe('components/Preview/loaders/useSignObjectUrls', () => {
await expect(baz()).resolves.toBe('123456789')
})
})

describe('createUrlProcessor', () => {
let sign = ({ bucket, key, version }: Model.S3.S3ObjectLocation) =>
`https://${bucket}+${key}+${version}`
let resolvePath = async (path: string) => ({
bucket: 'resolved-bucket',
key: path,
})
let processUrl = createUrlProcessor(sign, resolvePath)
it('should return unsinged web', () => {
expect(processUrl('http://bucket/path')).resolves.toBe('http://bucket/path')
})
it('should return signed S3 URL', () => {
expect(processUrl('s3://bucket/path')).resolves.toBe(
'https://bucket+path+undefined',
)
})
it('should return signed S3 relative URL', () => {
expect(processUrl('s3://./relative/path')).resolves.toBe(
'https://resolved-bucket+./relative/path+undefined',
)
})
it('should return signed path', () => {
expect(processUrl('./relative/path')).resolves.toBe(
'https://resolved-bucket+./relative/path+undefined',
)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const createPathResolver = (
key: s3paths.resolveKey(handle.key, path),
})

const createUrlProcessor = (
export const createUrlProcessor = (
sign: (handle: Model.S3.S3ObjectLocation) => string,
resolvePath: (path: string) => Promise<Model.S3.S3ObjectLocation>,
) =>
Expand Down

0 comments on commit 293bc35

Please sign in to comment.