Skip to content

Commit

Permalink
add jest for test
Browse files Browse the repository at this point in the history
  • Loading branch information
say8425 committed Nov 18, 2019
1 parent d45d359 commit b4da5bd
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},

"plugins": [
"jest",
"import",
"node",
"promise",
Expand Down Expand Up @@ -213,4 +214,4 @@

"standard/no-callback-literal": "error"
}
}
}
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const secretsManager = new aws.SecretsManager({
region: core.getInput('AWS_DEFAULT_REGION')
})

async function getSecretValue (secretName) {
async function getSecretValue (secretsManager, secretName) {
return secretsManager.getSecretValue({ SecretId: secretName }).promise()
}

getSecretValue(secretName).then(resp => {
getSecretValue(secretsManager, secretName).then(resp => {
core.setSecret(resp.SecretString)
const secret = resp.SecretString

Expand All @@ -27,3 +27,5 @@ getSecretValue(secretName).then(resp => {
}).catch(err => {
core.setFailed(err)
})

exports.getSecretValue = getSecretValue
41 changes: 41 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// // import { getSecretValue } from './index.js'
//
// const index = require('./index.js')
//
// describe("Index File", () => {
// test("it should has ENV File", async () => {
// const INPUT_SECRET_NAME = 'pongdang-env-test'
// process.env.INPUT_AWS_ACCESS_KEY_ID = 'AKIAXIPQLXCNPTH4UN6K'
// process.env.INPUT_AWS_SECRET_ACCESS_KEY = '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'
// process.env.INPUT_AWS_DEFAULT_REGION = 'ap-northeast-1'
//
// const data = await index.getSecretValue(INPUT_SECRET_NAME)
// expect(data).toEqual('Mark')
// })
// })

const aws = require('aws-sdk')
const index = require('./index.js')

describe('get SecretString from AWS SecretsManager', () => {
const INPUT_SECRET_NAME = process.env.SECRET_NAME
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
})
// const data = await index.getSecretValue(secretsManager, INPUT_SECRET_NAME)
test('should have SecretString', async () => {
const data = await index.getSecretValue(secretsManager, INPUT_SECRET_NAME)
expect(data).toHaveProperty('SecretString')

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)
})
})
9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js'],
moduleDirectories: ['node_modules'],
globals: {
NODE_ENV: 'test'
},
setupFiles: ['dotenv/config']
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
},
"devDependencies": {
"@zeit/ncc": "^0.20.5",
"dotenv": "^8.2.0",
"eslint": "^6.6.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jest": "^23.0.4",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
Expand Down
56 changes: 53 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@
"@types/istanbul-lib-coverage" "*"
"@types/istanbul-lib-report" "*"

"@types/json-schema@^7.0.3":
version "7.0.3"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636"
integrity sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A==

"@types/stack-utils@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
Expand All @@ -361,6 +366,27 @@
dependencies:
"@types/yargs-parser" "*"

"@typescript-eslint/experimental-utils@^2.5.0":
version "2.7.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.7.0.tgz#58d790a3884df3041b5a5e08f9e5e6b7c41864b5"
integrity sha512-9/L/OJh2a5G2ltgBWJpHRfGnt61AgDeH6rsdg59BH0naQseSwR7abwHq3D5/op0KYD/zFT4LS5gGvWcMmegTEg==
dependencies:
"@types/json-schema" "^7.0.3"
"@typescript-eslint/typescript-estree" "2.7.0"
eslint-scope "^5.0.0"

"@typescript-eslint/typescript-estree@2.7.0":
version "2.7.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.7.0.tgz#34fd98c77a07b40d04d5b4203eddd3abeab909f4"
integrity sha512-vVCE/DY72N4RiJ/2f10PTyYekX2OLaltuSIBqeHYI44GQ940VCYioInIb8jKMrK9u855OEJdFC+HmWAZTnC+Ag==
dependencies:
debug "^4.1.1"
glob "^7.1.4"
is-glob "^4.0.1"
lodash.unescape "4.0.1"
semver "^6.3.0"
tsutils "^3.17.1"

"@zeit/ncc@^0.20.5":
version "0.20.5"
resolved "https://registry.yarnpkg.com/@zeit/ncc/-/ncc-0.20.5.tgz#a41af6e6bcab4a58f4612bae6137f70bce0192e3"
Expand Down Expand Up @@ -1028,6 +1054,11 @@ domexception@^1.0.1:
dependencies:
webidl-conversions "^4.0.2"

dotenv@^8.2.0:
version "8.2.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a"
integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==

ecc-jsbn@~0.1.1:
version "0.1.2"
resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz#3a83a904e54353287874c564b7549386849a98c9"
Expand Down Expand Up @@ -1143,6 +1174,13 @@ eslint-plugin-import@^2.18.2:
read-pkg-up "^2.0.0"
resolve "^1.11.0"

eslint-plugin-jest@^23.0.4:
version "23.0.4"
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-23.0.4.tgz#1ab81ffe3b16c5168efa72cbd4db14d335092aa0"
integrity sha512-OaP8hhT8chJNodUPvLJ6vl8gnalcsU/Ww1t9oR3HnGdEWjm/DdCCUXLOral+IPGAeWu/EwgVQCK/QtxALpH1Yw==
dependencies:
"@typescript-eslint/experimental-utils" "^2.5.0"

eslint-plugin-node@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-node/-/eslint-plugin-node-10.0.0.tgz#fd1adbc7a300cf7eb6ac55cf4b0b6fc6e577f5a6"
Expand Down Expand Up @@ -1552,7 +1590,7 @@ glob-parent@^5.0.0:
dependencies:
is-glob "^4.0.1"

glob@^7.1.1, glob@^7.1.2, glob@^7.1.3:
glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4:
version "7.1.6"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6"
integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==
Expand Down Expand Up @@ -2559,6 +2597,11 @@ lodash.sortby@^4.7.0:
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=

lodash.unescape@4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/lodash.unescape/-/lodash.unescape-4.0.1.tgz#bf2249886ce514cda112fae9218cdc065211fc9c"
integrity sha1-vyJJiGzlFM2hEvrpIYzcBlIR/Jw=

lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15:
version "4.17.15"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
Expand Down Expand Up @@ -3491,7 +3534,7 @@ sax@>=0.6.0, sax@^1.2.1, sax@^1.2.4:
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==

semver@^6.0.0, semver@^6.1.0, semver@^6.1.2, semver@^6.2.0:
semver@^6.0.0, semver@^6.1.0, semver@^6.1.2, semver@^6.2.0, semver@^6.3.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
Expand Down Expand Up @@ -3926,11 +3969,18 @@ tr46@^1.0.1:
dependencies:
punycode "^2.1.0"

tslib@^1.9.0:
tslib@^1.8.1, tslib@^1.9.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"
integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==

tsutils@^3.17.1:
version "3.17.1"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.17.1.tgz#ed719917f11ca0dee586272b2ac49e015a2dd759"
integrity sha512-kzeQ5B8H3w60nFY2g8cJIuH7JDpsALXySGtwGJ0p2LSjLgay3NdIpqq5SoOBe46bKDW2iq25irHCr8wjomUS2g==
dependencies:
tslib "^1.8.1"

tunnel-agent@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd"
Expand Down

0 comments on commit b4da5bd

Please sign in to comment.