-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathgetUrl.test.ts
More file actions
79 lines (73 loc) · 2.25 KB
/
Copy pathgetUrl.test.ts
File metadata and controls
79 lines (73 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { getUrl as advancedGetUrl } from '../../../src/internals';
import { getUrl as getUrlInternal } from '../../../src/providers/s3/apis/internal/getUrl';
import { createMockAmplifyContext } from '../../testUtils/mockAmplifyContext';
jest.mock('../../../src/providers/s3/apis/internal/getUrl');
const mockedGetUrlInternal = jest.mocked(getUrlInternal);
const mockCtx = createMockAmplifyContext();
const MOCK_URL = new URL('https://s3.aws/mock-presigned-url');
const MOCK_DATE = new Date();
MOCK_DATE.setMonth(MOCK_DATE.getMonth() + 1);
describe('getUrl (internal)', () => {
beforeEach(() => {
mockedGetUrlInternal.mockResolvedValue({
url: MOCK_URL,
expiresAt: MOCK_DATE,
});
});
afterEach(() => {
jest.clearAllMocks();
});
it('should pass through advanced options to the internal getUrl', async () => {
const useAccelerateEndpoint = true;
const validateObjectExistence = false;
const expectedBucketOwner = '012345678901';
const expiresIn = 300; // seconds
const contentDisposition = 'inline; filename="example.jpg"';
const contentType = 'image/jpeg';
const bucket = { bucketName: 'bucket', region: 'us-east-1' };
const customEndpoint = 's3.dualstack.us-east-2.amazonaws.com';
const locationCredentialsProvider = async () => ({
credentials: {
accessKeyId: 'akid',
secretAccessKey: 'secret',
sessionToken: 'token',
expiration: new Date(),
},
});
const result = await advancedGetUrl(mockCtx, {
path: 'input/path/to/mock/object',
options: {
customEndpoint,
useAccelerateEndpoint,
bucket,
validateObjectExistence,
expiresIn,
contentDisposition,
contentType,
expectedBucketOwner,
locationCredentialsProvider,
},
});
expect(mockedGetUrlInternal).toHaveBeenCalledTimes(1);
expect(mockedGetUrlInternal).toHaveBeenCalledWith(mockCtx, {
path: 'input/path/to/mock/object',
options: {
customEndpoint,
useAccelerateEndpoint,
bucket,
validateObjectExistence,
expiresIn,
contentDisposition,
contentType,
expectedBucketOwner,
locationCredentialsProvider,
},
});
expect(result).toEqual({
url: MOCK_URL,
expiresAt: MOCK_DATE,
});
});
});