Some additional tests

This commit is contained in:
Chris Troutner
2021-04-08 15:00:47 -07:00
parent cd0aff2057
commit e82d0c0e45
4 changed files with 35 additions and 3 deletions
+5
View File
@@ -5,4 +5,9 @@ Below are a series of JSON RPC calls that can be manually entered at chat.fullst
- `{"jsonrpc":"2.0","id":"555","method":"users","params":{ "endpoint": "createUser", "email": "test555@test.com", "name": "testy tester", "password": "password"}}`
- `{"jsonrpc":"2.0","id":"556","method":"auth","params":{ "endpoint": "authUser", "login": "test555@test.com", "password": "password"}}`
- `{"jsonrpc":"2.0","id":"123","method":"users","params":{ "endpoint": "getAllUsers", "apiToken": "<JWT>"}}`
- `{"jsonrpc":"2.0","id":"123","method":"users","params":{ "endpoint": "updateUser", "apiToken": "<JWT>", "userId": "<_id>", "name": "test999"}}`
- `{"jsonrpc":"2.0","id":"123","method":"users","params":{ "endpoint": "getUser", "apiToken": "<JWT>", "userId": "<_id>"}}`
- `{"jsonrpc":"2.0","id":"123","method":"users","params":{ "endpoint": "deleteUser", "userId": "<_id>", "apiToken": "<JWT>"}}`
{"jsonrpc":"2.0","id":"555","method":"users","params":{ "endpoint": "createUser", "email": "test555@test.com", "name": "testy tester", "password": "password"}}
+11 -2
View File
@@ -22,10 +22,12 @@ class AuthRPC {
// a specific endpoint. This method routes incoming calls to one of those
// methods.
async authRouter (rpcData) {
let endpoint = 'unknown'
try {
// console.log('authRouter rpcData: ', rpcData)
const endpoint = rpcData.payload.params.endpoint
endpoint = rpcData.payload.params.endpoint
// Route the call based on the requested endpoint.
switch (endpoint) {
@@ -34,7 +36,14 @@ class AuthRPC {
}
} catch (err) {
console.error('Error in AuthRPC/authRouter()')
throw err
// throw err
return {
success: false,
status: 500,
message: err.message,
endpoint
}
}
}
+19
View File
@@ -76,6 +76,25 @@ describe('#AuthRPC', () => {
assert.equal(result, true)
})
it('should return 500 status on routing issue', async () => {
// Mock dependencies
sandbox.stub(uut, 'authUser').rejects(new Error('test error'))
// Generate the parsed data that the main router would pass to this
// endpoint.
const id = uid()
const authCall = jsonrpc.request(id, 'auth', { endpoint: 'authUser' })
const jsonStr = JSON.stringify(authCall, null, 2)
const rpcData = jsonrpc.parse(jsonStr)
const result = await uut.authRouter(rpcData)
assert.equal(result.success, false)
assert.equal(result.status, 500)
assert.equal(result.message, 'test error')
assert.equal(result.endpoint, 'authUser')
})
})
describe('#authUser', () => {
-1
View File
@@ -220,7 +220,6 @@ describe('#UserRPC', () => {
const result = await uut.userRouter(rpcData)
// console.log('result: ', result)
// assert.equal(result, true)
assert.equal(result.success, false)
assert.equal(result.status, 500)
assert.equal(result.message, 'test error')