Skip to content

Commit ad72d85

Browse files
add cache behavior support and updated tests
1 parent e2f0dd0 commit ad72d85

12 files changed

+791
-130
lines changed

__mocks__/aws-sdk.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,29 @@ const promisifyMock = (mockFn) => {
1010
const mockCreateDistribution = jest.fn()
1111
const mockCreateDistributionPromise = promisifyMock(mockCreateDistribution)
1212

13+
const mockUpdateDistribution = jest.fn()
14+
const mockUpdateDistributionPromise = promisifyMock(mockUpdateDistribution)
15+
1316
const mockGetDistributionConfig = jest.fn()
1417
const mockGetDistributionConfigPromise = promisifyMock(mockGetDistributionConfig)
1518

1619
const mockDeleteDistribution = jest.fn()
1720
const mockDeleteDistributionPromise = promisifyMock(mockDeleteDistribution)
1821

19-
jest.mock('aws-sdk', () => ({
20-
CloudFront: jest.fn(() => ({
21-
createDistribution: mockCreateDistribution,
22-
getDistributionConfig: mockGetDistributionConfig,
23-
deleteDistribution: mockDeleteDistribution
24-
}))
25-
}))
26-
2722
module.exports = {
2823
mockCreateDistribution,
24+
mockUpdateDistribution,
2925
mockGetDistributionConfig,
3026
mockDeleteDistribution,
3127
mockCreateDistributionPromise,
28+
mockUpdateDistributionPromise,
3229
mockGetDistributionConfigPromise,
33-
mockDeleteDistributionPromise
30+
mockDeleteDistributionPromise,
31+
32+
CloudFront: jest.fn(() => ({
33+
createDistribution: mockCreateDistribution,
34+
updateDistribution: mockUpdateDistribution,
35+
getDistributionConfig: mockGetDistributionConfig,
36+
deleteDistribution: mockDeleteDistribution
37+
}))
3438
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Input origin as a custom url creates distribution with custom url origin 1`] = `
4+
Object {
5+
"DistributionConfig": Object {
6+
"Aliases": Object {
7+
"Items": Array [],
8+
"Quantity": 0,
9+
},
10+
"CallerReference": "1566599541192",
11+
"Comment": "",
12+
"DefaultCacheBehavior": Object {
13+
"AllowedMethods": Object {
14+
"CachedMethods": Object {
15+
"Items": Array [
16+
"HEAD",
17+
"GET",
18+
],
19+
"Quantity": 2,
20+
},
21+
"Items": Array [
22+
"HEAD",
23+
"GET",
24+
],
25+
"Quantity": 2,
26+
},
27+
"Compress": false,
28+
"DefaultTTL": 86400,
29+
"FieldLevelEncryptionId": "",
30+
"ForwardedValues": Object {
31+
"Cookies": Object {
32+
"Forward": "none",
33+
},
34+
"Headers": Object {
35+
"Items": Array [],
36+
"Quantity": 0,
37+
},
38+
"QueryString": false,
39+
"QueryStringCacheKeys": Object {
40+
"Items": Array [],
41+
"Quantity": 0,
42+
},
43+
},
44+
"LambdaFunctionAssociations": Object {
45+
"Items": Array [],
46+
"Quantity": 0,
47+
},
48+
"MaxTTL": 31536000,
49+
"MinTTL": 0,
50+
"SmoothStreaming": false,
51+
"TargetOriginId": "mycustomorigin.com",
52+
"TrustedSigners": Object {
53+
"Enabled": false,
54+
"Items": Array [],
55+
"Quantity": 0,
56+
},
57+
"ViewerProtocolPolicy": "redirect-to-https",
58+
},
59+
"Enabled": true,
60+
"HttpVersion": "http2",
61+
"Origins": Object {
62+
"Items": Array [
63+
Object {
64+
"CustomOriginConfig": Object {
65+
"HTTPPort": 80,
66+
"HTTPSPort": 443,
67+
"OriginProtocolPolicy": "https-only",
68+
},
69+
"DomainName": "mycustomorigin.com",
70+
"Id": "mycustomorigin.com",
71+
},
72+
],
73+
"Quantity": 1,
74+
},
75+
"PriceClass": "PriceClass_All",
76+
},
77+
}
78+
`;
79+
80+
exports[`Input origin as a custom url updates distribution 1`] = `
81+
Object {
82+
"DistributionConfig": Object {
83+
"Enabled": true,
84+
"Origins": Object {
85+
"Items": Array [
86+
Object {
87+
"CustomOriginConfig": Object {
88+
"HTTPPort": 80,
89+
"HTTPSPort": 443,
90+
"OriginProtocolPolicy": "https-only",
91+
},
92+
"DomainName": "mycustomoriginupdated.com",
93+
"Id": "mycustomoriginupdated.com",
94+
},
95+
],
96+
"Quantity": 1,
97+
},
98+
},
99+
"Id": "distribution123",
100+
"IfMatch": "etag",
101+
}
102+
`;
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Input origin with path pattern creates distribution with custom url origin 1`] = `
4+
Object {
5+
"DistributionConfig": Object {
6+
"Aliases": Object {
7+
"Items": Array [],
8+
"Quantity": 0,
9+
},
10+
"CacheBehaviors": Object {
11+
"Items": Array [
12+
Object {
13+
"Compress": true,
14+
"ForwardedValues": Object {
15+
"Cookies": Object {
16+
"Forward": "all",
17+
},
18+
"QueryString": true,
19+
},
20+
"MinTTL": 10,
21+
"PathPattern": "/some/path",
22+
"TargetOriginId": "exampleorigin.com",
23+
"TrustedSigners": Object {
24+
"Enabled": false,
25+
},
26+
"ViewerProtocolPolicy": "https-only",
27+
},
28+
],
29+
"Quantity": 1,
30+
},
31+
"CallerReference": "1566599541192",
32+
"Comment": "",
33+
"DefaultCacheBehavior": Object {
34+
"AllowedMethods": Object {
35+
"CachedMethods": Object {
36+
"Items": Array [
37+
"HEAD",
38+
"GET",
39+
],
40+
"Quantity": 2,
41+
},
42+
"Items": Array [
43+
"HEAD",
44+
"GET",
45+
],
46+
"Quantity": 2,
47+
},
48+
"Compress": false,
49+
"DefaultTTL": 86400,
50+
"FieldLevelEncryptionId": "",
51+
"ForwardedValues": Object {
52+
"Cookies": Object {
53+
"Forward": "none",
54+
},
55+
"Headers": Object {
56+
"Items": Array [],
57+
"Quantity": 0,
58+
},
59+
"QueryString": false,
60+
"QueryStringCacheKeys": Object {
61+
"Items": Array [],
62+
"Quantity": 0,
63+
},
64+
},
65+
"LambdaFunctionAssociations": Object {
66+
"Items": Array [],
67+
"Quantity": 0,
68+
},
69+
"MaxTTL": 31536000,
70+
"MinTTL": 0,
71+
"SmoothStreaming": false,
72+
"TargetOriginId": "exampleorigin.com",
73+
"TrustedSigners": Object {
74+
"Enabled": false,
75+
"Items": Array [],
76+
"Quantity": 0,
77+
},
78+
"ViewerProtocolPolicy": "redirect-to-https",
79+
},
80+
"Enabled": true,
81+
"HttpVersion": "http2",
82+
"Origins": Object {
83+
"Items": Array [
84+
Object {
85+
"CustomOriginConfig": Object {
86+
"HTTPPort": 80,
87+
"HTTPSPort": 443,
88+
"OriginProtocolPolicy": "https-only",
89+
},
90+
"DomainName": "exampleorigin.com",
91+
"Id": "exampleorigin.com",
92+
},
93+
],
94+
"Quantity": 1,
95+
},
96+
"PriceClass": "PriceClass_All",
97+
},
98+
}
99+
`;
100+
101+
exports[`Input origin with path pattern updates distribution 1`] = `
102+
Object {
103+
"DistributionConfig": Object {
104+
"CacheBehaviors": Object {
105+
"Items": Array [
106+
Object {
107+
"Compress": true,
108+
"ForwardedValues": Object {
109+
"Cookies": Object {
110+
"Forward": "all",
111+
},
112+
"QueryString": true,
113+
},
114+
"MinTTL": 10,
115+
"PathPattern": "/some/other/path",
116+
"TargetOriginId": "exampleorigin.com",
117+
"TrustedSigners": Object {
118+
"Enabled": false,
119+
},
120+
"ViewerProtocolPolicy": "https-only",
121+
},
122+
],
123+
"Quantity": 1,
124+
},
125+
"Enabled": true,
126+
"Origins": Object {
127+
"Items": Array [
128+
Object {
129+
"CustomOriginConfig": Object {
130+
"HTTPPort": 80,
131+
"HTTPSPort": 443,
132+
"OriginProtocolPolicy": "https-only",
133+
},
134+
"DomainName": "exampleorigin.com",
135+
"Id": "exampleorigin.com",
136+
},
137+
],
138+
"Quantity": 1,
139+
},
140+
},
141+
"Id": "xyz",
142+
"IfMatch": "etag",
143+
}
144+
`;
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Input origin as an S3 bucket url creates distribution with S3 origin 1`] = `
4+
Object {
5+
"DistributionConfig": Object {
6+
"Aliases": Object {
7+
"Items": Array [],
8+
"Quantity": 0,
9+
},
10+
"CallerReference": "1566599541192",
11+
"Comment": "",
12+
"DefaultCacheBehavior": Object {
13+
"AllowedMethods": Object {
14+
"CachedMethods": Object {
15+
"Items": Array [
16+
"HEAD",
17+
"GET",
18+
],
19+
"Quantity": 2,
20+
},
21+
"Items": Array [
22+
"HEAD",
23+
"GET",
24+
],
25+
"Quantity": 2,
26+
},
27+
"Compress": false,
28+
"DefaultTTL": 86400,
29+
"FieldLevelEncryptionId": "",
30+
"ForwardedValues": Object {
31+
"Cookies": Object {
32+
"Forward": "none",
33+
},
34+
"Headers": Object {
35+
"Items": Array [],
36+
"Quantity": 0,
37+
},
38+
"QueryString": false,
39+
"QueryStringCacheKeys": Object {
40+
"Items": Array [],
41+
"Quantity": 0,
42+
},
43+
},
44+
"LambdaFunctionAssociations": Object {
45+
"Items": Array [],
46+
"Quantity": 0,
47+
},
48+
"MaxTTL": 31536000,
49+
"MinTTL": 0,
50+
"SmoothStreaming": false,
51+
"TargetOriginId": "mybucket",
52+
"TrustedSigners": Object {
53+
"Enabled": false,
54+
"Items": Array [],
55+
"Quantity": 0,
56+
},
57+
"ViewerProtocolPolicy": "redirect-to-https",
58+
},
59+
"Enabled": true,
60+
"HttpVersion": "http2",
61+
"Origins": Object {
62+
"Items": Array [
63+
Object {
64+
"DomainName": "mybucket.s3.amazonaws.com",
65+
"Id": "mybucket",
66+
"S3OriginConfig": Object {
67+
"OriginAccessIdentity": "",
68+
},
69+
},
70+
],
71+
"Quantity": 1,
72+
},
73+
"PriceClass": "PriceClass_All",
74+
},
75+
}
76+
`;
77+
78+
exports[`Input origin as an S3 bucket url updates distribution 1`] = `
79+
Object {
80+
"DistributionConfig": Object {
81+
"Enabled": true,
82+
"Origins": Object {
83+
"Items": Array [
84+
Object {
85+
"DomainName": "anotherbucket.s3.amazonaws.com",
86+
"Id": "anotherbucket",
87+
"S3OriginConfig": Object {
88+
"OriginAccessIdentity": "",
89+
},
90+
},
91+
],
92+
"Quantity": 1,
93+
},
94+
},
95+
"Id": "distributionwithS3origin",
96+
"IfMatch": "etag",
97+
}
98+
`;

0 commit comments

Comments
 (0)