-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestLocalScript.js
More file actions
55 lines (45 loc) · 1.91 KB
/
testLocalScript.js
File metadata and controls
55 lines (45 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require('dotenv').config({ path: './.backend-testing-env' }); //sets up enviornment variables
const fs = require('fs');
console.log('\n---------------------------START--------------------------\n');
console.log('⌛️ INITIALIZING ..\n');
//creates function called path to that directs to file location
const pathTo = (file) => require('./' + file);
//function to print final response
function done(result) {
console.log('\n****************************\n');
console.log('\n 🏁 Response 🏁 :');
console.log(JSON.stringify(result, null, 2));
console.log('\n---------------------------DONE---------------------------\n');
}
//list of lambda parent folder names
const lambdas = {
apply: { function: pathTo('apply/index.js'), event: 'events/apply.json' },
upload: { function: pathTo('upload/index.js'), event: 'events/upload.json' }
};
//reads arguments
let i = 0;
process.argv[i++]; // nodeName
process.argv[i++]; // cliName
const lambdaName = process.argv[i++];
//checks to see if there is a valid parameter
if (!lambdaName || !Object.keys(lambdas).includes(lambdaName)) {
let output = lambdaName
? `${lambdaName} is not a valid parameter option.`
: 'This function takes at least 1 parameter.';
console.log(output + ' Here is a list of Valid Parameter Options:');
console.log(Object.keys(lambdas));
console.log();
} else {
//retrieve function path and event file name from list of lambdas based on user key input
const lambdaFile = lambdas[lambdaName].function;
const eventFile = lambdas[lambdaName].event;
//parses event file into JSON
const event = JSON.parse(fs.readFileSync(eventFile, 'utf-8'));
//sets context for function call
const context = {};
console.log(`🚗 INVOKING: ${lambdaName}`);
console.log('\n****************************\n');
console.log('\t🖨 OUTPUTS 🖨 :\n');
//promise chain for testing code and printing out status
lambdaFile.handler(event, context).then(done);
}