Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
coreh committed Jun 6, 2018
1 parent 454f11e commit cb7643b
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 16 deletions.
95 changes: 79 additions & 16 deletions tests/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Zoop from '../lib';
import Zoop, { Marketplace } from '../lib';

const TEST_API_KEY = 'zpk_test_EzCkzFFKibGQU6HFq7EYVuxI';
const TEST_NONEXISTENT_ID = '87df28a2236e173b45ea8b0d049cf62b';
const TEST_MARKETPLACE_ID = '3249465a7753536b62545a6a684b0000';
const TEST_BUYER_ID = '19355ed168914b57b564e23ce41b48c3';
const TEST_BUYER_CREATION_INFO = {
first_name: 'Tester',
last_name: 'McTester',
Expand All @@ -17,26 +19,87 @@ const TEST_BUYER_CREATION_INFO = {
neighborhood: 'Test',
},
};
const TEST_TRANSACTION_ID = '01ee71b399144a20822ea93c965974d3';

it('should create the API client', async () => {
new Zoop(TEST_API_KEY);
let zoop: Zoop;
let marketplace: Marketplace;

beforeAll(() => {
zoop = new Zoop(TEST_API_KEY);
marketplace = zoop.marketplace(TEST_MARKETPLACE_ID);
});

it('should retrieve marketplace info', async () => {
const zoop = new Zoop(TEST_API_KEY);
const marketplaceInfo = await zoop.marketplace(TEST_MARKETPLACE_ID).get();
expect(marketplaceInfo).toBeDefined();
describe('marketplace', () => {
it('should retrieve marketplace info', async () => {
const marketplaceInfo = await zoop.marketplace(TEST_MARKETPLACE_ID).get();
expect(marketplaceInfo).toBeDefined();
expect(marketplaceInfo).toBeInstanceOf(Object);
expect(marketplaceInfo!.id).toEqual(TEST_MARKETPLACE_ID);
});

it('should throw when attempting to access another marketplace', async () => {
const marketplaceInfoPromise = zoop.marketplace(TEST_NONEXISTENT_ID).get();
expect(marketplaceInfoPromise).rejects.toThrow();
});
});

it('should create/retrieve buyers', async () => {
const zoop = new Zoop(TEST_API_KEY);
const marketplace = zoop.marketplace(TEST_MARKETPLACE_ID);
describe('buyer', () => {
it('should create buyer', async () => {
const buyerInfo = await marketplace.createBuyer(TEST_BUYER_CREATION_INFO);
expect(buyerInfo).toBeDefined();
expect(buyerInfo).toBeInstanceOf(Object);
expect(typeof buyerInfo.id).toBe('string');
});

it('should retrieve buyer', async () => {
const buyerInfo = await marketplace.buyer(TEST_BUYER_ID).get();
expect(buyerInfo).toBeDefined();
expect(buyerInfo).toBeInstanceOf(Object);
expect(buyerInfo!.id).toEqual(TEST_BUYER_ID);
});

it('should return undefined when buyer does not exist', async () => {
const buyerInfo = await marketplace.buyer(TEST_NONEXISTENT_ID).get();
expect(buyerInfo).toBeUndefined();
});

it('should list buyers', async () => {
let count = 0;

for await (const buyer of marketplace.listBuyers()) {
expect(buyer).toBeDefined();

// No need to iterate over all buyers
if (++count > 200) {
break;
}
}
});
});

describe('transaction', () => {
it('should retrieve transaction', async () => {
const transactionInfo = await marketplace.transaction(TEST_TRANSACTION_ID).get();
expect(transactionInfo).toBeDefined();
expect(transactionInfo).toBeInstanceOf(Object);
expect(transactionInfo!.id).toEqual(TEST_TRANSACTION_ID);
});

it('should return undefined when transaction does not exist', async () => {
const transactionInfo = await marketplace.transaction(TEST_NONEXISTENT_ID).get();
expect(transactionInfo).toBeUndefined();
});

it('should list transactions', async () => {
let count = 0;

const createdBuyerInfo = await marketplace.createBuyer(TEST_BUYER_CREATION_INFO);
expect(createdBuyerInfo).toBeDefined();
expect(typeof createdBuyerInfo.id).toBe('string');
for await (const transaction of marketplace.listTransactions()) {
expect(transaction).toBeDefined();

const retrievedBuyerInfo = await marketplace.buyer(createdBuyerInfo.id).get();
expect(retrievedBuyerInfo).toBeDefined();
expect(retrievedBuyerInfo).toEqual(createdBuyerInfo);
// No need to iterate over all transactions
if (++count > 200) {
break;
}
}
});
});
4 changes: 4 additions & 0 deletions tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../tsconfig.json",
"exclude": []
}

0 comments on commit cb7643b

Please sign in to comment.