Skip to content

Commit

Permalink
fix: update tests for catbox-memory lib upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronreynoza committed Sep 4, 2023
1 parent d3e35eb commit dd78015
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions test/unit/lib/cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ Test('Cache test', async (cacheTest) => {

await cacheTest.test('Cache should', async (initTest) => {
await initTest.test('call constructor of CatboxMemory', async (test) => {
sandbox.stub(Cache.CatboxMemory)
const catboxMemoryConstructorSpy = sandbox.spy(Cache, 'CatboxMemory')
sandbox.stub(Cache.CatboxMemory.Engine)
const catboxMemoryConstructorSpy = sandbox.spy(Cache.CatboxMemory, 'Engine')
await Cache.initCache()
test.ok(catboxMemoryConstructorSpy.calledOnce)
await Cache.destroyCache()
test.end()
})

await initTest.test('init+start and then stop CatboxMemory', async (test) => {
sandbox.spy(Cache.CatboxMemory.prototype, 'start')
sandbox.spy(Cache.CatboxMemory.prototype, 'stop')
sandbox.spy(Cache.CatboxMemory.Engine.prototype, 'start')
sandbox.spy(Cache.CatboxMemory.Engine.prototype, 'stop')
await Cache.initCache()
test.ok(Cache.CatboxMemory.prototype.start.calledOnce)
test.notOk(Cache.CatboxMemory.prototype.stop.calledOnce)
test.ok(Cache.CatboxMemory.Engine.prototype.start.calledOnce)
test.notOk(Cache.CatboxMemory.Engine.prototype.stop.calledOnce)
await Cache.destroyCache()
test.ok(Cache.CatboxMemory.prototype.start.calledOnce)
test.ok(Cache.CatboxMemory.prototype.stop.calledOnce)
test.ok(Cache.CatboxMemory.Engine.prototype.start.calledOnce)
test.ok(Cache.CatboxMemory.Engine.prototype.stop.calledOnce)
test.end()
})
initTest.end()
Expand Down Expand Up @@ -72,7 +72,7 @@ Test('Cache test', async (cacheTest) => {

await cacheClientTest.test('get() should call Catbox Memory get()', async (test) => {
Config.CACHE_CONFIG.CACHE_ENABLED = true
const getSpy = sandbox.spy(Cache.CatboxMemory.prototype, 'get')
const getSpy = sandbox.spy(Cache.CatboxMemory.Engine.prototype, 'get')

const cacheClient = Cache.registerCacheClient({
id: 'testCacheClient',
Expand All @@ -93,7 +93,7 @@ Test('Cache test', async (cacheTest) => {

await cacheClientTest.test('get() should NOT call Catbox Memory get() when cache is disabled', async (test) => {
Config.CACHE_CONFIG.CACHE_ENABLED = false
const getSpy = sandbox.spy(Cache.CatboxMemory.prototype, 'get')
const getSpy = sandbox.spy(Cache.CatboxMemory.Engine.prototype, 'get')

const cacheClient = Cache.registerCacheClient({
id: 'testCacheClient',
Expand All @@ -114,8 +114,8 @@ Test('Cache test', async (cacheTest) => {

await cacheClientTest.test('set() should call Catbox Memory set() and should work', async (test) => {
Config.CACHE_CONFIG.CACHE_ENABLED = true
const getSpy = sandbox.spy(Cache.CatboxMemory.prototype, 'get')
const setSpy = sandbox.spy(Cache.CatboxMemory.prototype, 'set')
const getSpy = sandbox.spy(Cache.CatboxMemory.Engine.prototype, 'get')
const setSpy = sandbox.spy(Cache.CatboxMemory.Engine.prototype, 'set')
const cacheClient = Cache.registerCacheClient({
id: 'testCacheClient',
preloadCache: async () => {}
Expand Down Expand Up @@ -145,9 +145,9 @@ Test('Cache test', async (cacheTest) => {

await cacheClientTest.test('drop() works', async (test) => {
Config.CACHE_CONFIG.CACHE_ENABLED = true
const getSpy = sandbox.spy(Cache.CatboxMemory.prototype, 'get')
const setSpy = sandbox.spy(Cache.CatboxMemory.prototype, 'set')
const dropSpy = sandbox.spy(Cache.CatboxMemory.prototype, 'drop')
const getSpy = sandbox.spy(Cache.CatboxMemory.Engine.prototype, 'get')
const setSpy = sandbox.spy(Cache.CatboxMemory.Engine.prototype, 'set')
const dropSpy = sandbox.spy(Cache.CatboxMemory.Engine.prototype, 'drop')
const cacheClient = Cache.registerCacheClient({
id: 'testCacheClient',
preloadCache: async () => {}
Expand Down

0 comments on commit dd78015

Please sign in to comment.