From 1602826adef8d261cf8c7e25aa7b68ad1d847f4e Mon Sep 17 00:00:00 2001 From: Tiago Siebler Date: Mon, 30 Sep 2024 09:55:37 +0100 Subject: [PATCH] feat(): configure e2e tests --- .github/workflows/e2etest.yml | 37 ++++++++++++++++------ test/CBAdvancedClient/private.test.ts | 12 ++++--- test/CBAdvancedClient/public.test.ts | 3 +- test/CBAppClient/private.test.ts | 12 ++++--- test/CBAppClient/public.test.ts | 3 +- test/CBExchangeClient/private.test.ts | 16 ++++++---- test/CBExchangeClient/public.test.ts | 3 +- test/CBInternationalClient/private.test.ts | 14 +++++--- test/CBPrimeClient/private.test.ts | 14 +++++--- test/proxy.util.ts | 26 +++++++++++++++ 10 files changed, 103 insertions(+), 37 deletions(-) create mode 100644 test/proxy.util.ts diff --git a/.github/workflows/e2etest.yml b/.github/workflows/e2etest.yml index 4d2baa5..2e9b23a 100644 --- a/.github/workflows/e2etest.yml +++ b/.github/workflows/e2etest.yml @@ -33,13 +33,30 @@ jobs: - name: Check Build run: npm run build - # - name: Test - # run: npm run test - # env: - # API_KEY: ${{ secrets.API_KEY }} - # API_SECRET: ${{ secrets.API_SECRET }} - # PROXY_ENABLED: ${{ secrets.PROXY_ENABLED }} - # PROXY_HOST: ${{ secrets.PROXY_HOST }} - # PROXY_PASS: ${{ secrets.PROXY_PASS }} - # PROXY_PORT: ${{ secrets.PROXY_PORT }} - # PROXY_USER: ${{ secrets.PROXY_USER }} + - name: Test + run: npm run test + env: + CB_PRIME_API_KEY: ${{ secrets.CB_PRIME_API_KEY }} + CB_PRIME_API_SECRET: ${{ secrets.CB_PRIME_API_SECRET }} + CB_PRIME_API_PASSPHRASE: ${{ secrets.CB_PRIME_API_PASSPHRASE }} + + CB_INTX_API_KEY: ${{ secrets.CB_INTX_API_KEY }} + CB_INTX_API_SECRET: ${{ secrets.CB_INTX_API_SECRET }} + CB_INTX_API_PASSPHRASE: ${{ secrets.CB_INTX_API_PASSPHRASE }} + + CB_EXCHANGE_API_KEY: ${{ secrets.CB_EXCHANGE_API_KEY }} + CB_EXCHANGE_API_SECRET: ${{ secrets.CB_EXCHANGE_API_SECRET }} + CB_EXCHANGE_API_PASSPHRASE: ${{ secrets.CB_EXCHANGE_API_PASSPHRASE }} + CB_EXCHANGE_USE_SANDBOX: ${{ secrets.CB_EXCHANGE_USE_SANDBOX }} + + CB_APP_API_KEY_NAME: ${{ secrets.CB_APP_API_KEY_NAME }} + CB_APP_API_PRIVATE_KEY: ${{ secrets.CB_APP_API_PRIVATE_KEY }} + + CB_ADV_API_KEY_NAME: ${{ secrets.CB_ADV_API_KEY_NAME }} + CB_ADV_API_PRIVATE_KEY: ${{ secrets.CB_ADV_API_PRIVATE_KEY }} + + PROXY_ENABLED: ${{ secrets.PROXY_ENABLED }} + PROXY_HOST: ${{ secrets.PROXY_HOST }} + PROXY_PASS: ${{ secrets.PROXY_PASS }} + PROXY_PORT: ${{ secrets.PROXY_PORT }} + PROXY_USER: ${{ secrets.PROXY_USER }} diff --git a/test/CBAdvancedClient/private.test.ts b/test/CBAdvancedClient/private.test.ts index b3913cc..1088f35 100644 --- a/test/CBAdvancedClient/private.test.ts +++ b/test/CBAdvancedClient/private.test.ts @@ -1,4 +1,5 @@ import { CBAdvancedTradeClient } from '../../src/index.js'; +import { getTestProxy } from '../proxy.util.js'; describe('CBAdvancedTradeClient PRIVATE', () => { const account = { @@ -8,10 +9,13 @@ describe('CBAdvancedTradeClient PRIVATE', () => { secret: process.env.CB_ADV_API_PRIVATE_KEY?.replace(/\\n/g, '\n'), }; - const rest = new CBAdvancedTradeClient({ - apiKey: account.key, - apiSecret: account.secret, - }); + const rest = new CBAdvancedTradeClient( + { + apiKey: account.key, + apiSecret: account.secret, + }, + getTestProxy(), + ); it('should have credentials to test with', () => { expect(account.key).toBeDefined(); diff --git a/test/CBAdvancedClient/public.test.ts b/test/CBAdvancedClient/public.test.ts index 03d4584..c865e08 100644 --- a/test/CBAdvancedClient/public.test.ts +++ b/test/CBAdvancedClient/public.test.ts @@ -1,7 +1,8 @@ import { CBAdvancedTradeClient } from '../../src/index.js'; +import { getTestProxy } from '../proxy.util.js'; describe('CBAdvancedTradeClient PUBLIC', () => { - const rest = new CBAdvancedTradeClient(); + const rest = new CBAdvancedTradeClient({}, getTestProxy()); describe('public endpoints', () => { it('should succeed making a GET request', async () => { diff --git a/test/CBAppClient/private.test.ts b/test/CBAppClient/private.test.ts index d856f5c..e4012a4 100644 --- a/test/CBAppClient/private.test.ts +++ b/test/CBAppClient/private.test.ts @@ -1,4 +1,5 @@ import { CBAppClient } from '../../src/index.js'; +import { getTestProxy } from '../proxy.util.js'; let accId = ''; @@ -8,10 +9,13 @@ describe('CBAppClient PRIVATE', () => { secret: process.env.CB_APP_API_PRIVATE_KEY?.replace(/\\n/g, '\n'), }; - const rest = new CBAppClient({ - apiKey: account.key, - apiSecret: account.secret, - }); + const rest = new CBAppClient( + { + apiKey: account.key, + apiSecret: account.secret, + }, + getTestProxy(), + ); it('should have credentials to test with', () => { expect(account.key).toBeDefined(); diff --git a/test/CBAppClient/public.test.ts b/test/CBAppClient/public.test.ts index 106a273..f518866 100644 --- a/test/CBAppClient/public.test.ts +++ b/test/CBAppClient/public.test.ts @@ -1,7 +1,8 @@ import { CBAppClient } from '../../src/index.js'; +import { getTestProxy } from '../proxy.util.js'; describe('CBAppClient PUBLIC', () => { - const rest = new CBAppClient(); + const rest = new CBAppClient({}, getTestProxy()); describe('public endpoints', () => { it('should succeed making a GET request', async () => { diff --git a/test/CBExchangeClient/private.test.ts b/test/CBExchangeClient/private.test.ts index 45cf857..8dc8711 100644 --- a/test/CBExchangeClient/private.test.ts +++ b/test/CBExchangeClient/private.test.ts @@ -1,4 +1,5 @@ import { CBExchangeClient } from '../../src/index.js'; +import { getTestProxy } from '../proxy.util.js'; describe('CBExchangeClient PRIVATE', () => { const account = { @@ -8,12 +9,15 @@ describe('CBExchangeClient PRIVATE', () => { useSandbox: process.env.CB_EXCHANGE_USE_SANDBOX === 'true', }; - const rest = new CBExchangeClient({ - apiKey: account.key, - apiSecret: account.secret, - apiPassphrase: account.passphrase, - useSandbox: account.useSandbox, - }); + const rest = new CBExchangeClient( + { + apiKey: account.key, + apiSecret: account.secret, + apiPassphrase: account.passphrase, + useSandbox: account.useSandbox, + }, + getTestProxy(), + ); it('should have credentials to test with', () => { expect(account.key).toBeDefined(); diff --git a/test/CBExchangeClient/public.test.ts b/test/CBExchangeClient/public.test.ts index 9136b35..6139863 100644 --- a/test/CBExchangeClient/public.test.ts +++ b/test/CBExchangeClient/public.test.ts @@ -1,7 +1,8 @@ import { CBExchangeClient } from '../../src/index.js'; +import { getTestProxy } from '../proxy.util.js'; describe('CBExchangeClient PUBLIC', () => { - const rest = new CBExchangeClient(); + const rest = new CBExchangeClient({}, getTestProxy()); describe('public endpoints', () => { it('should succeed making a GET request', async () => { diff --git a/test/CBInternationalClient/private.test.ts b/test/CBInternationalClient/private.test.ts index 85d3c65..9f03a1b 100644 --- a/test/CBInternationalClient/private.test.ts +++ b/test/CBInternationalClient/private.test.ts @@ -1,4 +1,5 @@ import { CBInternationalClient } from '../../src/index.js'; +import { getTestProxy } from '../proxy.util.js'; describe.skip('CBInternationalClient PRIVATE', () => { const account = { @@ -7,11 +8,14 @@ describe.skip('CBInternationalClient PRIVATE', () => { passphrase: process.env.CB_INTX_API_PASSPHRASE, }; - const rest = new CBInternationalClient({ - apiKey: account.key, - apiSecret: account.secret, - apiPassphrase: account.passphrase, - }); + const rest = new CBInternationalClient( + { + apiKey: account.key, + apiSecret: account.secret, + apiPassphrase: account.passphrase, + }, + getTestProxy(), + ); it('should have credentials to test with', () => { expect(account.key).toBeDefined(); diff --git a/test/CBPrimeClient/private.test.ts b/test/CBPrimeClient/private.test.ts index 93eed75..a985765 100644 --- a/test/CBPrimeClient/private.test.ts +++ b/test/CBPrimeClient/private.test.ts @@ -1,4 +1,5 @@ import { CBPrimeClient } from '../../src/index.js'; +import { getTestProxy } from '../proxy.util.js'; describe.skip('CBPrimeClient PRIVATE', () => { const account = { @@ -7,11 +8,14 @@ describe.skip('CBPrimeClient PRIVATE', () => { passphrase: process.env.CB_PRIME_API_PASSPHRASE, }; - const rest = new CBPrimeClient({ - apiKey: account.key, - apiSecret: account.secret, - apiPassphrase: account.passphrase, - }); + const rest = new CBPrimeClient( + { + apiKey: account.key, + apiSecret: account.secret, + apiPassphrase: account.passphrase, + }, + getTestProxy(), + ); let portfolioId: string; diff --git a/test/proxy.util.ts b/test/proxy.util.ts new file mode 100644 index 0000000..5918391 --- /dev/null +++ b/test/proxy.util.ts @@ -0,0 +1,26 @@ +import { AxiosRequestConfig } from 'axios'; + +export function getTestProxy(): AxiosRequestConfig { + if (process.env.PROXY_ENABLED !== 'true') { + return {}; + } + const host = process.env.PROXY_HOST; + const port = process.env.PROXY_PORT; + const user = process.env.PROXY_USER; + const pass = process.env.PROXY_PASS; + if (!host || !port || !user || !pass) { + throw new Error('One or more env vars missing for proxy support'); + } + + return { + proxy: { + host, + port: Number(port), + auth: { + username: user, + password: pass, + }, + protocol: 'http', + }, + }; +}