Skip to content

Commit

Permalink
🐛 bug: fixed test bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
t-kings committed Sep 10, 2021
1 parent d4c9c72 commit ff5af99
Show file tree
Hide file tree
Showing 21 changed files with 270 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PUBLIC_KEY=
SECRET_KEY=
PRIVATE_KEY=
ACCOUNT_NUMBER=
ACCOUNT_BANK=
ACCOUNT_NAME=
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
```bash
const CoinForBarter = require('coinforbarter -node-v3');

const c4b = new CoinForBarter(PUBLIC_KEY, SECRET_KEY, SECRET_HASH);
const c4b = new CoinForBarter(PUBLIC_KEY, PRIVATE_KEY, SECRET_HASH);

const customers = c4b.Customers.findAll();
```

For staging, Use TEST API Keys. For production, use LIVE API KEYS. You can get your PUBLIC_KEY and SECRET_KEY from the CoinForBarter dashboard.
For staging, Use TEST API Keys. For production, use LIVE API KEYS. You can get your PUBLIC_KEY and PRIVATE_KEY from the CoinForBarter dashboard.

Go [here](https://dashboard.coinforbarter.com/settings/api) to get your API Keys.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
},
"engines": {
"node": "<=14.17.1"
"node": ">=14.1"
},
"keywords": [
"bitcoin",
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ export default class CoinForBarter {
private readonly Request: CoinForBarterRequest;
constructor(
private readonly publicKey: string,
private readonly secretKey: string,
private readonly privateKey: string,
private readonly secretHash: string = '',
) {
this.Request = new CoinForBarterRequest(this.publicKey, this.secretKey);
this.Request = new CoinForBarterRequest(this.publicKey, this.privateKey);
this.Payment = new Payment(this.Request, this.publicKey);
this.Payout = new Payout(this.Request);
this.Transfer = new Transfer(this.Request);
Expand All @@ -41,6 +41,7 @@ export default class CoinForBarter {
this.BankAccount = new BankAccount(this.Request);
this.Customer = new Customer(this.Request);
this.Misc = new Misc(this.Request);
this.Transaction = new Transaction(this.Request);
this.Webhook = new Webhook(this.secretHash);
}
}
15 changes: 15 additions & 0 deletions src/lib/BankAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,19 @@ export class BankAccount {
statusCode,
};
}

async remove(bankAccountId: string) {
const { data, status, message, statusCode } = await this.request.call(
`${this.path}/account/archive/${bankAccountId}`,
'get',
{},
true,
);
return {
data,
status,
message,
statusCode,
};
}
}
2 changes: 1 addition & 1 deletion src/lib/Misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class Misc {
return { status, message, statusCode, data };
}

