@@ -3,6 +3,7 @@ import axios from 'axios';
3
3
import fs from 'fs' ;
4
4
import AdmZip from 'adm-zip' ;
5
5
import gql from 'graphql-tag' ;
6
+ import * as path from "node:path" ;
6
7
7
8
const HOST_PLACEHOLDER = '<AIR_ROUTES_DB_HOST>' ;
8
9
const PORT_PLACEHOLDER = '<AIR_ROUTES_DB_PORT>' ;
@@ -174,6 +175,51 @@ async function testResolverQueriesResults(resolverFile, queriesReferenceFolder,
174
175
}
175
176
}
176
177
178
+ /**
179
+ * Validates that an apollo zip contains the correct content.
180
+ *
181
+ * @param {string } outputFolderPath the test output folder path that contains the apollo zip file to validate
182
+ * @param {object } testDbInfo object that contains info about the neptune db/graph used to generate the apollo zip file
183
+ * @param {string } testDbInfo.graphName neptune db/graph name
184
+ * @param {string } testDbInfo.neptuneType neptune-db or neptune-graph
185
+ * @param {string } testDbInfo.host neptune host
186
+ * @param {int } testDbInfo.port neptune port
187
+ * @param {string } testDbInfo.region neptune region
188
+ * @param {boolean } subgraph true if the apollo zip contents should be for a subgraph
189
+ * @returns {Promise<void> }
190
+ */
191
+ async function testApolloArtifacts ( outputFolderPath , testDbInfo , subgraph = false ) {
192
+ test ( 'Validate Apollo zip contents' , ( ) => {
193
+ const expectedFiles = [
194
+ '.env' ,
195
+ 'index.mjs' ,
196
+ 'output.resolver.graphql.js' ,
197
+ 'package.json' ,
198
+ 'package-lock.json' ,
199
+ 'output.schema.graphql' ,
200
+ 'neptune.mjs' ,
201
+ 'queryHttpNeptune.mjs'
202
+ ] ;
203
+
204
+ const files = fs . readdirSync ( outputFolderPath ) ;
205
+ const apolloZips = files . filter ( file => file . startsWith ( `apollo-server-${ testDbInfo . graphName } -` ) && file . endsWith ( '.zip' ) ) ;
206
+ expect ( apolloZips . length ) . toEqual ( 1 ) ;
207
+
208
+ const actualFiles = unzipAndGetContents ( path . join ( outputFolderPath , 'unzipped' ) , path . join ( outputFolderPath , apolloZips [ 0 ] ) ) ;
209
+ expect ( actualFiles . toSorted ( ) ) . toEqual ( expectedFiles . toSorted ( ) ) ;
210
+
211
+ const expectedEnvContent = [
212
+ `NEPTUNE_TYPE=${ testDbInfo . neptuneType } ` ,
213
+ `NEPTUNE_HOST=${ testDbInfo . host } ` ,
214
+ `NEPTUNE_PORT=${ testDbInfo . port } ` ,
215
+ `AWS_REGION=${ testDbInfo . region } ` ,
216
+ 'LOGGING_ENABLED=false' ,
217
+ `SUBGRAPH=${ subgraph } `
218
+ ] ;
219
+ const actualEnvContent = fs . readFileSync ( path . join ( outputFolderPath , 'unzipped' , '.env' ) , 'utf8' ) ;
220
+ expect ( actualEnvContent ) . toEqual ( expectedEnvContent . join ( '\n' ) ) ;
221
+ } ) ;
222
+ }
177
223
178
224
export {
179
225
checkFileContains ,
@@ -183,6 +229,7 @@ export {
183
229
checkOutputZipLambdaUsesSdk ,
184
230
loadResolver ,
185
231
readJSONFile ,
232
+ testApolloArtifacts ,
186
233
testResolverQueries ,
187
234
testResolverQueriesResults ,
188
235
} ;
0 commit comments