forked from aws-amplify/amplify-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetUrl.test.ts
75 lines (69 loc) · 2.02 KB
/
getUrl.test.ts
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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { AmplifyClassV6 } from '@aws-amplify/core';
import { getUrl as advancedGetUrl } from '../../../src/internals';
import { getUrl as getUrlInternal } from '../../../src/providers/s3/apis/internal/getUrl';
jest.mock('../../../src/providers/s3/apis/internal/getUrl');
const mockedGetUrlInternal = jest.mocked(getUrlInternal);
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 expiresIn = 300; // seconds
const contentDisposition = 'inline; filename="example.jpg"';
const contentType = 'image/jpeg';
const bucket = { bucketName: 'bucket', region: 'us-east-1' };
const locationCredentialsProvider = async () => ({
credentials: {
accessKeyId: 'akid',
secretAccessKey: 'secret',
sessionToken: 'token',
expiration: new Date(),
},
});
const result = await advancedGetUrl({
path: 'input/path/to/mock/object',
options: {
useAccelerateEndpoint,
bucket,
validateObjectExistence,
expiresIn,
contentDisposition,
contentType,
locationCredentialsProvider,
},
});
expect(mockedGetUrlInternal).toHaveBeenCalledTimes(1);
expect(mockedGetUrlInternal).toHaveBeenCalledWith(
expect.any(AmplifyClassV6),
{
path: 'input/path/to/mock/object',
options: {
useAccelerateEndpoint,
bucket,
validateObjectExistence,
expiresIn,
contentDisposition,
contentType,
locationCredentialsProvider,
},
},
);
expect(result).toEqual({
url: MOCK_URL,
expiresAt: MOCK_DATE,
});
});
});