system.client: working data.diffStore
* src/system/client.js (data.diffStore): Compose all stores. * test/system/clientTest.js: Update test case. DEV-2296master
parent
0dcbd32202
commit
61a59db4e0
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const MemoryStore = require( '../store' ).MemoryStore;
|
const store = require( '../store' );
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,6 +34,34 @@ const MemoryStore = require( '../store' ).MemoryStore;
|
||||||
*/
|
*/
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: {
|
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,
|
||||||
|
};
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,20 +27,49 @@
|
||||||
const root = require( '../../' );
|
const root = require( '../../' );
|
||||||
const sut = root.system.client;
|
const sut = root.system.client;
|
||||||
const expect = require( 'chai' ).expect;
|
const expect = require( 'chai' ).expect;
|
||||||
const Store = root.store.Store;
|
|
||||||
const Class = require( 'easejs' ).Class;
|
const Class = require( 'easejs' ).Class;
|
||||||
|
|
||||||
|
const { Store, DiffStore } = root.store;
|
||||||
|
|
||||||
|
|
||||||
describe( 'client', () =>
|
describe( 'client', () =>
|
||||||
{
|
{
|
||||||
describe( 'data.diffStore', () =>
|
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;
|
.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 ] );
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
|
|
Loading…
Reference in New Issue