@@ -6,17 +6,20 @@ import { HotswapMode } from '../../../lib/api/hotswap/common';
6
6
let hotswapMockSdkProvider : setup . HotswapMockSdkProvider ;
7
7
let mockUpdateResolver : ( params : AppSync . UpdateResolverRequest ) => AppSync . UpdateResolverResponse ;
8
8
let mockUpdateFunction : ( params : AppSync . UpdateFunctionRequest ) => AppSync . UpdateFunctionResponse ;
9
+ let mockUpdateApiKey : ( params : AppSync . UpdateApiKeyRequest ) => AppSync . UpdateApiKeyResponse ;
9
10
let mockStartSchemaCreation : ( params : AppSync . StartSchemaCreationRequest ) => AppSync . StartSchemaCreationResponse ;
10
11
let mockS3GetObject : ( params : S3 . GetObjectRequest ) => S3 . GetObjectOutput ;
11
12
12
13
beforeEach ( ( ) => {
13
14
hotswapMockSdkProvider = setup . setupHotswapTests ( ) ;
14
15
mockUpdateResolver = jest . fn ( ) ;
15
16
mockUpdateFunction = jest . fn ( ) ;
17
+ mockUpdateApiKey = jest . fn ( ) ;
16
18
mockStartSchemaCreation = jest . fn ( ) ;
17
19
hotswapMockSdkProvider . stubAppSync ( {
18
20
updateResolver : mockUpdateResolver ,
19
21
updateFunction : mockUpdateFunction ,
22
+ updateApiKey : mockUpdateApiKey ,
20
23
startSchemaCreation : mockStartSchemaCreation ,
21
24
} ) ;
22
25
@@ -568,6 +571,127 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
568
571
} ) ;
569
572
} ) ;
570
573
574
+ test ( 'calls the updateFunction() API with function version when it receives both function version and runtime with a mapping template in a Function' , async ( ) => {
575
+ // GIVEN
576
+ const mockListFunctions = jest . fn ( ) . mockReturnValue ( { functions : [ { name : 'my-function' , functionId : 'functionId' } ] } ) ;
577
+ hotswapMockSdkProvider . stubAppSync ( { listFunctions : mockListFunctions , updateFunction : mockUpdateFunction } ) ;
578
+
579
+ setup . setCurrentCfnStackTemplate ( {
580
+ Resources : {
581
+ AppSyncFunction : {
582
+ Type : 'AWS::AppSync::FunctionConfiguration' ,
583
+ Properties : {
584
+ Name : 'my-function' ,
585
+ ApiId : 'apiId' ,
586
+ DataSourceName : 'my-datasource' ,
587
+ FunctionVersion : '2018-05-29' ,
588
+ Runtime : 'APPSYNC_JS' ,
589
+ RequestMappingTemplate : '## original request template' ,
590
+ ResponseMappingTemplate : '## original response template' ,
591
+ } ,
592
+ Metadata : {
593
+ 'aws:asset:path' : 'old-path' ,
594
+ } ,
595
+ } ,
596
+ } ,
597
+ } ) ;
598
+ const cdkStackArtifact = setup . cdkStackArtifactOf ( {
599
+ template : {
600
+ Resources : {
601
+ AppSyncFunction : {
602
+ Type : 'AWS::AppSync::FunctionConfiguration' ,
603
+ Properties : {
604
+ Name : 'my-function' ,
605
+ ApiId : 'apiId' ,
606
+ DataSourceName : 'my-datasource' ,
607
+ FunctionVersion : '2018-05-29' ,
608
+ Runtime : 'APPSYNC_JS' ,
609
+ RequestMappingTemplate : '## original request template' ,
610
+ ResponseMappingTemplate : '## new response template' ,
611
+ } ,
612
+ Metadata : {
613
+ 'aws:asset:path' : 'new-path' ,
614
+ } ,
615
+ } ,
616
+ } ,
617
+ } ,
618
+ } ) ;
619
+
620
+ // WHEN
621
+ const deployStackResult = await hotswapMockSdkProvider . tryHotswapDeployment ( hotswapMode , cdkStackArtifact ) ;
622
+
623
+ // THEN
624
+ expect ( deployStackResult ) . not . toBeUndefined ( ) ;
625
+ expect ( mockUpdateFunction ) . toHaveBeenCalledWith ( {
626
+ apiId : 'apiId' ,
627
+ dataSourceName : 'my-datasource' ,
628
+ functionId : 'functionId' ,
629
+ functionVersion : '2018-05-29' ,
630
+ name : 'my-function' ,
631
+ requestMappingTemplate : '## original request template' ,
632
+ responseMappingTemplate : '## new response template' ,
633
+ } ) ;
634
+ } ) ;
635
+
636
+ test ( 'calls the updateFunction() API with runtime when it receives both function version and runtime with code in a Function' , async ( ) => {
637
+ // GIVEN
638
+ const mockListFunctions = jest . fn ( ) . mockReturnValue ( { functions : [ { name : 'my-function' , functionId : 'functionId' } ] } ) ;
639
+ hotswapMockSdkProvider . stubAppSync ( { listFunctions : mockListFunctions , updateFunction : mockUpdateFunction } ) ;
640
+
641
+ setup . setCurrentCfnStackTemplate ( {
642
+ Resources : {
643
+ AppSyncFunction : {
644
+ Type : 'AWS::AppSync::FunctionConfiguration' ,
645
+ Properties : {
646
+ Name : 'my-function' ,
647
+ ApiId : 'apiId' ,
648
+ DataSourceName : 'my-datasource' ,
649
+ FunctionVersion : '2018-05-29' ,
650
+ Runtime : 'APPSYNC_JS' ,
651
+ Code : 'old test code' ,
652
+ } ,
653
+ Metadata : {
654
+ 'aws:asset:path' : 'old-path' ,
655
+ } ,
656
+ } ,
657
+ } ,
658
+ } ) ;
659
+ const cdkStackArtifact = setup . cdkStackArtifactOf ( {
660
+ template : {
661
+ Resources : {
662
+ AppSyncFunction : {
663
+ Type : 'AWS::AppSync::FunctionConfiguration' ,
664
+ Properties : {
665
+ Name : 'my-function' ,
666
+ ApiId : 'apiId' ,
667
+ DataSourceName : 'my-datasource' ,
668
+ FunctionVersion : '2018-05-29' ,
669
+ Runtime : 'APPSYNC_JS' ,
670
+ Code : 'new test code' ,
671
+ } ,
672
+ Metadata : {
673
+ 'aws:asset:path' : 'new-path' ,
674
+ } ,
675
+ } ,
676
+ } ,
677
+ } ,
678
+ } ) ;
679
+
680
+ // WHEN
681
+ const deployStackResult = await hotswapMockSdkProvider . tryHotswapDeployment ( hotswapMode , cdkStackArtifact ) ;
682
+
683
+ // THEN
684
+ expect ( deployStackResult ) . not . toBeUndefined ( ) ;
685
+ expect ( mockUpdateFunction ) . toHaveBeenCalledWith ( {
686
+ apiId : 'apiId' ,
687
+ dataSourceName : 'my-datasource' ,
688
+ functionId : 'functionId' ,
689
+ runtime : 'APPSYNC_JS' ,
690
+ name : 'my-function' ,
691
+ code : 'new test code' ,
692
+ } ) ;
693
+ } ) ;
694
+
571
695
test ( 'calls the updateFunction() API when it receives only a mapping template s3 location difference in a Function' , async ( ) => {
572
696
// GIVEN
573
697
mockS3GetObject = jest . fn ( ) . mockImplementation ( async ( ) => {
@@ -1032,4 +1156,110 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
1032
1156
apiId : 'apiId' ,
1033
1157
} ) ;
1034
1158
} ) ;
1159
+
1160
+ test ( 'calls the updateApiKey() API when it receives only a expires property difference in an AppSync ApiKey' , async ( ) => {
1161
+ // GIVEN
1162
+ setup . setCurrentCfnStackTemplate ( {
1163
+ Resources : {
1164
+ AppSyncApiKey : {
1165
+ Type : 'AWS::AppSync::ApiKey' ,
1166
+ Properties : {
1167
+ ApiId : 'apiId' ,
1168
+ Expires : 1000 ,
1169
+ Id : 'key-id' ,
1170
+ } ,
1171
+ Metadata : {
1172
+ 'aws:asset:path' : 'old-path' ,
1173
+ } ,
1174
+ } ,
1175
+ } ,
1176
+ } ) ;
1177
+ setup . pushStackResourceSummaries (
1178
+ setup . stackSummaryOf (
1179
+ 'AppSyncApiKey' ,
1180
+ 'AWS::AppSync::ApiKey' ,
1181
+ 'arn:aws:appsync:us-east-1:111111111111:apis/apiId/apikeys/api-key-id' ,
1182
+ ) ,
1183
+ ) ;
1184
+ const cdkStackArtifact = setup . cdkStackArtifactOf ( {
1185
+ template : {
1186
+ Resources : {
1187
+ AppSyncApiKey : {
1188
+ Type : 'AWS::AppSync::ApiKey' ,
1189
+ Properties : {
1190
+ ApiId : 'apiId' ,
1191
+ Expires : 1001 ,
1192
+ Id : 'key-id' ,
1193
+ } ,
1194
+ Metadata : {
1195
+ 'aws:asset:path' : 'new-path' ,
1196
+ } ,
1197
+ } ,
1198
+ } ,
1199
+ } ,
1200
+ } ) ;
1201
+
1202
+ // WHEN
1203
+ const deployStackResult = await hotswapMockSdkProvider . tryHotswapDeployment ( hotswapMode , cdkStackArtifact ) ;
1204
+
1205
+ // THEN
1206
+ expect ( deployStackResult ) . not . toBeUndefined ( ) ;
1207
+ expect ( mockUpdateApiKey ) . toHaveBeenCalledWith ( {
1208
+ apiId : 'apiId' ,
1209
+ expires : 1001 ,
1210
+ id : 'key-id' ,
1211
+ } ) ;
1212
+ } ) ;
1213
+
1214
+ test ( 'calls the updateApiKey() API when it receives only a expires property difference and no api-key-id in an AppSync ApiKey' , async ( ) => {
1215
+ // GIVEN
1216
+ setup . setCurrentCfnStackTemplate ( {
1217
+ Resources : {
1218
+ AppSyncApiKey : {
1219
+ Type : 'AWS::AppSync::ApiKey' ,
1220
+ Properties : {
1221
+ ApiId : 'apiId' ,
1222
+ Expires : 1000 ,
1223
+ } ,
1224
+ Metadata : {
1225
+ 'aws:asset:path' : 'old-path' ,
1226
+ } ,
1227
+ } ,
1228
+ } ,
1229
+ } ) ;
1230
+ setup . pushStackResourceSummaries (
1231
+ setup . stackSummaryOf (
1232
+ 'AppSyncApiKey' ,
1233
+ 'AWS::AppSync::ApiKey' ,
1234
+ 'arn:aws:appsync:us-east-1:111111111111:apis/apiId/apikeys/api-key-id' ,
1235
+ ) ,
1236
+ ) ;
1237
+ const cdkStackArtifact = setup . cdkStackArtifactOf ( {
1238
+ template : {
1239
+ Resources : {
1240
+ AppSyncApiKey : {
1241
+ Type : 'AWS::AppSync::ApiKey' ,
1242
+ Properties : {
1243
+ ApiId : 'apiId' ,
1244
+ Expires : 1001 ,
1245
+ } ,
1246
+ Metadata : {
1247
+ 'aws:asset:path' : 'new-path' ,
1248
+ } ,
1249
+ } ,
1250
+ } ,
1251
+ } ,
1252
+ } ) ;
1253
+
1254
+ // WHEN
1255
+ const deployStackResult = await hotswapMockSdkProvider . tryHotswapDeployment ( hotswapMode , cdkStackArtifact ) ;
1256
+
1257
+ // THEN
1258
+ expect ( deployStackResult ) . not . toBeUndefined ( ) ;
1259
+ expect ( mockUpdateApiKey ) . toHaveBeenCalledWith ( {
1260
+ apiId : 'apiId' ,
1261
+ expires : 1001 ,
1262
+ id : 'api-key-id' ,
1263
+ } ) ;
1264
+ } ) ;
1035
1265
} ) ;
0 commit comments