Skip to content

Commit

Permalink
Make everything standard compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
queicherius committed Oct 4, 2018
1 parent b4c3a7e commit ce4ee4b
Show file tree
Hide file tree
Showing 39 changed files with 265 additions and 265 deletions.
4 changes: 2 additions & 2 deletions src/cache/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = function (configuration) {
}

function _set (key, value, expiry) {
_storage[key] = {value, expiry: (new Date()).getTime() + expiry * 1000}
_storage[key] = { value, expiry: (new Date()).getTime() + expiry * 1000 }
persist()
}

Expand Down Expand Up @@ -90,5 +90,5 @@ module.exports = function (configuration) {
hydrate()
garbageCollection()

return {get, set, mget, mset, flush, _getStorage}
return { get, set, mget, mset, flush, _getStorage }
}
4 changes: 2 additions & 2 deletions src/cache/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = function (configuration) {
}

function _set (key, value, expiry) {
_storage[key] = {value, expiry: (new Date()).getTime() + expiry * 1000}
_storage[key] = { value, expiry: (new Date()).getTime() + expiry * 1000 }
}

function mget (keys) {
Expand Down Expand Up @@ -61,5 +61,5 @@ module.exports = function (configuration) {
setInterval(garbageCollection, configuration.gcTick)
garbageCollection()

return {get, set, mget, mset, flush, _getStorage}
return { get, set, mget, mset, flush, _getStorage }
}
2 changes: 1 addition & 1 deletion src/cache/null.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = function () {
return {get, set, mget, mset, flush}
return { get, set, mget, mset, flush }
}

function get () {
Expand Down
4 changes: 2 additions & 2 deletions src/cache/redis.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = function (configuration) {
configuration = Object.assign({
prefix: 'gw2api-',
prefix: 'gw2api-'
}, configuration)

if (!configuration.redis) {
Expand Down Expand Up @@ -89,5 +89,5 @@ module.exports = function (configuration) {
})
}

return {get, set, mget, mset, flush}
return { get, set, mget, mset, flush }
}
4 changes: 2 additions & 2 deletions src/endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ module.exports = class AbstractEndpoint {
/* istanbul ignore next */
const credentials = this.credentials ? 'include' : undefined

return this.fetch.single(url, {type, credentials})
return this.fetch.single(url, { type, credentials })
}

// Execute multiple requests in parallel
Expand All @@ -445,7 +445,7 @@ module.exports = class AbstractEndpoint {
/* istanbul ignore next */
const credentials = this.credentials ? 'include' : undefined

return this.fetch.many(urls, {type, credentials})
return this.fetch.many(urls, { type, credentials })
}

// Build the headers for localization and authentication
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function transformV1Format (json) {
const keys = Object.keys(events)

for (let i = 0; i !== keys.length; i++) {
transformed.push(Object.assign({id: keys[i]}, events[keys[i]]))
transformed.push(Object.assign({ id: keys[i] }, events[keys[i]]))
}

return transformed
Expand Down
20 changes: 10 additions & 10 deletions tests/cache/browser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const storage = require('../../src/cache/browser')
const idbMock = require('../mocks/idb.mock.js')

const cache = storage({storageEngine: idbMock, gcTick: 500, persistDebounce: 100})
const cache = storage({ storageEngine: idbMock, gcTick: 500, persistDebounce: 100 })
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms))

