@@ -9,6 +9,12 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
99 var CacheItem ;
1010 beforeEach ( function unpackContext ( ) {
1111 CacheItem = helpers . givenCacheItem ( dataSourceFactory ) ;
12+ CacheItem . sortedKeys = function ( filter , options ) {
13+ return this . keys ( filter , options ) . then ( function ( keys ) {
14+ keys . sort ( ) ;
15+ return keys ;
16+ } ) ;
17+ } ;
1218 } ) ;
1319
1420 it ( 'returns all keys - Callback API' , function ( done ) {
@@ -41,10 +47,9 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
4147 return helpers . givenKeys ( AnotherModel , [ 'otherKey1' , 'otherKey2' ] ) ;
4248 } )
4349 . then ( function ( ) {
44- return CacheItem . keys ( ) ;
50+ return CacheItem . sortedKeys ( ) ;
4551 } )
4652 . then ( function ( keys ) {
47- keys . sort ( ) ;
4853 should ( keys ) . eql ( [ 'key1' , 'key2' ] ) ;
4954 } ) ;
5055 } ) ;
@@ -53,16 +58,48 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
5358 var expectedKeys = [ ] ;
5459 for ( var ix = 0 ; ix < 1000 ; ix ++ )
5560 expectedKeys . push ( 'key-' + ix ) ;
61+ expectedKeys . sort ( ) ;
5662
5763 return helpers . givenKeys ( CacheItem , expectedKeys )
5864 . then ( function ( ) {
59- return CacheItem . keys ( ) ;
65+ return CacheItem . sortedKeys ( ) ;
6066 } )
6167 . then ( function ( keys ) {
62- keys . sort ( ) ;
63- expectedKeys . sort ( ) ;
6468 should ( keys ) . eql ( expectedKeys ) ;
6569 } ) ;
6670 } ) ;
71+
72+ context ( 'with "filter.match"' , function ( ) {
73+ beforeEach ( function createTestData ( ) {
74+ return helpers . givenKeys ( CacheItem , [
75+ 'hallo' ,
76+ 'hello' ,
77+ 'hxllo' ,
78+ 'hllo' ,
79+ 'heeello' ,
80+ 'foo' ,
81+ 'bar' ,
82+ ] ) ;
83+ } ) ;
84+
85+ it ( 'supports "?" operator' , function ( ) {
86+ return CacheItem . sortedKeys ( { match : 'h?llo' } ) . then ( function ( keys ) {
87+ should ( keys ) . eql ( [ 'hallo' , 'hello' , 'hxllo' ] ) ;
88+ } ) ;
89+ } ) ;
90+
91+ it ( 'supports "*" operator' , function ( ) {
92+ return CacheItem . sortedKeys ( { match : 'h*llo' } ) . then ( function ( keys ) {
93+ should ( keys ) . eql ( [ 'hallo' , 'heeello' , 'hello' , 'hllo' , 'hxllo' ] ) ;
94+ } ) ;
95+ } ) ;
96+
97+ it ( 'handles no matches found' , function ( ) {
98+ return CacheItem . sortedKeys ( { match : 'not-found' } )
99+ . then ( function ( keys ) {
100+ should ( keys ) . eql ( [ ] ) ;
101+ } ) ;
102+ } ) ;
103+ } ) ;
67104 } ) ;
68105} ;
0 commit comments