@@ -55,102 +55,93 @@ describe("Plugin", () => {
55
55
"Elasticsearch endpoint not specified."
56
56
) ;
57
57
} ) ;
58
+ } ) ;
58
59
59
- it ( "Tests that an error is through if there is a cf-endpoint and it does not have an endpoint" , async ( ) => {
60
- const serverless = {
60
+ describe ( "Setup indices" , ( ) => {
61
+ function createServerless ( indices : Index [ ] ) : Serverless < Custom > {
62
+ return {
61
63
...fakeServerless ,
62
64
service : {
63
65
custom : {
64
66
elasticsearch : {
65
- "cf-endpoint" : "TestCfEndpoint"
67
+ ...endpointConfig ,
68
+ indices
66
69
}
67
70
}
68
71
}
69
72
} ;
73
+ }
70
74
71
- findCloudformationExportStub . returns ( Promise . resolve ( undefined ) ) ;
72
- const plugin : ServerlessPlugin = new Plugin ( serverless , { } ) ;
73
-
74
- await checkAndCatchError (
75
- ( ) => plugin . hooks [ "before:aws:deploy:deploy:updateStack" ] ( ) ,
76
- "Endpoint not found at cloudformation export."
77
- ) ;
78
- } ) ;
79
-
80
- it ( "Tests that https is pre-pended to the url if it does not exist." , async ( ) => {
75
+ it ( "Tests that an error is through if there is a cf-endpoint and it does not have an endpoint" , async ( ) => {
81
76
const serverless = {
82
77
...fakeServerless ,
83
78
service : {
84
79
custom : {
85
80
elasticsearch : {
86
- endpoint : "TestCfEndpoint"
81
+ "cf- endpoint" : "TestCfEndpoint"
87
82
}
88
83
}
89
84
}
90
85
} ;
91
86
92
87
findCloudformationExportStub . returns ( Promise . resolve ( undefined ) ) ;
88
+ const plugin : ServerlessPlugin = new Plugin ( serverless , { } ) ;
89
+
90
+ plugin . hooks [ "before:aws:deploy:deploy:updateStack" ] ( ) ;
91
+ await checkAndCatchError ( ( ) => plugin . hooks [ "after:aws:deploy:deploy:updateStack" ] ( ) , "Endpoint not found at cloudformation export." ) ;
92
+ } ) ;
93
+
94
+ it ( "Tests that https is pre-pended to the url if it does not exist." , async ( ) => {
95
+ const serverless = createServerless ( [
96
+ {
97
+ name : "Index1" ,
98
+ file : "./test/testFiles/TestIndices1.json"
99
+ }
100
+ ] ) ;
101
+ serverless . service . custom . elasticsearch . endpoint = "TestCfEndpoint" ;
102
+
93
103
const plugin : Plugin = new Plugin ( serverless , { } ) ;
94
104
95
105
await plugin . hooks [ "before:aws:deploy:deploy:updateStack" ] ( ) ;
106
+ await plugin . hooks [ "after:aws:deploy:deploy:updateStack" ] ( ) ;
96
107
97
- expect ( plugin . endpoint ) . to . equal ( "https://TestCfEndpoint" ) ;
108
+ expect ( putStub ) . to . have . been . calledWith ( "https://TestCfEndpoint/Index1 " ) ;
98
109
} ) ;
99
110
100
111
it ( "Tests that https is pre-pended to the url if it does not exist from a cloudformation domain." , async ( ) => {
101
- const serverless = {
102
- ...fakeServerless ,
103
- service : {
104
- custom : {
105
- elasticsearch : {
106
- "cf-endpoint" : "TestCfEndpoint"
107
- }
108
- }
112
+ const serverless = createServerless ( [
113
+ {
114
+ name : "Index1" ,
115
+ file : "./test/testFiles/TestIndices1.json"
109
116
}
110
- } ;
117
+ ] ) ;
118
+ serverless . service . custom . elasticsearch . endpoint = undefined ;
119
+ serverless . service . custom . elasticsearch [ "cf-endpoint" ] = "ABCD123" ;
111
120
121
+ findCloudformationExportStub . returns ( Promise . resolve ( "TestCfEndpoint" ) ) ;
112
122
const plugin : Plugin = new Plugin ( serverless , { } ) ;
113
123
114
124
await plugin . hooks [ "before:aws:deploy:deploy:updateStack" ] ( ) ;
125
+ await plugin . hooks [ "after:aws:deploy:deploy:updateStack" ] ( ) ;
115
126
116
- expect ( plugin . endpoint ) . to . equal ( "https://ABCD123 " ) ;
127
+ expect ( putStub ) . to . have . been . calledWith ( "https://TestCfEndpoint/Index1 " ) ;
117
128
} ) ;
118
129
119
130
it ( "Tests that the url is not touched if it already has https." , async ( ) => {
120
- const serverless = {
121
- ...fakeServerless ,
122
- service : {
123
- custom : {
124
- elasticsearch : {
125
- endpoint : "https://TestCfEndpoint"
126
- }
127
- }
131
+ const serverless = createServerless ( [
132
+ {
133
+ name : "Index1" ,
134
+ file : "./test/testFiles/TestIndices1.json"
128
135
}
129
- } ;
130
-
131
- findCloudformationExportStub . returns ( Promise . resolve ( undefined ) ) ;
136
+ ] ) ;
137
+ serverless . service . custom . elasticsearch . endpoint = "https://TestCfEndpoint" ;
132
138
const plugin : Plugin = new Plugin ( serverless , { } ) ;
133
139
134
140
await plugin . hooks [ "before:aws:deploy:deploy:updateStack" ] ( ) ;
141
+ await plugin . hooks [ "after:aws:deploy:deploy:updateStack" ] ( ) ;
135
142
136
- expect ( plugin . endpoint ) . to . equal ( "https://TestCfEndpoint" ) ;
143
+ expect ( putStub ) . to . have . been . calledWith ( "https://TestCfEndpoint/Index1 " ) ;
137
144
} ) ;
138
- } ) ;
139
-
140
- describe ( "Setup indices" , ( ) => {
141
- function createServerless ( indices : Index [ ] ) : Serverless < Custom > {
142
- return {
143
- ...fakeServerless ,
144
- service : {
145
- custom : {
146
- elasticsearch : {
147
- ...endpointConfig ,
148
- indices
149
- }
150
- }
151
- }
152
- } ;
153
- }
154
145
155
146
it ( "Tests that an error is thrown if a name is not provided for index." , async ( ) => {
156
147
const indices : Index [ ] = [
0 commit comments