-
Notifications
You must be signed in to change notification settings - Fork 37
/
index.test.js
55 lines (47 loc) · 1.82 KB
/
index.test.js
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
const aws = require('aws-sdk')
const index = require('./index.js')
describe('get SecretString from AWS SecretsManager', () => {
let data = {}
describe('get parsable data', () => {
beforeAll(async () => {
const INPUT_SECRET_NAME = process.env.SECRET_NAME
const AWSConfig = {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: process.env.AWS_DEFAULT_REGION
}
if (process.env.AWS_SESSION_TOKEN) {
AWSConfig.sessionToken = process.env.AWS_SESSION_TOKEN
}
const secretsManager = new aws.SecretsManager(AWSConfig)
data = await index.getSecretValue(secretsManager, INPUT_SECRET_NAME)
})
test('should have SecretString', () => {
expect(data).toHaveProperty('SecretString')
})
test('should have parsed values', () => {
const parsedData = JSON.parse(data.SecretString)
expect(parsedData.SCIENTIFIC_NAME).toEqual('Pygoscelis adeliae')
expect(parsedData.MIN_HEIGHT).toEqual(46)
expect(parsedData.MAX_HEIGHT).toEqual(71)
expect(parsedData.MIN_WEIGHT).toEqual(3.6)
expect(parsedData.MAX_WEIGHT).toEqual(6)
expect(parsedData.SWIMMING_SPEED).toEqual(8)
expect(parsedData.LEAPING_METERS).toEqual(3)
})
})
describe('get unparsable data', () => {
beforeAll(async () => {
const INPUT_SECRET_NAME = `${process.env.SECRET_NAME}-unvalid`
const secretsManager = new aws.SecretsManager({
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: process.env.AWS_DEFAULT_REGION
})
data = await index.getSecretValue(secretsManager, INPUT_SECRET_NAME)
})
test('should have SecretString', () => {
expect(data).toHaveProperty('SecretString')
})
})
})