-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: integration test for Get /wallet
- Loading branch information
Showing
1 changed file
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
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 WalletService = require('../server/services/WalletService'); | ||
|
||
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+/); | ||
} | ||
|
||
const walletService = new WalletService(); | ||
|
||
for (let i = 0; i < 1010; i += 1) { | ||
await walletService.createWallet(seed.wallet.id, `test${i}`) | ||
} | ||
|
||
const res = await walletService.getAllWallets(seed.wallet.id); | ||
expect(res.count).to.eq(1011); | ||
}); | ||
|
||
beforeEach(async () => { | ||
sinon.restore(); | ||
}); | ||
|
||
it('Get wallets of WalletA without params, success', 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); | ||
|
||
const resB = await request(server) | ||
.get('/wallets') | ||
.set('treetracker-api-key', apiKey) | ||
.set('content-type', 'application/json') | ||
.set('Authorization', `Bearer ${bearerTokenB}`); | ||
|
||
expect(resB).property('statusCode').to.eq(200); | ||
expect(resB.body.total).to.eq(2); | ||
}); | ||
|
||
it('Get wallet by wallet name, success', async () => { | ||
const res = await request(server) | ||
.get('/wallets') | ||
.query({name: 'walletB'}) | ||
.set('treetracker-api-key', apiKey) | ||
.set('content-type', 'application/json') | ||
.set('Authorization', `Bearer ${bearerTokenB}`); | ||
|
||
expect(res).property('statusCode').to.eq(200); | ||
expect(res.body.total).to.eq(1); | ||
}) | ||
|
||
it('Get wallet which is managed by other account', async () => { | ||
const res = await request(server) | ||
.get(`/wallets`) | ||
.query({name: 'test0'}) | ||
.set('treetracker-api-key', apiKey) | ||
.set('content-type', 'application/json') | ||
.set('Authorization', `Bearer ${bearerTokenB}`); | ||
|
||
expect(res).property('statusCode').to.eq(200); | ||
expect(res.body.total).to.eq(1); | ||
expect(res.body.wallets[0].name).to.eq(seed.walletB.name); | ||
}) | ||
}) |