-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
234c2dc
commit 39db6b1
Showing
4 changed files
with
108 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* global describe, it, after, before, afterEach, beforeEach */ | ||
const expect = require('chai').expect; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const File = require('../file'); | ||
|
||
|
||
describe('File', () => { | ||
it('should create a file cache instance', () => { | ||
let file = new File({type: 'file'}, 'Test'); | ||
expect(file.type).to.equal('file'); | ||
expect(file.name).to.equal('Test'); | ||
expect(file).to.respondTo('_store'); | ||
expect(file).to.respondTo('_fetch'); | ||
expect(file).to.respondTo('_list'); | ||
expect(file).to.respondTo('_map'); | ||
expect(file).to.respondTo('_clear'); | ||
expect(file).to.respondTo('_remove'); | ||
}); | ||
|
||
it('should store and retrieve a cache value using callbacks', done => { | ||
let file = new File({type: 'file'}, 'Test'); | ||
file.store('TestType', 1, {a: 'Test'}, () => { | ||
file.fetch('TestType', 1, (err, result) => { | ||
expect(result).to.deep.equal({a: 'Test'}); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should store and retrieve a cache value using promises', async () => { | ||
let file = new File({type: 'file'}, 'Test'); | ||
await file.store('TestType', 1, {a: 'Test'}); | ||
let result = await file.fetch('TestType', 1); | ||
expect(result).to.deep.equal({a: 'Test'}); | ||
}); | ||
|
||
it('should support all standard operation for caching', async () => { | ||
let file = new File({type: 'file'}, 'Test'); | ||
await file.store('TestType', 1, {a: 'Test1'}); | ||
await file.store('TestType', 2, {a: 'Test2'}); | ||
|
||
let list = await file.list('TestType'); | ||
expect(list.length).to.equal(2); | ||
expect(list).to.include({a: 'Test1'}); | ||
expect(list).to.include({a: 'Test2'}); | ||
|
||
await file.remove('TestType', 1); | ||
let map = await file.map('TestType'); | ||
expect(map).to.have.any.key('2'); | ||
expect(map['2']).to.deep.equal({a: 'Test2'}); | ||
|
||
await file.clear('TestType'); | ||
let entry1 = await file.fetch('TestType', 1); | ||
expect(entry1).to.be.not.ok; | ||
let entry2 = await file.fetch('TestType', 2); | ||
expect(entry2).to.be.not.ok; | ||
expect(fs.existsSync(path.join(file.path, 'TestType'))).to.be.not.ok; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters