1
+ import { countResources , expect as expectCDK } from "@aws-cdk/assert" ;
2
+ import { Certificate , DnsValidatedCertificate } from "@aws-cdk/aws-certificatemanager" ;
3
+ import { PublicHostedZone } from "@aws-cdk/aws-route53" ;
1
4
import { App , Stack } from "@aws-cdk/core" ;
2
5
import { DomainRedirect , REGION_ERROR_MESSAGE } from "../src/redirect" ;
3
- import { countResources , expect as expectCDK } from "@aws-cdk/assert" ;
4
-
5
- import { Certificate } from "@aws-cdk/aws-certificatemanager" ;
6
6
7
7
class TestApp {
8
8
public readonly stack : Stack ;
@@ -19,7 +19,7 @@ class TestApp {
19
19
}
20
20
21
21
describe ( "DomainRedirect" , ( ) : void => {
22
- let stack : Stack , fromLookup : jest . Mock , fromAlias : jest . Mock , fakeCert : Certificate ;
22
+ let stack : Stack , fromLookup : jest . Mock , fromAlias : jest . Mock ;
23
23
beforeEach ( ( ) => {
24
24
( { stack } = new TestApp ( ) ) ;
25
25
fromLookup = jest . fn ( ) ;
@@ -29,16 +29,13 @@ describe("DomainRedirect", (): void => {
29
29
fromLookup : fromLookup ,
30
30
} ,
31
31
AddressRecordTarget : {
32
- fromAlias : function ( ) : object {
32
+ fromAlias : function ( ) : Record < string , unknown > {
33
33
return {
34
34
bind : fromAlias ,
35
35
} ;
36
36
} ,
37
37
} ,
38
38
} ) ) ;
39
- fakeCert = new Certificate ( stack , "Certificate" , {
40
- domainName : "example.com" ,
41
- } ) ;
42
39
} ) ;
43
40
it ( "looks up an IHostedZone if a valid hostname is passed as a string to DomainOptions.zoneName" , function ( ) : void {
44
41
fromLookup . mockReturnValue ( {
@@ -67,6 +64,9 @@ describe("DomainRedirect", (): void => {
67
64
fromLookup . mockReturnValue ( {
68
65
zoneName : "example.com." ,
69
66
} ) ;
67
+ const fakeCert = new Certificate ( stack , "Certificate" , {
68
+ domainName : "example.com" ,
69
+ } ) ;
70
70
new DomainRedirect ( stack , "redirects" , {
71
71
zoneName : "example.com" ,
72
72
cert : fakeCert ,
@@ -79,19 +79,42 @@ describe("DomainRedirect", (): void => {
79
79
fromLookup . mockReturnValue ( {
80
80
zoneName : "example.com." ,
81
81
} ) ;
82
+ const fakeCert = new Certificate ( stack , "Certificate" , {
83
+ domainName : "example.com" ,
84
+ } ) ;
82
85
new DomainRedirect ( stack , "redirects" , {
83
86
zoneName : "example.com" ,
84
87
cert : fakeCert ,
85
88
target : "https://spencerbeg.gs" ,
86
89
hostnames : "foobar.example.com" ,
87
90
} ) ;
91
+ expectCDK ( stack ) . to ( countResources ( "AWS::CertificateManager::Certificate" , 1 ) ) ;
92
+ expectCDK ( stack ) . to ( countResources ( "AWS::S3::Bucket" , 1 ) ) ;
93
+ expectCDK ( stack ) . to ( countResources ( "AWS::CloudFront::Distribution" , 1 ) ) ;
94
+ } ) ;
95
+ it ( "accepts a DnsValidatedCertificate as a cert type" , function ( ) : void {
96
+ const exampleDotComZone = new PublicHostedZone ( stack , "ExampleDotCom" , {
97
+ zoneName : "example.com" ,
98
+ } ) ;
99
+ new DomainRedirect ( stack , "redirects" , {
100
+ zoneName : "example.com" ,
101
+ cert : new DnsValidatedCertificate ( stack , "DnsValidatedCertificate" , {
102
+ domainName : "test.example.com" ,
103
+ hostedZone : exampleDotComZone ,
104
+ } ) ,
105
+ target : "https://spencerbeg.gs" ,
106
+ hostnames : "foobar.example.com" ,
107
+ } ) ;
88
108
expectCDK ( stack ) . to ( countResources ( "AWS::S3::Bucket" , 1 ) ) ;
89
109
expectCDK ( stack ) . to ( countResources ( "AWS::CloudFront::Distribution" , 1 ) ) ;
90
110
} ) ;
91
111
it ( "passes through an array of strings for DomainOptions.hostnames" , function ( ) : void {
92
112
fromLookup . mockReturnValue ( {
93
113
zoneName : "example.com." ,
94
114
} ) ;
115
+ const fakeCert = new Certificate ( stack , "Certificate" , {
116
+ domainName : "example.com" ,
117
+ } ) ;
95
118
new DomainRedirect ( stack , "redirects" , {
96
119
zoneName : "example.com" ,
97
120
cert : fakeCert ,
@@ -105,6 +128,9 @@ describe("DomainRedirect", (): void => {
105
128
fromLookup . mockReturnValue ( {
106
129
zoneName : "example.com" ,
107
130
} ) ;
131
+ const fakeCert = new Certificate ( stack , "Certificate" , {
132
+ domainName : "example.com" ,
133
+ } ) ;
108
134
new DomainRedirect ( stack , "redirects" , {
109
135
zoneName : "example.com" ,
110
136
cert : fakeCert ,
@@ -114,6 +140,9 @@ describe("DomainRedirect", (): void => {
114
140
expectCDK ( stack ) . to ( countResources ( "AWS::CloudFront::Distribution" , 1 ) ) ;
115
141
} ) ;
116
142
it ( "accepts and array of DomainOptions" , ( ) => {
143
+ const fakeCert = new Certificate ( stack , "Certificate" , {
144
+ domainName : "example.com" ,
145
+ } ) ;
117
146
fromLookup
118
147
. mockReturnValueOnce ( {
119
148
zoneName : "domain1.com" ,
@@ -140,7 +169,9 @@ describe("DomainRedirect", (): void => {
140
169
fromLookup . mockReturnValueOnce ( {
141
170
zoneName : "example.com" ,
142
171
} ) ;
143
-
172
+ const fakeCert = new Certificate ( stack , "Certificate" , {
173
+ domainName : "example.com" ,
174
+ } ) ;
144
175
new DomainRedirect ( stack , "redirects" , {
145
176
zoneName : "domain1.com" ,
146
177
cert : fakeCert ,
@@ -157,7 +188,9 @@ describe("DomainRedirect", (): void => {
157
188
fromLookup . mockReturnValueOnce ( {
158
189
zoneName : "example.com" ,
159
190
} ) ;
160
-
191
+ const fakeCert = new Certificate ( stack , "Certificate" , {
192
+ domainName : "example.com" ,
193
+ } ) ;
161
194
new DomainRedirect ( stack , "redirects" , {
162
195
zoneName : "domain1.com" ,
163
196
cert : fakeCert ,
@@ -169,6 +202,9 @@ describe("DomainRedirect", (): void => {
169
202
} ) ;
170
203
it ( "it throws if you try to create a stack that is not in us-east-1" , ( ) => {
171
204
const { stack : stackInWrongRegion } = new TestApp ( "us-west-1" ) ;
205
+ const fakeCert = new Certificate ( stack , "Certificate" , {
206
+ domainName : "example.com" ,
207
+ } ) ;
172
208
const fn = ( ) : void => {
173
209
new DomainRedirect ( stackInWrongRegion , "redirects" , {
174
210
zoneName : "domain1.com" ,
0 commit comments