Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#369 rebuild integration test #379

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions __tests__/integration/auth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const { expect } = require('chai');
const chai = require('chai');
const server = require('../../server/app');
chai.use(require('chai-uuid'));
const Zaven = require('../mock-data/Zaven.json');
const testUtils = require('./testUtils');
const Zaven = require('../mock-data/wallet/Zaven.json');
const testUtils = require('../utils/testUtils');

describe('Authentication', () => {
let registeredUser;
Expand Down
8 changes: 4 additions & 4 deletions __tests__/integration/bundle-transfer-decline.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const { expect } = require('chai');
const chai = require('chai');
const server = require('../../server/app');
chai.use(require('chai-uuid'));
const Zaven = require('../mock-data/Zaven.json');
const Meisze = require('../mock-data/Meisze.json');
const testUtils = require('./testUtils');
const TokenA = require('../mock-data/TokenA');
const Zaven = require('../mock-data/wallet/Zaven.json');
const Meisze = require('../mock-data/wallet/Meisze.json');
const testUtils = require('../utils/testUtils');
const TokenA = require('../mock-data/token/TokenA.json');
const TransferEnums = require('../../server/utils/transfer-enum');

describe('Zaven request to send 1 token to Meisze', () => {
Expand Down
123 changes: 0 additions & 123 deletions __tests__/integration/testUtils.js

This file was deleted.

138 changes: 138 additions & 0 deletions __tests__/integration/wallet-get.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
require('dotenv').config();
const request = require('supertest');
const {expect} = require('chai');
const sinon = require('sinon');
const chai = require('chai');
const server = require('../../server/app');
chai.use(require('chai-uuid'));
const {registerAndLogin, clear, feedSubWallets} = require('../utils/testUtils');
const walletAInfo = require('../mock-data/wallet/walletA.json');
const walletBInfo = require('../mock-data/wallet/walletB.json');
const wallets = require('../mock-data/wallet/wallets.json');


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

before(async () => {
await clear();
})

beforeEach(async () => {
walletA = await registerAndLogin(walletAInfo);
// what registerAndLogin returned?
// walletA = {
// name: <string>,
// password: <string>,
// salt: <string>,
// logo_url: null,
// created_at: <time>,
// apiKey: <string>,
// token: <string> (the bearer token)
// }
walletB = await registerAndLogin(walletBInfo);
await feedSubWallets(walletA.id, wallets);
});

afterEach(async () => {
sinon.restore();
await clear();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another await clear(). I think you can just put it as the first statement in the beforeEach function, that way there won't be any duplicates

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do this because I can ensure the database is empty before the whole test starts. And also, I can clean the database after all tests are finished. so that the developer's database does not be contaminated by test data. if we just use beforeEach to clean the database, then after the last test is finished, the data will remain in the database(mysophobia???? lol). do you think this matters? If not, I will change it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay no problem, that's fine

})

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

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

const resB = await request(server)
.get('/wallets')
.set('treetracker-api-key', walletB.apiKey)
.set('content-type', 'application/json')
.set('Authorization', `Bearer ${walletB.token}`);

expect(resB).property('statusCode').to.eq(200);
expect(resB.body.total).to.eq(1);
});

it('Get wallet by wallet name, success', async () => {
const res = await request(server)
.get('/wallets')
.query({name: 'walletB'})
.set('treetracker-api-key', walletA.apiKey)
.set('content-type', 'application/json')
.set('Authorization', `Bearer ${walletA.token}`);

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: wallets[0].name})
.set('treetracker-api-key', walletB.apiKey)
.set('content-type', 'application/json')
.set('Authorization', `Bearer ${walletB.token}`);

expect(res).property('statusCode').to.eq(200);
expect(res.body.total).to.eq(1);
expect(res.body.wallets[0].name).to.eq(walletB.name);
})

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

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

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

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

const resC = await request(server)
.get('/wallets')
.query({limit: 2, offset: 0})
.set('treetracker-api-key', walletA.apiKey)
.set('content-type', 'application/json')
.set('Authorization', `Bearer ${walletA.token}`);
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/${walletA.id}`)
.set('treetracker-api-key', walletA.apiKey)
.set('content-type', 'application/json')
.set('Authorization', `Bearer ${walletA.token}`);

expect(res).property('statusCode').to.eq(200);
})

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', walletA.apiKey)
.set('content-type', 'application/json')
.set('Authorization', `Bearer ${walletA.token}`);

expect(res).property('statusCode').to.eq(404);
})
})
4 changes: 4 additions & 0 deletions __tests__/mock-data/wallet/walletA.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "walletA",
"password": "test1234"
}
4 changes: 4 additions & 0 deletions __tests__/mock-data/wallet/walletB.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "walletB",
"password": "test1234"
}
4 changes: 4 additions & 0 deletions __tests__/mock-data/wallet/walletC.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "walletC",
"password": "test1234"
}
42 changes: 42 additions & 0 deletions __tests__/mock-data/wallet/wallets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"name": "test0",
"password": "test1234"
},
{
"name": "test1",
"password": "test1234"
},
{
"name": "test2",
"password": "test1234"
},
{
"name": "test3",
"password": "test1234"
},
{
"name": "test4",
"password": "test1234"
},
{
"name": "test5",
"password": "test1234"
},
{
"name": "test6",
"password": "test1234"
},
{
"name": "test7",
"password": "test1234"
},
{
"name": "test8",
"password": "test1234"
},
{
"name": "test9",
"password": "test1234"
}
]
Loading