-
Notifications
You must be signed in to change notification settings - Fork 54
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
WeiyuSun
wants to merge
17
commits into
Greenstand:master
Choose a base branch
from
WeiyuSun:#369_rebuild_integration_test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,853
−2,320
Open
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
71d9894
fix: rebuild __tests__ file structure, copy original wallet get test
WeiyuSun b96ca91
feat: refactor wallet get, add one function in testUnit, some mock data
WeiyuSun feb7809
fix: delete useless code
WeiyuSun e3dbad1
feat: test for transfer cancel, new test util file for sending req, e…
WeiyuSun d3f3e99
feat: pending transfer test, fix test util bug, more utils and mack date
WeiyuSun 7bd75aa
feat: more functions in testUtils.js
WeiyuSun 9a9881e
feat: pending-transfer-accepted.spec.js
WeiyuSun 10d6801
feat: pending-transfer-cancel.spec.js, pending-transfer-decline.spec.…
WeiyuSun 28097fe
feat: enhance utils, more files refactored
WeiyuSun f082f9d
fix: fix big in testUtils.js, enhance util functions
WeiyuSun 77623b4
feat: enhance testUtil, test for 'receive' trust relationship request
WeiyuSun ec91045
feat: trust relationship test
WeiyuSun 57cc3b8
feat: all refactor work finished. old version test deleted
WeiyuSun 5b141b2
Merge branch 'master' into #369_rebuild_integration_test
WeiyuSun 77aaaf1
fix: bug fix
WeiyuSun a755d25
fix: fix conflicts
WeiyuSun dbbb13c
fix: res code out of data, fixed
WeiyuSun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
This file was deleted.
Oops, something went wrong.
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,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(); | ||
}) | ||
|
||
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); | ||
}) | ||
}) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,4 @@ | ||
{ | ||
"name": "walletA", | ||
"password": "test1234" | ||
} |
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,4 @@ | ||
{ | ||
"name": "walletB", | ||
"password": "test1234" | ||
} |
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,4 @@ | ||
{ | ||
"name": "walletC", | ||
"password": "test1234" | ||
} |
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,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" | ||
} | ||
] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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