@@ -33,7 +33,8 @@ describe('patchLetters API Handler', () => {
3333 const event = makeApiGwEvent ( {
3434 path : '/letters/id1' ,
3535 body : requestBody ,
36- pathParameters : { id : "id1" } } ) ;
36+ pathParameters : { id : "id1" } ,
37+ headers : { 'app-supplier-id' : 'supplier1' } } ) ;
3738 const context = mockDeep < Context > ( ) ;
3839 const callback = jest . fn ( ) ;
3940
@@ -51,7 +52,8 @@ describe('patchLetters API Handler', () => {
5152 it ( 'returns 400 Bad Request as there is no body' , async ( ) => {
5253 const event = makeApiGwEvent ( {
5354 path : '/letters/id1' ,
54- pathParameters : { id : "id1" } } ) ;
55+ pathParameters : { id : "id1" } ,
56+ headers : { 'app-supplier-id' : 'supplier1' } } ) ;
5557 const context = mockDeep < Context > ( ) ;
5658 const callback = jest . fn ( ) ;
5759 const result = await patchLetters ( event , context , callback ) ;
@@ -66,7 +68,8 @@ describe('patchLetters API Handler', () => {
6668 const event = makeApiGwEvent ( {
6769 path : '/unknown' ,
6870 body : requestBody ,
69- pathParameters : { id : "id1" } } ) ;
71+ pathParameters : { id : "id1" } ,
72+ headers : { 'app-supplier-id' : 'supplier1' } } ) ;
7073 const context = mockDeep < Context > ( ) ;
7174 const callback = jest . fn ( ) ;
7275 const result = await patchLetters ( event , context , callback ) ;
@@ -80,7 +83,8 @@ describe('patchLetters API Handler', () => {
8083 it ( 'returns 404 Not Found as path parameter is not found' , async ( ) => {
8184 const event = makeApiGwEvent ( {
8285 path : '/letters' ,
83- body : requestBody } ) ;
86+ body : requestBody ,
87+ headers : { 'app-supplier-id' : 'supplier1' } } ) ;
8488 const context = mockDeep < Context > ( ) ;
8589 const callback = jest . fn ( ) ;
8690 const result = await patchLetters ( event , context , callback ) ;
@@ -98,7 +102,8 @@ describe('patchLetters API Handler', () => {
98102 const event = makeApiGwEvent ( {
99103 path : '/letters/id1' ,
100104 body : requestBody ,
101- pathParameters : { id : "id1" }
105+ pathParameters : { id : "id1" } ,
106+ headers : { 'app-supplier-id' : 'supplier1' }
102107 } ) ;
103108 const context = mockDeep < Context > ( ) ;
104109 const callback = jest . fn ( ) ;
@@ -118,7 +123,8 @@ describe('patchLetters API Handler', () => {
118123 const event = makeApiGwEvent ( {
119124 path : '/letters/id1' ,
120125 body : requestBody ,
121- pathParameters : { id : "id1" }
126+ pathParameters : { id : "id1" } ,
127+ headers : { 'app-supplier-id' : 'supplier1' }
122128 } ) ;
123129 const context = mockDeep < Context > ( ) ;
124130 const callback = jest . fn ( ) ;
@@ -138,11 +144,27 @@ describe('patchLetters API Handler', () => {
138144 const event = makeApiGwEvent ( {
139145 path : '/letters/id1' ,
140146 body : requestBody ,
141- pathParameters : { id : "id1" }
147+ pathParameters : { id : "id1" } ,
148+ headers : { 'app-supplier-id' : 'supplier1' }
142149 } ) ;
143150 const context = mockDeep < Context > ( ) ;
144151 const callback = jest . fn ( ) ;
145152
146153 await expect ( patchLetters ( event , context , callback ) ) . rejects . toThrow ( 'Unexpected error' ) ;
147154 } ) ;
155+
156+ it ( 'returns 400 Bad Request: Missing supplier ID if header app-supplier-id ' , async ( ) => {
157+ const event = makeApiGwEvent ( {
158+ path : '/letters/id1' ,
159+ body : requestBody ,
160+ pathParameters : { id : "id1" } } ) ;
161+ const context = mockDeep < Context > ( ) ;
162+ const callback = jest . fn ( ) ;
163+ const result = await patchLetters ( event , context , callback ) ;
164+
165+ expect ( result ) . toEqual ( {
166+ statusCode : 400 ,
167+ body : 'Bad Request: Missing supplier ID' ,
168+ } ) ;
169+ } ) ;
148170} ) ;
0 commit comments