1
1
import * as path from 'path' ;
2
2
import { Template } from '@aws-cdk/assertions' ;
3
3
import * as es from '@aws-cdk/aws-elasticsearch' ;
4
- import { testDeprecated } from '@aws-cdk/cdk-build-tools' ;
4
+ import { describeDeprecated } from '@aws-cdk/cdk-build-tools' ;
5
5
import * as cdk from '@aws-cdk/core' ;
6
6
import * as appsync from '../lib' ;
7
7
8
8
// GLOBAL GIVEN
9
9
let stack : cdk . Stack ;
10
10
let api : appsync . GraphqlApi ;
11
11
let domain : es . Domain ;
12
- beforeEach ( ( ) => {
13
- stack = new cdk . Stack ( ) ;
14
- api = new appsync . GraphqlApi ( stack , 'baseApi' , {
15
- name : 'api' ,
16
- schema : appsync . Schema . fromAsset ( path . join ( __dirname , 'appsync.test.graphql' ) ) ,
17
- } ) ;
18
- domain = new es . Domain ( stack , 'EsDomain' , {
19
- version : es . ElasticsearchVersion . V7_10 ,
20
- } ) ;
21
- } ) ;
22
-
23
- describe ( 'Elasticsearch Data Source Configuration' , ( ) => {
24
- testDeprecated ( 'Elasticsearch configure properly' , ( ) => {
25
- // WHEN
26
- api . addElasticsearchDataSource ( 'ds' , domain ) ;
27
-
28
- // THEN
29
- Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::IAM::Policy' , {
30
- PolicyDocument : {
31
- Version : '2012-10-17' ,
32
- Statement : [ {
33
- Action : [
34
- 'es:ESHttpGet' ,
35
- 'es:ESHttpHead' ,
36
- 'es:ESHttpDelete' ,
37
- 'es:ESHttpPost' ,
38
- 'es:ESHttpPut' ,
39
- 'es:ESHttpPatch' ,
40
- ] ,
41
- Effect : 'Allow' ,
42
- Resource : [ {
43
- 'Fn::GetAtt' : [ 'EsDomain1213C634' , 'Arn' ] ,
44
- } ,
45
- {
46
- 'Fn::Join' : [ '' , [ {
47
- 'Fn::GetAtt' : [ 'EsDomain1213C634' , 'Arn' ] ,
48
- } , '/*' ] ] ,
49
- } ] ,
50
- } ] ,
51
- } ,
12
+
13
+ describeDeprecated ( 'Appsync Elasticsearch integration' , ( ) => {
14
+ beforeEach ( ( ) => {
15
+ stack = new cdk . Stack ( ) ;
16
+ api = new appsync . GraphqlApi ( stack , 'baseApi' , {
17
+ name : 'api' ,
18
+ schema : appsync . Schema . fromAsset ( path . join ( __dirname , 'appsync.test.graphql' ) ) ,
19
+ } ) ;
20
+ domain = new es . Domain ( stack , 'EsDomain' , {
21
+ version : es . ElasticsearchVersion . V7_10 ,
52
22
} ) ;
53
23
} ) ;
54
24
55
- testDeprecated ( 'Elastic search configuration contains fully qualified url' , ( ) => {
56
- // WHEN
57
- api . addElasticsearchDataSource ( 'ds' , domain ) ;
58
-
59
- // THEN
60
- Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::AppSync::DataSource' , {
61
- ElasticsearchConfig : {
62
- Endpoint : {
63
- 'Fn::Join' : [ '' , [ 'https://' , {
64
- 'Fn::GetAtt' : [ 'EsDomain1213C634' , 'DomainEndpoint' ] ,
65
- } ] ] ,
25
+ describe ( 'Elasticsearch Data Source Configuration' , ( ) => {
26
+ test ( 'Elasticsearch configure properly' , ( ) => {
27
+ // WHEN
28
+ api . addElasticsearchDataSource ( 'ds' , domain ) ;
29
+
30
+ // THEN
31
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::IAM::Policy' , {
32
+ PolicyDocument : {
33
+ Version : '2012-10-17' ,
34
+ Statement : [ {
35
+ Action : [
36
+ 'es:ESHttpGet' ,
37
+ 'es:ESHttpHead' ,
38
+ 'es:ESHttpDelete' ,
39
+ 'es:ESHttpPost' ,
40
+ 'es:ESHttpPut' ,
41
+ 'es:ESHttpPatch' ,
42
+ ] ,
43
+ Effect : 'Allow' ,
44
+ Resource : [ {
45
+ 'Fn::GetAtt' : [ 'EsDomain1213C634' , 'Arn' ] ,
46
+ } ,
47
+ {
48
+ 'Fn::Join' : [ '' , [ {
49
+ 'Fn::GetAtt' : [ 'EsDomain1213C634' , 'Arn' ] ,
50
+ } , '/*' ] ] ,
51
+ } ] ,
52
+ } ] ,
66
53
} ,
67
- } ,
54
+ } ) ;
68
55
} ) ;
69
- } ) ;
70
56
71
- testDeprecated ( 'default configuration produces name identical to the id ', ( ) => {
72
- // WHEN
73
- api . addElasticsearchDataSource ( 'ds' , domain ) ;
57
+ test ( 'Elastic search configuration contains fully qualified url ', ( ) => {
58
+ // WHEN
59
+ api . addElasticsearchDataSource ( 'ds' , domain ) ;
74
60
75
- // THEN
76
- Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::AppSync::DataSource' , {
77
- Type : 'AMAZON_ELASTICSEARCH' ,
78
- Name : 'ds' ,
61
+ // THEN
62
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::AppSync::DataSource' , {
63
+ ElasticsearchConfig : {
64
+ Endpoint : {
65
+ 'Fn::Join' : [ '' , [ 'https://' , {
66
+ 'Fn::GetAtt' : [ 'EsDomain1213C634' , 'DomainEndpoint' ] ,
67
+ } ] ] ,
68
+ } ,
69
+ } ,
70
+ } ) ;
79
71
} ) ;
80
- } ) ;
81
72
82
- testDeprecated ( 'appsync configures name correctly' , ( ) => {
83
- // WHEN
84
- api . addElasticsearchDataSource ( 'ds' , domain , {
85
- name : 'custom' ,
86
- } ) ;
73
+ test ( 'default configuration produces name identical to the id' , ( ) => {
74
+ // WHEN
75
+ api . addElasticsearchDataSource ( 'ds' , domain ) ;
87
76
88
- // THEN
89
- Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::AppSync::DataSource' , {
90
- Type : 'AMAZON_ELASTICSEARCH' ,
91
- Name : 'custom' ,
77
+ // THEN
78
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::AppSync::DataSource' , {
79
+ Type : 'AMAZON_ELASTICSEARCH' ,
80
+ Name : 'ds' ,
81
+ } ) ;
92
82
} ) ;
93
- } ) ;
94
83
95
- testDeprecated ( 'appsync configures name and description correctly' , ( ) => {
96
- // WHEN
97
- api . addElasticsearchDataSource ( 'ds' , domain , {
98
- name : 'custom' ,
99
- description : 'custom description' ,
84
+ test ( 'appsync configures name correctly' , ( ) => {
85
+ // WHEN
86
+ api . addElasticsearchDataSource ( 'ds' , domain , {
87
+ name : 'custom' ,
88
+ } ) ;
89
+
90
+ // THEN
91
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::AppSync::DataSource' , {
92
+ Type : 'AMAZON_ELASTICSEARCH' ,
93
+ Name : 'custom' ,
94
+ } ) ;
100
95
} ) ;
101
96
102
- // THEN
103
- Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::AppSync::DataSource' , {
104
- Type : 'AMAZON_ELASTICSEARCH' ,
105
- Name : 'custom' ,
106
- Description : 'custom description' ,
97
+ test ( 'appsync configures name and description correctly' , ( ) => {
98
+ // WHEN
99
+ api . addElasticsearchDataSource ( 'ds' , domain , {
100
+ name : 'custom' ,
101
+ description : 'custom description' ,
102
+ } ) ;
103
+
104
+ // THEN
105
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::AppSync::DataSource' , {
106
+ Type : 'AMAZON_ELASTICSEARCH' ,
107
+ Name : 'custom' ,
108
+ Description : 'custom description' ,
109
+ } ) ;
107
110
} ) ;
108
- } ) ;
109
111
110
- testDeprecated ( 'appsync errors when creating multiple elasticsearch data sources with no configuration' , ( ) => {
111
- // WHEN
112
- const when = ( ) => {
113
- api . addElasticsearchDataSource ( 'ds' , domain ) ;
114
- api . addElasticsearchDataSource ( 'ds' , domain ) ;
115
- } ;
116
-
117
- // THEN
118
- expect ( when ) . toThrow ( 'There is already a Construct with name \'ds\' in GraphqlApi [baseApi]' ) ;
119
- } ) ;
120
- } ) ;
121
-
122
- describe ( 'adding elasticsearch data source from imported api' , ( ) => {
123
- testDeprecated ( 'imported api can add ElasticsearchDataSource from id' , ( ) => {
124
- // WHEN
125
- const importedApi = appsync . GraphqlApi . fromGraphqlApiAttributes ( stack , 'importedApi' , {
126
- graphqlApiId : api . apiId ,
127
- } ) ;
128
- importedApi . addElasticsearchDataSource ( 'ds' , domain ) ;
112
+ test ( 'appsync errors when creating multiple elasticsearch data sources with no configuration' , ( ) => {
113
+ // WHEN
114
+ const when = ( ) => {
115
+ api . addElasticsearchDataSource ( 'ds' , domain ) ;
116
+ api . addElasticsearchDataSource ( 'ds' , domain ) ;
117
+ } ;
129
118
130
- // THEN
131
- Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::AppSync::DataSource' , {
132
- Type : 'AMAZON_ELASTICSEARCH' ,
133
- ApiId : { 'Fn::GetAtt' : [ 'baseApiCDA4D43A' , 'ApiId' ] } ,
119
+ // THEN
120
+ expect ( when ) . toThrow ( 'There is already a Construct with name \'ds\' in GraphqlApi [baseApi]' ) ;
134
121
} ) ;
135
122
} ) ;
136
123
137
- testDeprecated ( 'imported api can add ElasticsearchDataSource from attributes' , ( ) => {
138
- // WHEN
139
- const importedApi = appsync . GraphqlApi . fromGraphqlApiAttributes ( stack , 'importedApi' , {
140
- graphqlApiId : api . apiId ,
141
- graphqlApiArn : api . arn ,
124
+ describe ( 'adding elasticsearch data source from imported api' , ( ) => {
125
+ test ( 'imported api can add ElasticsearchDataSource from id' , ( ) => {
126
+ // WHEN
127
+ const importedApi = appsync . GraphqlApi . fromGraphqlApiAttributes ( stack , 'importedApi' , {
128
+ graphqlApiId : api . apiId ,
129
+ } ) ;
130
+ importedApi . addElasticsearchDataSource ( 'ds' , domain ) ;
131
+
132
+ // THEN
133
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::AppSync::DataSource' , {
134
+ Type : 'AMAZON_ELASTICSEARCH' ,
135
+ ApiId : { 'Fn::GetAtt' : [ 'baseApiCDA4D43A' , 'ApiId' ] } ,
136
+ } ) ;
142
137
} ) ;
143
- importedApi . addElasticsearchDataSource ( 'ds' , domain ) ;
144
138
145
- // THEN
146
- Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::AppSync::DataSource' , {
147
- Type : 'AMAZON_ELASTICSEARCH' ,
148
- ApiId : { 'Fn::GetAtt' : [ 'baseApiCDA4D43A' , 'ApiId' ] } ,
139
+ test ( 'imported api can add ElasticsearchDataSource from attributes' , ( ) => {
140
+ // WHEN
141
+ const importedApi = appsync . GraphqlApi . fromGraphqlApiAttributes ( stack , 'importedApi' , {
142
+ graphqlApiId : api . apiId ,
143
+ graphqlApiArn : api . arn ,
144
+ } ) ;
145
+ importedApi . addElasticsearchDataSource ( 'ds' , domain ) ;
146
+
147
+ // THEN
148
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::AppSync::DataSource' , {
149
+ Type : 'AMAZON_ELASTICSEARCH' ,
150
+ ApiId : { 'Fn::GetAtt' : [ 'baseApiCDA4D43A' , 'ApiId' ] } ,
151
+ } ) ;
149
152
} ) ;
150
153
} ) ;
151
154
} ) ;
0 commit comments