-
Notifications
You must be signed in to change notification settings - Fork 308
/
utils.test.ts
52 lines (44 loc) · 1.62 KB
/
utils.test.ts
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
import { getApiKeys } from '../../src/transport/utils'
import { config } from '../../src/config'
import { AdapterInputError } from '@chainlink/external-adapter-framework/validation/error'
describe('execute', () => {
const signingKey = 'fake-signing-key'
const accessKey = 'fake-access-key'
const passPhrase = 'fake-passphrase'
const signingKey1 = 'fake-signing-key1'
const accessKey1 = 'fake-access-key1'
const passPhrase1 = 'fake-passphrase1'
beforeAll(async () => {
config.initialize()
config.settings.ACCESS_KEY = accessKey
config.settings.SIGNING_KEY = signingKey
config.settings.PASSPHRASE = passPhrase
})
describe('no apiKey provided', () => {
it('should use default env variable', async () => {
const [signingKey, accessKey, passPhrase] = getApiKeys('', config.settings)
expect(signingKey).toBe(signingKey)
expect(accessKey).toBe(accessKey)
expect(passPhrase).toBe(passPhrase)
})
})
describe('apiKey provided', () => {
it('should use apiKey', async () => {
process.env['KEY1_ACCESS_KEY'] = accessKey1
process.env['KEY1_PASSPHRASE'] = passPhrase1
process.env['KEY1_SIGNING_KEY'] = signingKey1
const [signingKey, accessKey, passPhrase] = getApiKeys('KEY1', config.settings)
expect(signingKey).toBe(signingKey1)
expect(accessKey).toBe(accessKey1)
expect(passPhrase).toBe(passPhrase1)
})
})
describe('invalid apiKey provided', () => {
it('should throw exception', async () => {
const call = () => {
getApiKeys('KEY2', config.settings)
}
expect(call).toThrow(AdapterInputError)
})
})
})