Skip to content

Commit

Permalink
feat: more integration tests for Get /wallet, initialize Post /wallet…
Browse files Browse the repository at this point in the history
… test
  • Loading branch information
WeiyuSun committed Jul 26, 2023
1 parent 373e22b commit 91dd15d
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 4 deletions.
39 changes: 35 additions & 4 deletions __tests__/wallet-get.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,27 @@ describe('Wallet: Get wallets of an account', () => {

const walletService = new WalletService();

for (let i = 0; i < 1010; i += 1) {
for (let i = 0; i < 10; i += 1) {
await walletService.createWallet(seed.wallet.id, `test${i}`)
}

const res = await walletService.getAllWallets(seed.wallet.id);
expect(res.count).to.eq(1011);
expect(res.count).to.eq(11);
});

beforeEach(async () => {
sinon.restore();
});

it('Get wallets of WalletA without params, success', async () => {
it('Get wallets of WalletA without params', async () => {
const res = await request(server)
.get('/wallets')
.set('treetracker-api-key', apiKey)
.set('content-type', 'application/json')
.set('Authorization', `Bearer ${bearerTokenA}`);

expect(res).property('statusCode').to.eq(200);
expect(res.body.total).to.eq(1000);
expect(res.body.total).to.eq(11);

const resB = await request(server)
.get('/wallets')
Expand Down Expand Up @@ -105,4 +105,35 @@ describe('Wallet: Get wallets of an account', () => {
expect(res.body.total).to.eq(1);
expect(res.body.wallets[0].name).to.eq(seed.walletB.name);
})

it('Get wallet with offset val', async () => {
let res = await request(server)
.get('/wallets')
.query({offset: 0})
.set('treetracker-api-key', apiKey)
.set('content-type', 'application/json')
.set('Authorization', `Bearer ${bearerTokenA}`);

expect(res).property('statusCode').to.eq(200);
expect(res.body.total).to.eq(11);

res = await request(server)
.get('/wallets')
.query({limit: 100, offset: 2})
.set('treetracker-api-key', apiKey)
.set('content-type', 'application/json')
.set('Authorization', `Bearer ${bearerTokenA}`);

expect(res).property('statusCode').to.eq(200);
expect(res.body.total).to.eq(9);

res = await request(server)
.get('/wallets')
.query({limit: 2, offset: 0})
.set('treetracker-api-key', apiKey)
.set('content-type', 'application/json')
.set('Authorization', `Bearer ${bearerTokenA}`);
expect(res).property('statusCode').to.eq(200);
expect(res.body.total).to.eq(2);
})
})
56 changes: 56 additions & 0 deletions __tests__/wallet-post.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require('dotenv').config();
const request = require('supertest');
const {expect} = require('chai');
const sinon = require('sinon');
const chai = require('chai');
const server = require('../server/app');
const seed = require('./seed');
chai.use(require('chai-uuid'));

const {apiKey} = seed;

describe('Wallet: Get wallets of an account', () => {
let bearerTokenA;
let bearerTokenB;

before(async () => {
await seed.clear();
await seed.seed();

{
// Authorizes before each of the follow tests
const res = await request(server)
.post('/auth')
.set('treetracker-api-key', apiKey)
.send({
wallet: seed.wallet.name,
password: seed.wallet.password,
});

expect(res).to.have.property('statusCode', 200);
bearerTokenA = res.body.token;
expect(bearerTokenA).to.match(/\S+/);
}

{
// Authorizes before each of the follow tests
const res = await request(server)
.post('/auth')
.set('treetracker-api-key', apiKey)
.send({
wallet: seed.walletB.name,
password: seed.walletB.password,
});
expect(res).to.have.property('statusCode', 200);
bearerTokenB = res.body.token;
expect(bearerTokenB).to.match(/\S+/);
}
});


beforeEach(async () => {
sinon.restore();
});


})

0 comments on commit 91dd15d

Please sign in to comment.