Skip to content

Commit

Permalink
Removed duplicates of airports.source.schema.graphql and changed refe…
Browse files Browse the repository at this point in the history
…rences to use a common file. Changed integration test references to neptune db host and port to have values injected from environment variables so that contributors do not have to modify the case files to execute tests, which could lead to accidental commit of real URLs.

Fixed tests failing due to hardcoded output directory reference in main.js, missing comma in json file, typo in referenced file suffix, and incorrect order of test cases (delete, create changed to create, delete).
  • Loading branch information
andreachild authored and Cole-Greer committed Oct 11, 2024
1 parent b6e130d commit 3e48485
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 46 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ test/TestCases/Case02/output/**
test/TestCases/Case03/output/**
test/TestCases/Case04/output/**
test/TestCases/Case05/output/**
test/TestCases/Case06/output/**
test/TestCases/Case06/output/**
*.iml
12 changes: 12 additions & 0 deletions .jest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
'transform': {},
'verbose': true,
'testSequencer': './test/jestTestSequencer.js',
'globals': {
// neptune db that has pre-loaded air routes sample data host and port
// ex. db-neptune-foo-bar.cluster-abc.us-west-2.neptune.amazonaws.com
'AIR_ROUTES_DB_HOST': process.env.AIR_ROUTES_DB_HOST,
// ex. 8182
'AIR_ROUTES_DB_PORT': process.env.AIR_ROUTES_DB_PORT
}
};
5 changes: 0 additions & 5 deletions .jest.json

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"scripts": {
"postinstall": "cd templates/Lambda4AppSyncHTTP && npm install && cd ../Lambda4AppSyncSDK && npm install",
"lint": "eslint neptune-for-graphql.mjs ./src",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --runInBand --detectOpenHandles --config .jest.json",
"test:resolver": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --runInBand --detectOpenHandles --config .jest.json --testPathPattern=test/TestCases/Case01"
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --runInBand --detectOpenHandles --config .jest.js",
"test:resolver": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --runInBand --detectOpenHandles --config .jest.js --testPathPattern=test/TestCases/Case01"
},
"jest": {
"collectCoverage": true,
Expand Down
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ async function main() {
// Outputs
// ****************************************************************************

mkdirSync('./output', { recursive: true });
mkdirSync(outputFolderPath, { recursive: true });

// Output GraphQL schema no directives
if (inputGraphQLSchema != '') {
Expand Down
2 changes: 1 addition & 1 deletion test/TestCases/Case01/Case01.04.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { readJSONFile, testResolverQueriesResults } from '../../testLib';

const casetest = readJSONFile('./test/TestCases/Case01/case.json');

await testResolverQueriesResults( './TestCases/Case01/output/output.resolver.graphql.cjs',
await testResolverQueriesResults( './TestCases/Case01/output/output.resolver.graphql.js',
'./test/TestCases/Case01/queries',
casetest.host,
casetest.port);
6 changes: 3 additions & 3 deletions test/TestCases/Case01/case.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"name": "Unit Test (Air Routes)",
"description":"Start from graphql schema with directives, using Air Routes unit test schema",
"argv":["--quiet",
"--input-schema-file", "./test/TestCases/Case01/input/airports.source.schema.graphql",
"--input-schema-file", "./test/TestCases/airports.source.schema.graphql",
"--input-schema-changes-file", "./test/TestCases/Case01/input/changesAirport.json",
"--output-js-resolver-file", "./test/TestCases/Case01/output/output.resolver.graphql.cjs",
"--output-folder-path", "./test/TestCases/Case01/output",
"--output-no-lambda-zip"],
"host": "<your-airroutes-db-host>",
"port": "<your-airroutes-db-port>"
"host": "<AIR_ROUTES_DB_HOST>",
"port": "<AIR_ROUTES_DB_PORT>",
"testOutputFilesSize": ["output.resolver.graphql.js", "output.schema.graphql", "output.source.schema.graphql"],
"testOutputFilesContent": ["output.schema.graphql", "output.source.schema.graphql"]
}
4 changes: 2 additions & 2 deletions test/TestCases/Case02/case.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"--output-js-resolver-file", "./test/TestCases/Case02/output/output.resolver.graphql.cjs",
"--output-folder-path", "./test/TestCases/Case02/output",
"--output-no-lambda-zip"],
"host": "<your-airroutes-db-host>",
"port": "<your-airroutes-db-port>"
"host": "<AIR_ROUTES_DB_HOST>",
"port": "<AIR_ROUTES_DB_PORT>",
"testOutputFilesSize": ["output.lambda.zip", "output.resolver.graphql.js", "output.schema.graphql", "output.source.schema.graphql"],
"testOutputFilesContent": ["output.schema.graphql", "output.source.schema.graphql"]
}
4 changes: 2 additions & 2 deletions test/TestCases/Case03/case.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"--input-schema-file", "./test/TestCases/Case03/input/todo.schema.graphql",
"--output-folder-path", "./test/TestCases/Case03/output",
"--output-no-lambda-zip"],
"host": "",
"port": "",
"host": "<AIR_ROUTES_DB_HOST>",
"port": "<AIR_ROUTES_DB_PORT>",
"testOutputFilesSize": ["output.lambda.zip", "output.resolver.graphql.js", "output.schema.graphql", "output.source.schema.graphql"],
"testOutputFilesContent": ["output.schema.graphql", "output.source.schema.graphql"]
}
6 changes: 3 additions & 3 deletions test/TestCases/Case04/case.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"name": "Get Database Schema",
"description":"",
"argv":["--quiet",
"--input-graphdb-schema-neptune-endpoint", "<neptune-endpoint>",
"--input-graphdb-schema-neptune-endpoint", "<AIR_ROUTES_DB_HOST>:<AIR_ROUTES_DB_PORT>",
"--output-folder-path", "./test/TestCases/Case04/output",
"--output-no-lambda-zip"],
"host": "",
"port": "",
"host": "<AIR_ROUTES_DB_HOST>",
"port": "<AIR_ROUTES_DB_PORT>",
"testOutputFilesSize": ["output.lambda.zip", "output.resolver.graphql.js", "output.schema.graphql", "output.source.schema.graphql"],
"testOutputFilesContent": ["output.schema.graphql", "output.source.schema.graphql"]
}
18 changes: 11 additions & 7 deletions test/TestCases/Case05/case01.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{
"name": "Unit Test (Air Routes) Remove Pipeline",
"description":"Remove pipeline",
"argv":["--quiet",
"--remove-aws-pipeline-name", "AirportsJestTest",
"--output-folder-path", "./test/TestCases/Case05/output"],
"host": "",
"port": "",
"name": "Unit Test (Air Routes) Pipeline",
"description":"Create pipeline",
"argv":["--quiet",
"--input-schema-file", "./test/TestCases/airports.source.schema.graphql",
"--output-folder-path", "./test/TestCases/Case05/output",
"--create-update-aws-pipeline",
"--create-update-aws-pipeline-name", "AirportsJestTest",
"--create-update-aws-pipeline-neptune-endpoint", "<AIR_ROUTES_DB_HOST>:<AIR_ROUTES_DB_PORT>",
"--output-resolver-query-https"],
"host": "<AIR_ROUTES_DB_HOST>",
"port": "<AIR_ROUTES_DB_PORT>",
"testOutputFilesSize": ["output.resolver.graphql.js", "output.schema.graphql", "output.source.schema.graphql"],
"testOutputFilesContent": ["output.schema.graphql", "output.source.schema.graphql"]
}
22 changes: 9 additions & 13 deletions test/TestCases/Case05/case02.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
{
"name": "Unit Test (Air Routes) Pipeline",
"description":"Create pipeline",
"argv":["--quiet",
"--input-schema-file", "./test/TestCases/Case05/input/airports.source.schema.graphql",
"--output-folder-path", "./test/TestCases/Case05/output",
"--create-update-aws-pipeline",
"--create-update-aws-pipeline-name", "AirportsJestTest",
"--create-update-aws-pipeline-neptune-endpoint", "<neptune-endpoint>",
"--output-resolver-query-https"],
"host": "",
"port": "",
"testOutputFilesSize": ["output.resolver.graphql.js", "output.schema.graphql", "output.source.schema.graphql"],
"testOutputFilesContent": ["output.schema.graphql", "output.source.schema.graphql"]
"name": "Unit Test (Air Routes) Remove Pipeline",
"description":"Remove pipeline",
"argv":["--quiet",
"--remove-aws-pipeline-name", "AirportsJestTest",
"--output-folder-path", "./test/TestCases/Case05/output"],
"host": "<AIR_ROUTES_DB_HOST>",
"port": "<AIR_ROUTES_DB_HOST>",
"testOutputFilesSize": ["output.resolver.graphql.js", "output.schema.graphql", "output.source.schema.graphql"],
"testOutputFilesContent": ["output.schema.graphql", "output.source.schema.graphql"]
}
8 changes: 4 additions & 4 deletions test/TestCases/Case06/case.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
"name": "Unit Test (Air Routes) CDK Pipeline",
"description":"Create CDK pipeline",
"argv":["--quiet",
"--input-schema-file", "./test/TestCases/Case06/input/airports.source.schema.graphql",
"--input-schema-file", "./test/TestCases/airports.source.schema.graphql",
"--output-folder-path", "./test/TestCases/Case06/output",
"--output-aws-pipeline-cdk",
"--output-aws-pipeline-cdk-name", "AirportCDKTestJest",
"--output-aws-pipeline-cdk-neptume-database-name", "airport00",
"--output-aws-pipeline-cdk-region", "us-east-1",
"--output-aws-pipeline-cdk-neptume-endpoint", "<neptune-endpoint>",
"--output-aws-pipeline-cdk-neptume-endpoint", "<AIR_ROUTES_DB_HOST>:<AIR_ROUTES_DB_PORT>",
"--output-resolver-query-https"],
"host": "",
"port": "",
"host": "<AIR_ROUTES_DB_HOST>",
"port": "<AIR_ROUTES_DB_PORT>",
"testOutputFilesSize": ["output.resolver.graphql.js", "output.schema.graphql", "output.source.schema.graphql"],
"testOutputFilesContent": ["output.schema.graphql", "output.source.schema.graphql"]
}
28 changes: 26 additions & 2 deletions test/testLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import axios from 'axios';
import fs from 'fs';


const HOST_PLACEHOLDER = '<AIR_ROUTES_DB_HOST>';
const PORT_PLACEHOLDER = '<AIR_ROUTES_DB_PORT>';

async function queryNeptune(q, language, host, port, param) {
try {
Expand All @@ -18,9 +19,32 @@ async function queryNeptune(q, language, host, port, param) {
}
}

/**
* Searches the given text for a placeholder text and if found replaces it with an environment variable value of the same name.
* It is expected that the placeholder text is surrounded by angle brackets and the environment variable name is the placeholder text without the angle brackets.
*
* @param text the text to search and replace the placeholder
* @param placeholder the placeholder text to search for
* @returns text with replaced placeholder if found
* @throws error if the placeholder text is found but the environment variable is not set
*/
function replacePlaceholderWithEnvironmentVariable(text, placeholder) {
if (text.includes(placeholder)) {
// remove angle brackets
let envVarName = placeholder.replace(/[<>]/g, '');
if (process.env[envVarName]) {
return text.replace(placeholder, process.env[envVarName]);
}
throw new Error('Expected environment variable ' + envVarName + ' is not set');
}
return text;
}

function readJSONFile(fileName) {
return JSON.parse(fs.readFileSync(fileName, 'utf8'));
let text = fs.readFileSync(fileName, 'utf8');
text = replacePlaceholderWithEnvironmentVariable(text, HOST_PLACEHOLDER);
text = replacePlaceholderWithEnvironmentVariable(text, PORT_PLACEHOLDER);
return JSON.parse(text);
}


Expand Down

0 comments on commit 3e48485

Please sign in to comment.