UNPKG

@code-o-mat/globals

Version:

Abstract Package to support CodeOMat series of apps.

111 lines (92 loc) 2.73 kB
import Bunyan from 'bunyan'; const log = Bunyan.createLogger({name: "CacheTest"}); import 'mocha'; import { expect } from 'chai'; const codePath = process.env.NODE_ENV === "PRODUCTION" ? 'lib' : 'src'; const TYPES = require(`../${codePath}/constants/types`); const { CACHE } = TYPES; const Cache = require(`../${codePath}/caches/cache`).default; describe(`test of basic Cache functions`, () => { var cache; var data = { "guests": "are", "like": "fish", "best": "if", "gone": "within", "three": "days" } var mergeData = { "three": "weeks", "prissy": "smith" } var mergedData = { "guests": "are", "like": "fish", "best": "if", "gone": "within", "three": "weeks", "prissy": "smith", } it(`should be able to create a cache with data`, () => { cache = new Cache(data); expect(cache.TYPE).to.equal(CACHE); } ); it(`should be able to retrieve the data object entirely from the cache`, () => { expect(cache.data()).to.deep.equal(data); } ); it(`should be able to retrieve data from the cache`, () => { expect(cache.get('guests')).to.equal('are'); expect(cache.get('like')).to.equal('fish'); expect(cache.get('best')).to.equal('if'); expect(cache.get('gone')).to.equal('within'); expect(cache.get('three')).to.equal('days'); } ); it(`should be able to retrieve a default value when something is not in the cache`, () => { expect(cache.get('flower', 'phone')).to.equal('phone'); } ); it(`should be able to set some data to the cache`, () => { cache.set('guests', 'annoying'); expect(cache.get('guests')).to.equal('annoying'); expect(cache.data()).to.not.deep.equal(data); } ); it(`should be able to set the entired data object over the original one`, () => { cache.data(data); expect(cache.data()).to.deep.equal(data) } ); it(`should be able to merge new data`, () => { cache = new Cache(data); const stillCache = cache.merge(mergeData); expect(stillCache.TYPE).to.equal(CACHE); expect(cache.data()).to.deep.equal(mergedData); } ); it(`should be able to create a new clone`, () => { cache = new Cache(data); const clone = cache.clone(); expect(clone.TYPE).to.equal(CACHE); clone.set('guests', 'bonnieandclyde'); expect(cache.get('guests')).to.equal('are'); expect(clone.get('guests')).to.equal('bonnieandclyde'); } ); } );