Skip to content
This repository has been archived by the owner on Feb 28, 2023. It is now read-only.

Commit

Permalink
fix(lint): fix all lint issues (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
lisathesecond committed Feb 3, 2021
1 parent 8b39242 commit 44d7227
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 109 deletions.
4 changes: 2 additions & 2 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function setupCache (config = {}) {

// Execute request against local cache
let res = await request(reqConfig, req)
let next = res.next
const next = res.next

// Response is not function, something was in cache, return it
if (!isFunction(next)) return next
Expand All @@ -39,7 +39,7 @@ function setupCache (config = {}) {

if (networkError) {
// Check if we should attempt reading stale cache data
let readOnError = isFunction(reqConfig.readOnError)
const readOnError = isFunction(reqConfig.readOnError)
? reqConfig.readOnError(networkError, req)
: reqConfig.readOnError

Expand Down
1 change: 1 addition & 0 deletions src/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class RedisStore {
this.hlenAsync = promisify(client.hlen).bind(client)
this.hgetallAsync = promisify(client.hgetall).bind(client)
}

async getItem (key) {
const item = (await this.hgetAsync(this.HASH_KEY, key)) || null

Expand Down
22 changes: 11 additions & 11 deletions test/spec/cache.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Cache store', () => {

const storedData = JSON.parse(store.store.test)

assert.equal(storedData.expires, expires)
assert.strictEqual(storedData.expires, expires)
assert.ok(storedData.data.data.youhou)

store.setItem = async () => {
Expand All @@ -52,7 +52,7 @@ describe('Cache store', () => {

cacheResult = await cache.write(config, req, res)

assert.equal(cacheResult, false)
assert.strictEqual(cacheResult, false)
})

it('Should clear cache if a store error occurs and clearOnError option is activated', async () => {
Expand All @@ -68,11 +68,11 @@ describe('Cache store', () => {

cacheResult = await cache.write(config, req, res)

assert.equal(cacheResult, false)
assert.strictEqual(cacheResult, false)

const length = await store.length()

assert.equal(length, 0)
assert.strictEqual(length, 0)
})

it('Should throw when unable to clear cache after a store error occurs', async () => {
Expand All @@ -91,22 +91,22 @@ describe('Cache store', () => {

cacheResult = await cache.write(config, req, res)

assert.equal(cacheResult, false)
assert.strictEqual(cacheResult, false)
})

it('Should read from cache', async () => {
try {
await cache.read(config, req)
} catch (err) {
assert.equal(err.reason, 'cache-miss')
assert.strictEqual(err.reason, 'cache-miss')
}

await cache.write(config, req, res)

try {
await cache.read(config, req)
} catch (err) {
assert.equal(err.reason, 'cache-stale')
assert.strictEqual(err.reason, 'cache-stale')
}

config.expires = Date.now() + (15 * 60 * 1000) // Add 15min to cache expiry date
Expand All @@ -124,23 +124,23 @@ describe('Cache store', () => {
try {
await cache.read(config, req)
} catch (err) {
assert.equal(err.reason, 'cache-miss')
assert.strictEqual(err.reason, 'cache-miss')
}
})

it('Should generate a cache key', () => {
const expected = function key () {}

assert.deepEqual(cache.key({ key: expected }), expected)
assert.deepStrictEqual(cache.key({ key: expected }), expected)

let cacheKey = cache.key({ key: 'my-key' })

assert.ok(isFunction(cacheKey))
assert.equal(cacheKey({ url: 'https://httpbin.org/' }), 'my-key/https://httpbin.org/')
assert.strictEqual(cacheKey({ url: 'https://httpbin.org/' }), 'my-key/https://httpbin.org/')

cacheKey = cache.key({})

assert.ok(isFunction(cacheKey))
assert.equal(cacheKey({ url: 'https://httpbin.org/' }), 'https://httpbin.org/')
assert.strictEqual(cacheKey({ url: 'https://httpbin.org/' }), 'https://httpbin.org/')
})
})
48 changes: 24 additions & 24 deletions test/spec/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ describe('Per request config', () => {
}

it('Should merge per-request keys in a new object', () => {
let requestConfig = { maxAge: 1000 }
const requestConfig = { maxAge: 1000 }
fakeRequest.cache = requestConfig

let mergedConfig = config.mergeRequestConfig(globalConfig, fakeRequest)
const mergedConfig = config.mergeRequestConfig(globalConfig, fakeRequest)

assert.notStrictEqual(globalConfig, mergedConfig)
assert.notStrictEqual(requestConfig, mergedConfig)
})

it('Should merge the permitted keys', () => {
let requestConfig = {
const requestConfig = {
maxAge: 10,
key: 'myKey',
exclude: {
Expand All @@ -51,28 +51,28 @@ describe('Per request config', () => {
}
fakeRequest.cache = requestConfig

let mergedConfig = config.mergeRequestConfig(globalConfig, fakeRequest)
const mergedConfig = config.mergeRequestConfig(globalConfig, fakeRequest)

assert.equal(mergedConfig.maxAge, requestConfig.maxAge)
assert.equal(mergedConfig.key, requestConfig.key)
assert.deepEqual(mergedConfig.exclude, {
assert.strictEqual(mergedConfig.maxAge, requestConfig.maxAge)
assert.strictEqual(mergedConfig.key, requestConfig.key)
assert.deepStrictEqual(mergedConfig.exclude, {
...globalConfig.exclude,
...requestConfig.exclude
})
assert.equal(mergedConfig.clearOnStale, requestConfig.clearOnStale)
assert.equal(mergedConfig.clearOnError, requestConfig.clearOnError)
assert.strictEqual(mergedConfig.clearOnStale, requestConfig.clearOnStale)
assert.strictEqual(mergedConfig.clearOnError, requestConfig.clearOnError)
assert.strictEqual(mergedConfig.debug, requestConfig.debug)

assert.notEqual(mergedConfig.maxAge, globalConfig.maxAge)
assert.notEqual(mergedConfig.key, globalConfig.key)
assert.notEqual(mergedConfig.exclude, globalConfig.exclude)
assert.notEqual(mergedConfig.clearOnStale, globalConfig.clearOnStale)
assert.notEqual(mergedConfig.clearOnError, globalConfig.clearOnError)
assert.notEqual(mergedConfig.debug, globalConfig.debug)
assert.notStrictEqual(mergedConfig.maxAge, globalConfig.maxAge)
assert.notStrictEqual(mergedConfig.key, globalConfig.key)
assert.notStrictEqual(mergedConfig.exclude, globalConfig.exclude)
assert.notStrictEqual(mergedConfig.clearOnStale, globalConfig.clearOnStale)
assert.notStrictEqual(mergedConfig.clearOnError, globalConfig.clearOnError)
assert.notStrictEqual(mergedConfig.debug, globalConfig.debug)
})

it('Should not merge the disallowed keys', () => {
let requestConfig = {
const requestConfig = {
limit: true,
store: 'abc',
adapter: 'whoops',
Expand All @@ -81,22 +81,22 @@ describe('Per request config', () => {
}
fakeRequest.cache = requestConfig

let mergedConfig = config.mergeRequestConfig(globalConfig, fakeRequest)
const mergedConfig = config.mergeRequestConfig(globalConfig, fakeRequest)

assert.equal(mergedConfig.limit, globalConfig.limit)
assert.equal(mergedConfig.store, globalConfig.store)
assert.equal(mergedConfig.adapter, globalConfig.adapter)
assert.equal(mergedConfig.uuid, globalConfig.key(fakeRequest))
assert.equal(mergedConfig.acceptStale, globalConfig.acceptStale)
assert.strictEqual(mergedConfig.limit, globalConfig.limit)
assert.strictEqual(mergedConfig.store, globalConfig.store)
assert.strictEqual(mergedConfig.adapter, globalConfig.adapter)
assert.strictEqual(mergedConfig.uuid, globalConfig.key(fakeRequest))
assert.strictEqual(mergedConfig.acceptStale, globalConfig.acceptStale)
})

it('Should transform the debug key when true', () => {
let requestConfig = {
const requestConfig = {
debug: true
}
fakeRequest.cache = requestConfig

let mergedConfig = config.mergeRequestConfig(globalConfig, fakeRequest)
const mergedConfig = config.mergeRequestConfig(globalConfig, fakeRequest)

assert.ok(typeof mergedConfig.debug === 'function')
})
Expand Down
6 changes: 3 additions & 3 deletions test/spec/exclude.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Cache exclusion', () => {
it('Should not exclude if not configured', () => {
const config = { debug }

assert.equal(exclude(config, { url }), false)
assert.strictEqual(exclude(config, { url }), false)
})

it('Should exclude requests with query parameters with config.exclude.query=true', () => {
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('Cache exclusion', () => {
}

assert.ok(exclude(config, { url }))
assert.equal(exclude(config, { url: 'https://some-rest.api/invoices' }), false)
assert.strictEqual(exclude(config, { url: 'https://some-rest.api/invoices' }), false)
})

it('Should exclude filtered requests', () => {
Expand All @@ -64,6 +64,6 @@ describe('Cache exclusion', () => {
}

assert.ok(exclude(config, { url, params: { shouldExclude: true } }))
assert.equal(exclude(config, { url }), false)
assert.strictEqual(exclude(config, { url }), false)
})
})

0 comments on commit 44d7227

Please sign in to comment.