I'm creating a utilities class to handle some of our common functions to help reduce code copy/past in our modules: I created an exports module. All that's happening here is the export of an object which contains three functions.
module.exports = {
//retrieve a secret object from the AWS Secrets Manager
//Parameter should be string value of the Secret ID
getSecretIdAsync : async (param) => {
return await new Promise((resolve, reject) => {
scrtmgr.getSecretValue({SecretId: param}, (err, data) => {
if(err){
reject(console.log('Error getting SecretId: ' + err, err.stack));
} else{
if('SecretString' in data)
return resolve(JSON.parse(data.SecretString));
}
});
});
},
//retrieves the AWS Paramter value from the AWS Paramter store
//param should be string value of parameter hierarchical id
getParameterValueFromStoreAsync : async (param) => {
return await new Promise((resolve, reject) => {
servmgr.getParameter({ Name: param}, (err, data) => {
if(err){
reject(console.log('Error getting parameter: ' + err, err.stack));
}
return resolve(data.Parameters.Value);
});
});
},
//retrieves the AWS Paramter "object" from the AWS Paramter store
//param should be string value of parameter hierarchical id
getParameterFromStoreAsync : async (param) => {
return await new Promise((resolve, reject) => {
servmgr.getParameter({ Name: param}, (err, data) => {
if(err){
reject(console.log('Error getting parameter: ' + err, err.stack));
}
return resolve(data.Parameters);
});
});
}
}
Whenever I attempt to reference this module (say in my unit test I reference to module as:
let chai = require('chai');
let ut = require('../utilities.js');
let expect = chai.expect;
let aws = require('aws-sdk-mock');
describe('get parameter value', ()=>{
it('resolves', (done)=>{
var result = aws.mock('SSM', 'putParameter' , {"Name": "someName", "Value": "someValue"} );
console.log('###### ' + JSON.stringify(ut));
//console.log(obj);
});
});
directory structure is utilities.js is located in the root, where the unit test is in a folder called test.
Whenever I try to import the utilities module the object it always empty.
console.log('###### ' + JSON.stringify(ut));
generates ###### {}
I've exported individual functions in the past and I thought a group of functions would just require exporting a constructor.
Should multiple functions be exported in a different manner?