mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-21 16:52:00 -07:00
Increased unit test coverage of controllers
This commit is contained in:
@@ -229,8 +229,9 @@ describe('#validators', () => {
|
||||
|
||||
it('should throw an error if user can not be found', async () => {
|
||||
try {
|
||||
// Force an error
|
||||
sandbox.stub(uut.UserModel, 'findById').rejects(new Error('test error'))
|
||||
// Mock external dependencies.
|
||||
sandbox.stub(uut.jwt, 'verify').returns(true)
|
||||
sandbox.stub(uut.UserModel, 'findById').resolves(null)
|
||||
|
||||
// Generate the parsed data that the main router would pass to this
|
||||
// endpoint.
|
||||
@@ -243,15 +244,38 @@ describe('#validators', () => {
|
||||
const jsonStr = JSON.stringify(userCall, null, 2)
|
||||
const rpcData = jsonrpc.parse(jsonStr)
|
||||
|
||||
await uut.ensureTargetUserOrAdmin(rpcData)
|
||||
|
||||
assert.fail('Unexpected code path')
|
||||
} catch (err) {
|
||||
// console.log(err)
|
||||
assert.include(err.message, 'User not found!')
|
||||
}
|
||||
})
|
||||
|
||||
it('should throw an error if JWT is from a different user', async () => {
|
||||
try {
|
||||
// Mock external dependencies.
|
||||
sandbox.stub(uut.jwt, 'verify').returns(true)
|
||||
sandbox.stub(uut.UserModel, 'findById').resolves({ _id: 'badId' })
|
||||
|
||||
// Generate the parsed data that the main router would pass to this
|
||||
// endpoint.
|
||||
const id = uid()
|
||||
const userCall = jsonrpc.request(id, 'users', {
|
||||
endpoint: 'deleteUser',
|
||||
apiToken: 'fakeJWTToken',
|
||||
userId: 'abc123'
|
||||
})
|
||||
const jsonStr = JSON.stringify(userCall, null, 2)
|
||||
const rpcData = jsonrpc.parse(jsonStr)
|
||||
|
||||
await uut.ensureTargetUserOrAdmin(rpcData)
|
||||
|
||||
assert.fail('Unexpected code path')
|
||||
} catch (err) {
|
||||
// console.log(err)
|
||||
assert.include(err.message, 'test error')
|
||||
assert.include(err.message, 'User is neither admin nor target user.')
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
Unit tests for the json-rpc/about/index.js file.
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const sinon = require('sinon')
|
||||
const assert = require('chai').assert
|
||||
|
||||
// Local libraries
|
||||
const AboutRPC = require('../../../../src/controllers/json-rpc/about')
|
||||
|
||||
describe('#AboutRPC', () => {
|
||||
let uut
|
||||
let sandbox
|
||||
|
||||
beforeEach(() => {
|
||||
sandbox = sinon.createSandbox()
|
||||
|
||||
uut = new AboutRPC()
|
||||
})
|
||||
|
||||
afterEach(() => sandbox.restore())
|
||||
|
||||
describe('#aboutRouter', () => {
|
||||
it('should return information about the service', async () => {
|
||||
const result = await uut.aboutRouter()
|
||||
// console.log('result: ', result)
|
||||
|
||||
assert.property(result, 'success')
|
||||
assert.equal(result.success, true)
|
||||
assert.property(result, 'status')
|
||||
assert.equal(result.status, 200)
|
||||
assert.property(result, 'message')
|
||||
assert.property(result, 'endpoint')
|
||||
assert.equal(result.endpoint, 'about')
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user