async getBalance(): Promise<CoinForBarterResponse<BalanceResponse[]>> {
async getBalances(): Promise<CoinForBarterResponse<BalanceResponse[]>> {
const { status, message, statusCode, data } = await this.request.call(
'/balances',
'get',
Expand Down
79 changes: 79 additions & 0 deletions src/lib/Wallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { CoinForBarterRequest } from 'src/services';
import {
CoinForBarterResponse,
CreateWalletBody,
CreateWalletResponse,
WalletQuery,
} from 'src/types';

export class Wallet {
path = '/wallets';
constructor(private readonly request: CoinForBarterRequest) {}

async create(
body: CreateWalletBody,
): Promise<CoinForBarterResponse<CreateWalletResponse>> {
const { status, message, statusCode, data } = await this.request.call(
this.path,
'post',
body,
true,
);
return {
status,
message,
statusCode,
data,
};
}

async findAll(
query: WalletQuery = {},
): Promise<CoinForBarterResponse<CreateWalletResponse[]>> {
const queryString = this.request.makeQueryString(query);
const { status, message, statusCode, data } = await this.request.call(
`${this.path}${queryString}`,
'get',
{},
true,
);
return {
status,
message,
statusCode,
data,
};
}

async findOne(
id: string,
): Promise<CoinForBarterResponse<CreateWalletResponse>> {
const { status, message, statusCode, data } = await this.request.call(
`${this.path}/${id}`,
'get',
{},
true,
);
return {
status,
message,
statusCode,
data,
};
}

async remove(id: string): Promise<CoinForBarterResponse<null>> {
const { status, message, statusCode, data } = await this.request.call(
`${this.path}/${id}`,
'patch',
undefined,
true,
);
return {
status,
message,
statusCode,
data,
};
}
}
8 changes: 4 additions & 4 deletions src/services/Request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { CoinForBarterStatus } from '../types';
import { RequestResponseSchema } from '../types/request';

export class CoinForBarterRequest {
private url = 'https://api.coinforbarter.com/v1';
private url = 'https://coinforbarter-api.herokuapp.com/v1';
constructor(
private readonly publicKey: string,
private readonly secretKey: string,
private readonly privateKey: string,
) {}

async call(
Expand All @@ -22,7 +22,7 @@ export class CoinForBarterRequest {
if (method === 'get' || method === 'delete') {
if (useToken) {
const headers = {
Authorization: `Bearer ${this.secretKey}`,
Authorization: `Bearer ${this.privateKey}`,
'Content-Type': contentType,
};
request = await axios[method](url, { headers });
Expand All @@ -37,7 +37,7 @@ export class CoinForBarterRequest {
if (method !== 'get' && method !== 'delete') {
if (useToken) {
const headers = {
Authorization: `Bearer ${this.secretKey}`,
Authorization: `Bearer ${this.privateKey}`,
'Content-Type': contentType,
};
request = await axios[method](url, body, { headers });
Expand Down
27 changes: 22 additions & 5 deletions src/test/bank-account.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import {

describe('BankAccount', () => {
const publicKey = process.env.PUBLIC_KEY;
const secretKey = process.env.SECRET_KEY;
const privateKey = process.env.PRIVATE_KEY;

const request = new CoinForBarterRequest(publicKey, secretKey);
const request = new CoinForBarterRequest(publicKey, privateKey);

const bankAccount = new BankAccount(request);

let bankAccountId = '';

it('should be defined', () => {
expect(bankAccount).toBeDefined();
});
Expand Down Expand Up @@ -85,6 +87,7 @@ describe('BankAccount', () => {
const respWithParam = await bankAccount.findAll(param);
const resp = await bankAccount.findAll();
if (resp.status === CoinForBarterStatus.Success) {
bankAccountId = resp.data[0].id;
expect(resp.data.length).toBeGreaterThan(0);
} else {
expect(resp.statusCode).toEqual(404);
Expand All @@ -103,10 +106,9 @@ describe('BankAccount', () => {
});

it('should find one bank account from id', async () => {
const id = process.env.BANK_ACCOUNT_ID;
const resp = await bankAccount.findOne(id);
const resp = await bankAccount.findOne(bankAccountId);
if (resp.status === CoinForBarterStatus.Success) {
return expect(resp.data.id).toBe(id);
return expect(resp.data.id).toBe(bankAccountId);
} else {
expect(resp.statusCode).not.toEqual(200);
}
Expand Down Expand Up @@ -145,4 +147,19 @@ describe('BankAccount', () => {
}
});
});

describe('remove', () => {
it('should be defined', () => {
expect(bankAccount.remove).toBeDefined();
});

it('should make an account primary', async () => {
const resp = await bankAccount.remove(bankAccountId);
if (resp.status === CoinForBarterStatus.Success) {
return expect(resp.statusCode).toEqual(204);
} else {
return expect(resp.statusCode).not.toEqual(200);
}
});
});
});
4 changes: 2 additions & 2 deletions src/test/customer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { CoinForBarterRequest } from '../services';

describe('customer', () => {
const publicKey = process.env.PUBLIC_KEY;
const secretKey = process.env.SECRET_KEY;
const privateKey = process.env.PRIVATE_KEY;

const email = process.env.EMAIL;
const phoneNumber = process.env.PHONE_NUMBER;
const fullName = process.env.EMAIL;
const request = new CoinForBarterRequest(publicKey, secretKey);
const request = new CoinForBarterRequest(publicKey, privateKey);

const customer = new Customer(request);

Expand Down
20 changes: 2 additions & 18 deletions src/test/misc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { CoinForBarterRequest } from '../services/Request';

describe('misc', () => {
const publicKey = process.env.PUBLIC_KEY;
const secretKey = process.env.SECRET_KEY;
const privateKey = process.env.PRIVATE_KEY;

const request = new CoinForBarterRequest(publicKey, secretKey);
const request = new CoinForBarterRequest(publicKey, privateKey);

const misc = new Misc(request);

Expand All @@ -30,22 +30,6 @@ describe('misc', () => {
});
});

describe('getBalance', () => {
it('should be defined', () => {
expect(misc.getBalance).toBeDefined();
});

it('should find all countries', async () => {
const resp = await misc.getBalance();

if (resp.status === CoinForBarterStatus.Success) {
expect(resp.data.length).toBeGreaterThan(0);
} else {
expect(resp.statusCode).toEqual(404);
}
});
});

describe('getCurrencies', () => {
it('should be defined', () => {
expect(misc.getCurrencies).toBeDefined();
Expand Down
4 changes: 2 additions & 2 deletions src/test/payment-plan-subscribers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { CoinForBarterRequest } from '../services/Request';

describe('paymentPlanSubscriber', () => {
const publicKey = process.env.PUBLIC_KEY;
const secretKey = process.env.SECRET_KEY;
const privateKey = process.env.PRIVATE_KEY;

const email = process.env.EMAIL;
const phoneNumber = process.env.PHONE_NUMBER;
const fullName = process.env.EMAIL;
const paymentPlanId = process.env.PAYMENT_PLAN_ID;
const request = new CoinForBarterRequest(publicKey, secretKey);
const request = new CoinForBarterRequest(publicKey, privateKey);

const paymentPlanSubscriber = new PaymentPlanSubscriber(request);

Expand Down
4 changes: 2 additions & 2 deletions src/test/payment-plan.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { CoinForBarterStatus } from '../types/response.types';

describe('paymentPlan', () => {
const publicKey = process.env.PUBLIC_KEY;
const secretKey = process.env.SECRET_KEY;
const privateKey = process.env.PRIVATE_KEY;

const request = new CoinForBarterRequest(publicKey, secretKey);
const request = new CoinForBarterRequest(publicKey, privateKey);

const paymentPlan = new PaymentPlan(request);

Expand Down
4 changes: 2 additions & 2 deletions src/test/payment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { CoinForBarterStatus } from '../types/response.types';

describe('Payment', () => {
const publicKey = process.env.PUBLIC_KEY;
const secretKey = process.env.SECRET_KEY;
const privateKey = process.env.PRIVATE_KEY;

const request = new CoinForBarterRequest(publicKey, secretKey);
const request = new CoinForBarterRequest(publicKey, privateKey);
const id = process.env.PAYMENT_ID;

const currency = 'DOGE';
Expand Down
4 changes: 2 additions & 2 deletions src/test/payout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { CoinForBarterStatus } from '../types/response.types';

describe('payout', () => {
const publicKey = process.env.PUBLIC_KEY;
const secretKey = process.env.SECRET_KEY;
const privateKey = process.env.PRIVATE_KEY;

const request = new CoinForBarterRequest(publicKey, secretKey);
const request = new CoinForBarterRequest(publicKey, privateKey);

const payout = new Payout(request);

Expand Down
4 changes: 2 additions & 2 deletions src/test/transaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { TransactionQuery } from '../types/transaction.type';
import { CoinForBarterStatus } from '../types/response.types';
describe('Transaction', () => {
const publicKey = process.env.PUBLIC_KEY;
const secretKey = process.env.SECRET_KEY;
const privateKey = process.env.PRIVATE_KEY;

const request = new CoinForBarterRequest(publicKey, secretKey);
const request = new CoinForBarterRequest(publicKey, privateKey);

const transaction = new Transaction(request);

Expand Down
4 changes: 2 additions & 2 deletions src/test/transfer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { CoinForBarterStatus } from '../types/response.types';

describe('Transfer', () => {
const publicKey = process.env.PUBLIC_KEY;
const secretKey = process.env.SECRET_KEY;
const privateKey = process.env.PRIVATE_KEY;
const accountNumber = process.env.ACCOUNT_NUMBER;
const walletAddress = process.env.WALLET_ADDRESS;
const walletNetwork = process.env.WALLET_NETWORK;

const request = new CoinForBarterRequest(publicKey, secretKey);
const request = new CoinForBarterRequest(publicKey, privateKey);

const transfer = new Transfer(request);

Expand Down
4 changes: 2 additions & 2 deletions src/test/wallet-address.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { CoinForBarterStatus } from '../types/response.types';

describe('WalletAddress', () => {
const publicKey = process.env.PUBLIC_KEY;
const secretKey = process.env.SECRET_KEY;
const privateKey = process.env.PRIVATE_KEY;

const request = new CoinForBarterRequest(publicKey, secretKey);
const request = new CoinForBarterRequest(publicKey, privateKey);

const walletAddress = new WalletAddress(request);

Expand Down
Loading

0 comments on commit ff5af99

Please sign in to comment.