-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
580634c
commit 642b9bb
Showing
3 changed files
with
86 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* Test getParameters function | ||
* | ||
* @group unit/parameters/SSMProvider/getParameters/function | ||
*/ | ||
import { DEFAULT_PROVIDERS } from '../../src/BaseProvider'; | ||
import { SSMProvider, getParameters } from '../../src/SSMProvider'; | ||
import { SSMClient, GetParametersByPathCommand } from '@aws-sdk/client-ssm'; | ||
import { mockClient } from 'aws-sdk-client-mock'; | ||
import 'aws-sdk-client-mock-jest'; | ||
|
||
describe('Function: getParameters', () => { | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('when called and a default provider doesn\'t exist, it instantiates one and returns the value', async () => { | ||
|
||
// Prepare | ||
const parameterPath = '/foo'; | ||
const parameterValue = 'bar'; | ||
const client = mockClient(SSMClient).on(GetParametersByPathCommand).resolves({ | ||
Parameters: [{ | ||
Name: '/foo/bar', | ||
Value: parameterValue, | ||
}], | ||
}); | ||
|
||
// Act | ||
const parameters = await getParameters(parameterPath); | ||
|
||
// Assess | ||
expect(client).toReceiveCommandWith(GetParametersByPathCommand, { | ||
Path: parameterPath, | ||
}); | ||
expect(parameters).toEqual({ | ||
bar: parameterValue, | ||
}); | ||
|
||
}); | ||
|
||
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 parameterPath = '/foo'; | ||
const parameterValue = 'bar'; | ||
const client = mockClient(SSMClient).on(GetParametersByPathCommand).resolves({ | ||
Parameters: [{ | ||
Name: '/foo/bar', | ||
Value: parameterValue, | ||
}], | ||
}); | ||
|
||
// Act | ||
const parameters = await getParameters(parameterPath); | ||
|
||
// Assess | ||
expect(client).toReceiveCommandWith(GetParametersByPathCommand, { | ||
Path: parameterPath, | ||
}); | ||
expect(parameters).toEqual({ | ||
'bar': parameterValue, | ||
}); | ||
expect(DEFAULT_PROVIDERS.ssm).toBe(provider); | ||
|
||
}); | ||
|
||
}); |