@@ -106,14 +106,14 @@ const genEvent = (reqHost: string, env: any) => ({
106106} )
107107
108108describe ( 'origin selector' , ( ) => {
109- it ( 'should select the origin based on the req-host and env headers' , async ( ) => {
109+ it ( 'should select a domain-mapped origin based on the req-host and env headers' , async ( ) => {
110110 const env = {
111111 domainMapping : {
112112 'example.org' : {
113- domain : 'somewhere.org' ,
113+ destination : 'somewhere.org' ,
114114 } ,
115115 'example.com' : {
116- domain : 'somewhere.com' ,
116+ destination : 'somewhere.com' ,
117117 } ,
118118 } ,
119119 }
@@ -131,4 +131,26 @@ describe('origin selector', () => {
131131 expect ( result2 . origin . custom ?. domainName ) . toBe ( 'somewhere.com' )
132132 expect ( result2 . headers [ 'host' ] [ 0 ] . value ) . toBe ( 'somewhere.com' )
133133 } )
134+
135+ it ( 'should select a domain-mapped origin based on the req-host and env headers' , async ( ) => {
136+ const env = {
137+ domainMapping : {
138+ 'example.org' : 'somewhere.org' ,
139+ 'example.com' : 'somewhere.com' ,
140+ } ,
141+ }
142+ const result = await handler ( genEvent ( 'example.org' , env ) as any )
143+ if ( ! result . origin ) {
144+ throw new Error ( 'no origin on result' )
145+ }
146+ expect ( result . origin . custom ?. domainName ) . toBe ( 'somewhere.org' )
147+ expect ( result . headers [ 'host' ] [ 0 ] . value ) . toBe ( 'somewhere.org' )
148+
149+ const result2 = await handler ( genEvent ( 'example.com' , env ) as any )
150+ if ( ! result2 . origin ) {
151+ throw new Error ( 'no origin on result' )
152+ }
153+ expect ( result2 . origin . custom ?. domainName ) . toBe ( 'somewhere.com' )
154+ expect ( result2 . headers [ 'host' ] [ 0 ] . value ) . toBe ( 'somewhere.com' )
155+ } )
134156} )
0 commit comments