Skip to content

Commit

Permalink
feat: completed SSMProvider implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamorosi committed Dec 27, 2022
1 parent 743f7e0 commit 7f24e91
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/parameters/src/SSMProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SSMProvider extends BaseProvider {
* @param {Record<string, unknown>[]} parameters - List of parameter names, and any optional overrides
*
*/
public async getParametersByName(parameters: Record<string, SSMGetParametersByNameOptionsInterface>, options: SSMGetParametersByNameOptionsInterface): Promise<Record<string, unknown>> {
public async getParametersByName(parameters: Record<string, SSMGetParametersByNameOptionsInterface>, options?: SSMGetParametersByNameOptionsInterface): Promise<Record<string, unknown>> {
const configs = { ...{
decrypt: false,
maxAge: DEFAULT_MAX_AGE_SECS,
Expand Down Expand Up @@ -372,8 +372,17 @@ const getParameters = (path: string, options?: SSMGetMultipleOptionsInterface):
return DEFAULT_PROVIDERS.ssm.getMultiple(path, options);
};

const getParametersByName = (parameters: Record<string, SSMGetParametersByNameOptionsInterface>, options?: SSMGetParametersByNameOptionsInterface): Promise<Record<string, unknown>> => {
if (!DEFAULT_PROVIDERS.hasOwnProperty('ssm')) {
DEFAULT_PROVIDERS.ssm = new SSMProvider();
}

return (DEFAULT_PROVIDERS.ssm as SSMProvider).getParametersByName(parameters, options);
};

export {
SSMProvider,
getParameter,
getParameters,
getParametersByName,
};
60 changes: 60 additions & 0 deletions packages/parameters/tests/unit/getParametersByName.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Test getParametersByName function
*
* @group unit/parameters/SSMProvider/getParametersByName/function
*/
import { DEFAULT_PROVIDERS } from '../../src/BaseProvider';
import { SSMProvider, getParametersByName } from '../../src/SSMProvider';

describe('Function: getParametersByName', () => {

beforeEach(() => {
jest.clearAllMocks();
});

test('when called and a default provider doesn\'t exist, it instantiates one and returns the value', async () => {

// Prepare
const parameters = {
'/foo/bar': {
maxAge: 1000,
},
'/foo/baz': {
maxAge: 2000,
}
};
const getParametersByNameSpy = jest.spyOn(SSMProvider.prototype, 'getParametersByName').mockImplementation();

// Act
await getParametersByName(parameters);

// Assess
expect(getParametersByNameSpy).toHaveBeenCalledWith(parameters, undefined);

});

test('when called and a default provider exists, it uses it and returns the value', async () => {

// Prepare
const provider = new SSMProvider();
DEFAULT_PROVIDERS.ssm = provider;
const parameters = {
'/foo/bar': {
maxAge: 1000,
},
'/foo/baz': {
maxAge: 2000,
}
};
const getParametersByNameSpy = jest.spyOn(provider, 'getParametersByName').mockImplementation();

// Act
await getParametersByName(parameters);

// Assess
expect(getParametersByNameSpy).toHaveBeenCalledWith(parameters, undefined);
expect(DEFAULT_PROVIDERS.ssm).toBe(provider);

});

});

0 comments on commit 7f24e91

Please sign in to comment.