Skip to content

Commit

Permalink
Merge pull request #48 from tiagosiebler/testci
Browse files Browse the repository at this point in the history
feat(): configure e2e tests
  • Loading branch information
tiagosiebler authored Sep 30, 2024
2 parents b129712 + 1602826 commit 34c2031
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 37 deletions.
37 changes: 27 additions & 10 deletions .github/workflows/e2etest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
12 changes: 8 additions & 4 deletions test/CBAdvancedClient/private.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CBAdvancedTradeClient } from '../../src/index.js';
import { getTestProxy } from '../proxy.util.js';

describe('CBAdvancedTradeClient PRIVATE', () => {
const account = {
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion test/CBAdvancedClient/public.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
12 changes: 8 additions & 4 deletions test/CBAppClient/private.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CBAppClient } from '../../src/index.js';
import { getTestProxy } from '../proxy.util.js';

let accId = '';

Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion test/CBAppClient/public.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
16 changes: 10 additions & 6 deletions test/CBExchangeClient/private.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CBExchangeClient } from '../../src/index.js';
import { getTestProxy } from '../proxy.util.js';

describe('CBExchangeClient PRIVATE', () => {
const account = {
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion test/CBExchangeClient/public.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
14 changes: 9 additions & 5 deletions test/CBInternationalClient/private.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CBInternationalClient } from '../../src/index.js';
import { getTestProxy } from '../proxy.util.js';

describe.skip('CBInternationalClient PRIVATE', () => {
const account = {
Expand All @@ -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();
Expand Down
14 changes: 9 additions & 5 deletions test/CBPrimeClient/private.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CBPrimeClient } from '../../src/index.js';
import { getTestProxy } from '../proxy.util.js';

describe.skip('CBPrimeClient PRIVATE', () => {
const account = {
Expand All @@ -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;

Expand Down
26 changes: 26 additions & 0 deletions test/proxy.util.ts
Original file line number Diff line number Diff line change
@@ -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',
},
};
}

0 comments on commit 34c2031

Please sign in to comment.