describe('cache > browser', function () {
Expand All @@ -15,7 +15,7 @@ describe('cache > browser', function () {
it('can hydrate the cache', async () => {
await idbMock.set('gw2api-temp-cache', {
foo: {
value: {bar: 1337},
value: { bar: 1337 },
expiry: new Date().getTime() + 5 * 60 * 1000
}
})
Expand All @@ -30,22 +30,22 @@ describe('cache > browser', function () {
// Make sure the data is cached
await wait(100)
let cachedFromPersistent = await tmpCache.get('foo')
expect(cachedFromPersistent).toEqual({bar: 1337})
expect(cachedFromPersistent).toEqual({ bar: 1337 })
})

it('can set and get a single value', async () => {
await cache.set('foo', {herp: 'derp'}, 2)
await cache.set('foo', { herp: 'derp' }, 2)

// Make sure the data is cached
let cachedFresh = await cache.get('foo')
expect(cachedFresh).toEqual({herp: 'derp'})
expect(cachedFresh).toEqual({ herp: 'derp' })

// Make sure that the debounce saving is respected
let storageBeforeSave = await idbMock.get('gw2api-cache')
expect(storageBeforeSave).toEqual(undefined)
await wait(150)
let storageAfterSave = await idbMock.get('gw2api-cache')
expect(storageAfterSave.foo.value).toEqual({herp: 'derp'})
expect(storageAfterSave.foo.value).toEqual({ herp: 'derp' })
expect(typeof storageAfterSave.foo.expiry).toEqual('number')

// Make sure the data expires
Expand All @@ -55,13 +55,13 @@ describe('cache > browser', function () {
})

it('can set and get multiple values', async () => {
await cache.set('abc', {foo: 'bar'}, 2)
await cache.mset([['foo', 'bar', 2], ['herp', {derp: 1}, 2]])
await cache.set('abc', { foo: 'bar' }, 2)
await cache.mset([['foo', 'bar', 2], ['herp', { derp: 1 }, 2]])

let cachedFresh = await cache.get('abc')
expect(cachedFresh).toEqual({foo: 'bar'})
expect(cachedFresh).toEqual({ foo: 'bar' })
let cachedFreshMany = await cache.mget(['foo', 'herp', 'abc'])
expect(cachedFreshMany).toEqual(['bar', {derp: 1}, {foo: 'bar'}])
expect(cachedFreshMany).toEqual(['bar', { derp: 1 }, { foo: 'bar' }])

await wait(3000)

Expand Down
14 changes: 7 additions & 7 deletions tests/cache/memory.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env jest */
const storage = require('../../src/cache/memory')
const cache = storage({gcTick: 500})
const cache = storage({ gcTick: 500 })
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms))

describe('cache > memory', function () {
Expand All @@ -22,11 +22,11 @@ describe('cache > memory', function () {
})

it('can set and get a single value', async () => {
await cache.set('foo', {herp: 'derp'}, 2)
await cache.set('foo', { herp: 'derp' }, 2)

// Make sure the data is cached
let cachedFresh = await cache.get('foo')
expect(cachedFresh).toEqual({herp: 'derp'})
expect(cachedFresh).toEqual({ herp: 'derp' })

// Make sure the data expires
await wait(3000)
Expand All @@ -35,13 +35,13 @@ describe('cache > memory', function () {
})

it('can set and get multiple values', async () => {
await cache.set('abc', {foo: 'bar'}, 2)
await cache.mset([['foo', 'bar', 2], ['herp', {derp: 1}, 2]])
await cache.set('abc', { foo: 'bar' }, 2)
await cache.mset([['foo', 'bar', 2], ['herp', { derp: 1 }, 2]])

let cachedFresh = await cache.get('abc')
expect(cachedFresh).toEqual({foo: 'bar'})
expect(cachedFresh).toEqual({ foo: 'bar' })
let cachedFreshMany = await cache.mget(['foo', 'herp', 'abc'])
expect(cachedFreshMany).toEqual(['bar', {derp: 1}, {foo: 'bar'}])
expect(cachedFreshMany).toEqual(['bar', { derp: 1 }, { foo: 'bar' }])

await wait(3000)

Expand Down
14 changes: 7 additions & 7 deletions tests/cache/redis.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env jest */
const storage = require('../../src/cache/redis')
const redis = require('redis')
const cache = storage({redis: redis.createClient()})
const cache = storage({ redis: redis.createClient() })
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms))

describe('cache > redis', function () {
Expand All @@ -27,11 +27,11 @@ describe('cache > redis', function () {
})

it('can set and get a single value', async () => {
await cache.set('foo', {herp: 'derp'}, 2)
await cache.set('foo', { herp: 'derp' }, 2)

// Make sure the data is cached
let cachedFresh = await cache.get('foo')
expect(cachedFresh).toEqual({herp: 'derp'})
expect(cachedFresh).toEqual({ herp: 'derp' })

// Make sure the data expires
await wait(3000)
Expand All @@ -40,13 +40,13 @@ describe('cache > redis', function () {
})

it('can set and get multiple values', async () => {
await cache.set('abc', {foo: 'bar'}, 2)
await cache.mset([['foo', 'bar', 2], ['herp', {derp: 1}, 2]])
await cache.set('abc', { foo: 'bar' }, 2)
await cache.mset([['foo', 'bar', 2], ['herp', { derp: 1 }, 2]])

let cachedFresh = await cache.get('abc')
expect(cachedFresh).toEqual({foo: 'bar'})
expect(cachedFresh).toEqual({ foo: 'bar' })
let cachedFreshMany = await cache.mget(['foo', 'herp', 'abc'])
expect(cachedFreshMany).toEqual(['bar', {derp: 1}, {foo: 'bar'}])
expect(cachedFreshMany).toEqual(['bar', { derp: 1 }, { foo: 'bar' }])

await wait(3000)

Expand Down
8 changes: 4 additions & 4 deletions tests/client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('client', () => {
})

it('can set a cache handler', () => {
let cacheHandler = {set: () => false, get: () => false}
let cacheHandler = { set: () => false, get: () => false }
let api = client.cacheStorage(cacheHandler)
expect(client.caches).toEqual([cacheHandler])
expect(api).toBeInstanceOf(Module)
Expand All @@ -49,7 +49,7 @@ describe('client', () => {
// Mock the build endpoint
let savedBuildId = null
let buildMock = {
live: () => ({get: () => Promise.resolve(123)}),
live: () => ({ get: () => Promise.resolve(123) }),
_cacheGetSingle: (key) => Promise.resolve(null),
_cacheSetSingle: (key, value) => {
savedBuildId = value
Expand All @@ -72,15 +72,15 @@ describe('client', () => {

// Cached and live is the same, expect the caches to still be there
buildMock._cacheGetSingle = (key) => Promise.resolve(456)
buildMock.live = () => ({get: () => Promise.resolve(456)})
buildMock.live = () => ({ get: () => Promise.resolve(456) })
await client.flushCacheIfGameUpdated()
expect(await client.caches[1].get('foo')).toEqual('bar')
expect(await client.caches[2].get('herp')).toEqual('derp')
expect(savedBuildId).toEqual(456)
await wait(50)

// Live is newer, expect the caches to be flushed
buildMock.live = () => ({get: () => Promise.resolve(789)})
buildMock.live = () => ({ get: () => Promise.resolve(789) })
await client.flushCacheIfGameUpdated()
expect(await client.caches[1].get('foo')).toEqual(null)
expect(await client.caches[2].get('herp')).toEqual(null)
Expand Down
Loading

0 comments on commit ce4ee4b

Please sign in to comment.