1 | mongojs = require 'mongojs'
|
2 | async = require 'async'
|
3 | Datastore = require '../src/datastore'
|
4 |
|
5 | describe 'Datastore cache stuff', ->
|
6 | beforeEach ->
|
7 | @sut = new Datastore
|
8 | database: mongojs('datastore-test')
|
9 | collection: 'jalapenos'
|
10 | cacheAttributes: ['id', 'jalapId']
|
11 |
|
12 | describe '->_generateCacheKey', ->
|
13 | context 'when the fields exist', ->
|
14 | beforeEach ->
|
15 | query =
|
16 | id: 'foo'
|
17 | jalapId: 'serano'
|
18 |
|
19 | @cacheKey = @sut._generateCacheKey {query}
|
20 |
|
21 | it 'should generate the proper key', ->
|
22 | expect(@cacheKey).to.equal '71e52b62d7f35e138983163d679121b5e5123f4d'
|
23 |
|
24 | context 'when a field is missing', ->
|
25 | beforeEach ->
|
26 | query =
|
27 | id: 'foo'
|
28 |
|
29 | @cacheKey = @sut._generateCacheKey {query}
|
30 |
|
31 | it 'should return null', ->
|
32 | expect(@cacheKey).to.be.undefined
|