Skip to content

Commit

Permalink
feat: all tests for /wallet included
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiyuSun committed Jul 26, 2023
1 parent 91dd15d commit 4bd22d1
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 7 deletions.
32 changes: 26 additions & 6 deletions __tests__/wallet-get.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('Wallet: Get wallets of an account', () => {
})

it('Get wallet with offset val', async () => {
let res = await request(server)
const res = await request(server)
.get('/wallets')
.query({offset: 0})
.set('treetracker-api-key', apiKey)
Expand All @@ -117,23 +117,43 @@ describe('Wallet: Get wallets of an account', () => {
expect(res).property('statusCode').to.eq(200);
expect(res.body.total).to.eq(11);

res = await request(server)
const resB = 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);
expect(resB).property('statusCode').to.eq(200);
expect(resB.body.total).to.eq(9);

res = await request(server)
const resC = 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(resC).property('statusCode').to.eq(200);
expect(resC.body.total).to.eq(2);
})

it('Get wallet by valid uuid', async () => {
const res = await request(server)
.get(`/wallets/${seed.walletC.id}`)
.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);
})

it('Get wallet by valid uuid which does not exist', async () => {
const res = await request(server)
.get(`/wallets/00a6fa25-df29-4701-9077-557932591766`)
.set('treetracker-api-key', apiKey)
.set('content-type', 'application/json')
.set('Authorization', `Bearer ${bearerTokenA}`);

expect(res).property('statusCode').to.eq(404);
})
})
52 changes: 51 additions & 1 deletion __tests__/wallet-post.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ const chai = require('chai');
const server = require('../server/app');
const seed = require('./seed');
chai.use(require('chai-uuid'));
const WalletService = require('../server/services/WalletService');

const {apiKey} = seed;

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

Expand Down Expand Up @@ -52,5 +53,54 @@ describe('Wallet: Get wallets of an account', () => {
sinon.restore();
});

it('create wallet by a valid wallet name', async () => {
const walletService = new WalletService();
const res = await request(server)
.post('/wallets')
.send({wallet: 'azAZ.-@0123456789'})
.set('treetracker-api-key', apiKey)
.set('content-type', 'application/json')
.set('Authorization', `Bearer ${bearerTokenA}`);

expect(res.body).contain({wallet: 'azAZ.-@0123456789'})
expect(res.body.id).to.exist;
await walletService.getById(res.body.id).then((wallet) => {
expect(wallet.name).to.eq('azAZ.-@0123456789');
})
})

it('create wallet by invalid name length', async () => {
const res = await request(server)
.post('/wallets')
.send({wallet: 'ab'})
.set('treetracker-api-key', apiKey)
.set('content-type', 'application/json')
.set('Authorization', `Bearer ${bearerTokenA}`);

expect(res.body.code).to.eq(422);

const resB = await request(server)
.post('/wallets')
.send({wallet: '2023.7.26CodingAtCanadaNiceToMeetYouuuuuuuuuuuuuuuu'})
.set('treetracker-api-key', apiKey)
.set('content-type', 'application/json')
.set('Authorization', `Bearer ${bearerTokenA}`);

expect(resB.body.code).to.eq(422);
})

it('create wallet with invalid characters', async () => {
const set = "~!#$%^&*()_+=[]\\{}|;':\",/<>?";

// eslint-disable-next-line no-restricted-syntax
for(const char of set){
const res = await request(server)
.post('/wallets')
.send({wallet: `test${char}`})
.set('treetracker-api-key', apiKey)
.set('content-type', 'application/json')
.set('Authorization', `Bearer ${bearerTokenA}`);
expect(res.body.code).to.eq(422);
}
})
})

0 comments on commit 4bd22d1

Please sign in to comment.