fix(decodeOpReturn): Adding test cases for 429 and 503 errors

This commit is contained in:
Chris Troutner
2021-02-27 13:28:53 -08:00
parent 179d924899
commit 1b8727da55
3 changed files with 62 additions and 18 deletions
+19 -1
View File
@@ -1366,6 +1366,23 @@ const txDetailsSLPNftChild = {
}
const mock429Error = new Error('Request failed with status code 429')
mock429Error.response = {
status: 429,
statusText: 'Too Many Requests',
data: {
error:
'Too many requests. Your limits are currently 100 requests per minute. Increase rate limits at https://fullstack.cash'
}
}
const mock503Error = new Error('Request failed with status code 503')
mock503Error.response = {
status: 503,
statusText: 'Service Unavailable',
data: {
error: 'Some error message'
}
}
module.exports = {
mockList,
@@ -1399,5 +1416,6 @@ module.exports = {
whitelist,
slpdbStatus,
mockValidateTxidArray,
mock429Error
mock429Error,
mock503Error
}
+31 -2
View File
@@ -495,8 +495,37 @@ describe('#SLP Utils', () => {
assert.fail('Unexpect result')
} catch (err) {
console.log('err: ', err)
// assert.include(err.message, 'amount string size not 8 bytes')
// console.log('err: ', err)
assert.property(err, 'message')
assert.property(err, 'response')
assert.equal(err.response.status, 429)
assert.equal(err.response.statusText, 'Too Many Requests')
assert.include(err.response.data.error, 'Too many requests')
}
})
// 503 means the service is down.
it('should throw error when axios returns 503 status', async () => {
try {
// Mock the call to the REST API
sandbox.stub(uut.Utils.axios, 'post').rejects(mockData.mock503Error)
const txid =
'a60a522cc11ad7011b74e57fbabbd99296e4b9346bcb175dcf84efb737030415'
await uut.Utils.decodeOpReturn(txid)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.fail('Unexpect result')
} catch (err) {
// console.log('err: ', err)
assert.property(err, 'message')
assert.property(err, 'response')
assert.equal(err.response.status, 503)
assert.equal(err.response.statusText, 'Service Unavailable')
assert.property(err.response, 'data')
}
})
})