@@ -55,102 +55,93 @@ describe("Plugin", () => {
5555 "Elasticsearch endpoint not specified."
5656 ) ;
5757 } ) ;
58+ } ) ;
5859
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 {
6163 ...fakeServerless ,
6264 service : {
6365 custom : {
6466 elasticsearch : {
65- "cf-endpoint" : "TestCfEndpoint"
67+ ...endpointConfig ,
68+ indices
6669 }
6770 }
6871 }
6972 } ;
73+ }
7074
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 ( ) => {
8176 const serverless = {
8277 ...fakeServerless ,
8378 service : {
8479 custom : {
8580 elasticsearch : {
86- endpoint : "TestCfEndpoint"
81+ "cf- endpoint" : "TestCfEndpoint"
8782 }
8883 }
8984 }
9085 } ;
9186
9287 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+
93103 const plugin : Plugin = new Plugin ( serverless , { } ) ;
94104
95105 await plugin . hooks [ "before:aws:deploy:deploy:updateStack" ] ( ) ;
106+ await plugin . hooks [ "after:aws:deploy:deploy:updateStack" ] ( ) ;
96107
97- expect ( plugin . endpoint ) . to . equal ( "https://TestCfEndpoint" ) ;
108+ expect ( putStub ) . to . have . been . calledWith ( "https://TestCfEndpoint/Index1 " ) ;
98109 } ) ;
99110
100111 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"
109116 }
110- } ;
117+ ] ) ;
118+ serverless . service . custom . elasticsearch . endpoint = undefined ;
119+ serverless . service . custom . elasticsearch [ "cf-endpoint" ] = "ABCD123" ;
111120
121+ findCloudformationExportStub . returns ( Promise . resolve ( "TestCfEndpoint" ) ) ;
112122 const plugin : Plugin = new Plugin ( serverless , { } ) ;
113123
114124 await plugin . hooks [ "before:aws:deploy:deploy:updateStack" ] ( ) ;
125+ await plugin . hooks [ "after:aws:deploy:deploy:updateStack" ] ( ) ;
115126
116- expect ( plugin . endpoint ) . to . equal ( "https://ABCD123 " ) ;
127+ expect ( putStub ) . to . have . been . calledWith ( "https://TestCfEndpoint/Index1 " ) ;
117128 } ) ;
118129
119130 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"
128135 }
129- } ;
130-
131- findCloudformationExportStub . returns ( Promise . resolve ( undefined ) ) ;
136+ ] ) ;
137+ serverless . service . custom . elasticsearch . endpoint = "https://TestCfEndpoint" ;
132138 const plugin : Plugin = new Plugin ( serverless , { } ) ;
133139
134140 await plugin . hooks [ "before:aws:deploy:deploy:updateStack" ] ( ) ;
141+ await plugin . hooks [ "after:aws:deploy:deploy:updateStack" ] ( ) ;
135142
136- expect ( plugin . endpoint ) . to . equal ( "https://TestCfEndpoint" ) ;
143+ expect ( putStub ) . to . have . been . calledWith ( "https://TestCfEndpoint/Index1 " ) ;
137144 } ) ;
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- }
154145
155146 it ( "Tests that an error is thrown if a name is not provided for index." , async ( ) => {
156147 const indices : Index [ ] = [
0 commit comments