unit test for getResource()

This commit is contained in:
Chris Troutner
2020-02-06 14:51:09 -08:00
parent 86951eccac
commit 8a558db690
2 changed files with 16 additions and 4 deletions
+4 -4
View File
@@ -40,6 +40,8 @@ class RateLimits {
this.rateLimiter = new RateLimiterRedis(rateLimitOptions)
}
// Used to disconnect from the Redis DB.
// Called by unit tests so that node.js thread doesn't live forever.
closeRedis() {
redisClient.disconnect()
}
@@ -228,9 +230,7 @@ class RateLimits {
/*
This is the new rate limit function that uses the rate-limiter-flexible npm
library. For the moment, it only distinguishes between anonymous usage
and registered user access. anon usage allows up to 3 RPM, whereas registered
users (with JWT tokens) have 100 RPM.
library.
*/
async newRateLimit(req, res, next) {
try {
@@ -353,7 +353,7 @@ class RateLimits {
// what kind of variations will be seen in production.
getResource(url) {
try {
console.log(`url: ${JSON.stringify(url, null, 2)}`)
// console.log(`url: ${JSON.stringify(url, null, 2)}`)
const splitUrl = url.split("/")
const resource = splitUrl[1]
+12
View File
@@ -240,6 +240,18 @@ describe("#route-ratelimits & jwt-auth", () => {
)
})
})
describe("#getResource", () => {
it("should decode a blockchain request", () => {
const url =
"/blockchain/getTxOut/62a3ea958a463a372bc0caf2c374a7f60be9c624be63a0db8db78f05809df6d8/0?include_mempool=true"
const result = rateLimits.getResource(url)
// console.log(`result: ${JSON.stringify(result, null, 2)}`)
assert.equal(result, "blockchain")
})
})
})
// Generates a Basic authorization header.