-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(persister): Cache recordings (#31)
Cache recordings and bring `findRecordingEntry` into the base persister. * feat: Cleanup public facing persister API + bust cache * test: Add test cases
- Loading branch information
1 parent
43db361
commit a04d7a7
Showing
11 changed files
with
116 additions
and
78 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
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
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
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 |
---|---|---|
@@ -1,7 +1,72 @@ | ||
import Adapter from '../../src'; | ||
import Persister from '../../src'; | ||
|
||
describe('Unit | Adapter', function() { | ||
describe('Unit | Persister', function() { | ||
it('should exist', function() { | ||
expect(Adapter).to.be.a('function'); | ||
expect(Persister).to.be.a('function'); | ||
}); | ||
|
||
describe('Caching', function() { | ||
let callCounts, recording; | ||
|
||
beforeEach(function() { | ||
callCounts = { find: 0, save: 0, delete: 0 }; | ||
recording = {}; | ||
|
||
class CustomPersister extends Persister { | ||
findRecording() { | ||
callCounts.find++; | ||
|
||
return recording; | ||
} | ||
|
||
saveRecording() { | ||
callCounts.save++; | ||
} | ||
|
||
deleteRecording() { | ||
callCounts.delete++; | ||
} | ||
} | ||
|
||
this.persister = new CustomPersister({}); | ||
}); | ||
|
||
it('caches', async function() { | ||
await this.persister.find('test'); | ||
await this.persister.find('test'); | ||
await this.persister.find('test'); | ||
|
||
expect(callCounts.find).to.equal(1); | ||
}); | ||
|
||
it('does not cache falsy values', async function() { | ||
recording = null; | ||
|
||
await this.persister.find('test'); | ||
await this.persister.find('test'); | ||
await this.persister.find('test'); | ||
|
||
expect(callCounts.find).to.equal(3); | ||
}); | ||
|
||
it('busts the cache after a save', async function() { | ||
await this.persister.find('test'); | ||
await this.persister.save('test'); | ||
await this.persister.find('test'); | ||
await this.persister.find('test'); | ||
|
||
expect(callCounts.save).to.equal(1); | ||
expect(callCounts.find).to.equal(2); | ||
}); | ||
|
||
it('busts the cache after a delete', async function() { | ||
await this.persister.find('test'); | ||
await this.persister.delete('test'); | ||
await this.persister.find('test'); | ||
await this.persister.find('test'); | ||
|
||
expect(callCounts.delete).to.equal(1); | ||
expect(callCounts.find).to.equal(2); | ||
}); | ||
}); | ||
}); |