Skip to content

Commit

Permalink
chore(): misc test improvements, including newline escape handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagosiebler committed Sep 27, 2024
1 parent f9f5d6b commit b129712
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"scripts": {
"clean": "rm -rf dist",
"build": "npm run clean && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && bash ./postBuild.sh",
"test": "jest --passWithNoTests"
"test": "jest --passWithNoTests",
"test:watch": "jest --watch --passWithNoTests"
},
"main": "dist/cjs/index.js",
"module": "dist/mjs/index.js",
Expand Down
8 changes: 5 additions & 3 deletions test/CBAdvancedClient/private.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { CBAdvancedTradeClient } from '../../src/index.js';

describe('CBAdvancedTradeClient PRIVATE', () => {
const account = {
key: process.env.CB_ADV_API_KEY_NAME,
secret: process.env.CB_ADV_API_PRIVATE_KEY,
// The new line characters can be a bit unpredictable depending on the OS.
// Simplest is to ensure they're replaced into the correct format (if incorrect).
key: process.env.CB_ADV_API_KEY_NAME?.replace(/\\n/g, '\n'),
secret: process.env.CB_ADV_API_PRIVATE_KEY?.replace(/\\n/g, '\n'),
};

const rest = new CBAdvancedTradeClient({
Expand Down Expand Up @@ -59,7 +61,7 @@ describe('CBAdvancedTradeClient PRIVATE', () => {
whatever: true,
});
} catch (e: any) {
// These are deliberatly restricted API keys. If the response is a permission error, it confirms the sign + request was OK and permissions were denied.
// These are deliberately restricted API keys. If the response is a permission error, it confirms the sign + request was OK and permissions were denied.
// console.log(`err "${expect.getState().currentTestName}"`, e?.body);
const responseBody = e?.body;
expect(responseBody).toMatchObject({
Expand Down
11 changes: 6 additions & 5 deletions test/CBAppClient/private.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ let accId = '';

describe('CBAppClient PRIVATE', () => {
const account = {
key: process.env.CB_APP_API_KEY_NAME,
secret: process.env.CB_APP_API_PRIVATE_KEY,
key: process.env.CB_APP_API_KEY_NAME?.replace(/\\n/g, '\n'),
secret: process.env.CB_APP_API_PRIVATE_KEY?.replace(/\\n/g, '\n'),
};

const rest = new CBAppClient({
Expand Down Expand Up @@ -65,13 +65,14 @@ describe('CBAppClient PRIVATE', () => {
whatever: true,
});
} catch (e: any) {
// These are deliberatly restricted API keys. If the response is a permission error, it confirms the sign + request was OK and permissions were denied.
// These are deliberately restricted API keys. If the response is a permission error, it confirms the sign + request was OK and permissions were denied.
// console.log(`err "${expect.getState().currentTestName}"`, e?.body);
const responseBody = e?.body.errors[0];

expect(responseBody).toMatchObject({
id: 'invalid_scope',
id: expect.any(String),
message: expect.any(String),
url: expect.any(String),
// url: expect.any(String),
});
}
});
Expand Down
12 changes: 6 additions & 6 deletions test/CBExchangeClient/private.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { CBExchangeClient } from '../../src/index.js';

describe('CBExchangeClient PRIVATE', () => {
const account = {
key: process.env.CB_EXCHANGE_API_KEY_NAME_EXCH,
secret: process.env.CB_EXCHANGE_API_PRIVATE_KEY_EXCH,
passphrase: process.env.CB_EXCHANGE_API_PASSPHRASE_EXCH,
key: process.env.CB_EXCHANGE_API_KEY,
secret: process.env.CB_EXCHANGE_API_SECRET,
passphrase: process.env.CB_EXCHANGE_API_PASSPHRASE,
useSandbox: process.env.CB_EXCHANGE_USE_SANDBOX === 'true',
};

Expand Down Expand Up @@ -48,7 +48,7 @@ describe('CBExchangeClient PRIVATE', () => {

test('with params', async () => {
const res = await rest.getTransfers({ type: 'deposit' });
console.log(`res "${expect.getState().currentTestName}"`, res);
// console.log(`res "${expect.getState().currentTestName}"`, res);

expect(res).toEqual(expect.arrayContaining([expect.any(Object)]));
});
Expand All @@ -66,9 +66,9 @@ describe('CBExchangeClient PRIVATE', () => {
whatever: true,
});
} catch (e: any) {
// These are deliberatly restricted API keys. If the response is a permission error, it confirms the sign + request was OK and permissions were denied.
// These are deliberately restricted API keys. If the response is a permission error, it confirms the sign + request was OK and permissions were denied.
// console.log(`err "${expect.getState().currentTestName}"`, e?.body);
console.log(`Error, "${expect.getState().currentTestName}"`, e);
// console.log(`Error, "${expect.getState().currentTestName}"`, e);

const responseBody = e?.body;
expect(responseBody).toMatchObject({
Expand Down
6 changes: 3 additions & 3 deletions test/CBInternationalClient/private.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { CBInternationalClient } from '../../src/index.js';

describe.skip('CBInternationalClient PRIVATE', () => {
const account = {
key: process.env.CB_INTX_API_KEY_NAME,
secret: process.env.CB_INTX_API_PRIVATE_KEY,
key: process.env.CB_INTX_API_KEY,
secret: process.env.CB_INTX_API_SECRET,
passphrase: process.env.CB_INTX_API_PASSPHRASE,
};

Expand Down Expand Up @@ -62,7 +62,7 @@ describe.skip('CBInternationalClient PRIVATE', () => {
whatever: true,
});
} catch (e: any) {
// These are deliberatly restricted API keys. If the response is a permission error, it confirms the sign + request was OK and permissions were denied.
// These are deliberately restricted API keys. If the response is a permission error, it confirms the sign + request was OK and permissions were denied.
// console.log(`err "${expect.getState().currentTestName}"`, e?.body);
//console.log('Error, CBINTX, post req:', e);
const responseBody = e?.body;
Expand Down
6 changes: 3 additions & 3 deletions test/CBPrimeClient/private.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { CBPrimeClient } from '../../src/index.js';

describe.skip('CBPrimeClient PRIVATE', () => {
const account = {
key: process.env.CB_PRIME_API_KEY_NAME,
secret: process.env.CB_PRIME_API_PRIVATE_KEY,
key: process.env.CB_PRIME_API_KEY,
secret: process.env.CB_PRIME_API_SECRET,
passphrase: process.env.CB_PRIME_API_PASSPHRASE,
};

Expand Down Expand Up @@ -54,7 +54,7 @@ describe.skip('CBPrimeClient PRIVATE', () => {
whatever: true,
});
} catch (e: any) {
// These are deliberatly restricted API keys. If the response is a permission error, it confirms the sign + request was OK and permissions were denied.
// These are deliberately restricted API keys. If the response is a permission error, it confirms the sign + request was OK and permissions were denied.
// console.log(`err "${expect.getState().currentTestName}"`, e?.body);
//console.log('Error, CBPrime, post req:', e);
const responseBody = e?.body;
Expand Down

0 comments on commit b129712

Please sign in to comment.