1
0
Fork 0

system.client: working data.diffStore

* src/system/client.js (data.diffStore): Compose all stores.
* test/system/clientTest.js: Update test case.

DEV-2296
master
Mike Gerwitz 2017-01-30 00:30:12 -05:00
parent 0dcbd32202
commit 61a59db4e0
2 changed files with 63 additions and 6 deletions

View File

@ -21,7 +21,7 @@
"use strict";
const MemoryStore = require( '../store' ).MemoryStore;
const store = require( '../store' );
/**
@ -34,6 +34,34 @@ const MemoryStore = require( '../store' ).MemoryStore;
*/
module.exports = {
data: {
diffStore: () => MemoryStore(),
/**
* Create a store suitable for comparing diffs
*
* This relies very much on assumptions about how the rest of the
* system works:
* - bstore expects the diff format to be provided directly to it;
* - cstore expects a full classification result set with which
* _it_ will compute the diff; and
* - the outer store proxies to cstore for 'c:*'.
*/
diffStore: () => {
const cstore = store.DiffStore();
const bstore = store.MemoryStore();
const proxy = store.MemoryStore.use(
store.PatternProxy( [
[ /^c:(.*)$/, cstore ],
[ /./, bstore ],
] )
)();
// TODO: breaking encapsulation should not be necessary in the
// future
return {
store: proxy,
cstore: cstore,
bstore: bstore,
};
},
},
};

View File

@ -27,20 +27,49 @@
const root = require( '../../' );
const sut = root.system.client;
const expect = require( 'chai' ).expect;
const Store = root.store.Store;
const Class = require( 'easejs' ).Class;
const { Store, DiffStore } = root.store;
describe( 'client', () =>
{
describe( 'data.diffStore', () =>
{
it( 'produces Store', () =>
it( 'produces proper Stores', () =>
{
const result = sut.data.diffStore();
const { store, cstore, bstore } = sut.data.diffStore();
expect( Class.isA( Store, result ) )
// we don't care what type of store these two are
expect( Class.isA( Store, store ) )
.to.be.true;
expect( Class.isA( Store, bstore ) )
.to.be.true;
// but it's essential that this is a DiffStore
expect( Class.isA( DiffStore, cstore ) )
.to.be.true;
} );
it( 'proxies c:* to cstore, others to bstore', () =>
{
const { store, cstore, bstore } = sut.data.diffStore();
const cname = 'c:foo'; // Master Shifu
const cval = 'panda';
const bname = 'henry';
const bval = 'liza';
return expect(
store.add( cname, cval )
.then( () => store.add( bname, bval ) )
.then( () => Promise.all( [
cstore.get( cname.replace( /^c:/, '' ) ),
bstore.get( bname )
] ) )
).to.eventually.deep.equal( [ cval, bval ] );
} );
} );
} );