Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <gerwitzm@lovullo.com>2017-01-30 00:30:12 -0500
committerMike Gerwitz <gerwitzm@lovullo.com>2017-01-30 00:43:13 -0500
commit61a59db4e0e10a4bb3c6f2347192280c351e47b7 (patch)
tree7c0ef8ce017058ddfe71cde54d41f7640489a32b
parent0dcbd3220250ab889472d92433b24470d8a5e051 (diff)
downloadliza-61a59db4e0e10a4bb3c6f2347192280c351e47b7.tar.gz
liza-61a59db4e0e10a4bb3c6f2347192280c351e47b7.tar.bz2
liza-61a59db4e0e10a4bb3c6f2347192280c351e47b7.zip
system.client: working data.diffStore
* src/system/client.js (data.diffStore): Compose all stores. * test/system/clientTest.js: Update test case. DEV-2296
-rw-r--r--src/system/client.js32
-rw-r--r--test/system/clientTest.js37
2 files changed, 63 insertions, 6 deletions
diff --git a/src/system/client.js b/src/system/client.js
index 1cd8568..54e8917 100644
--- a/src/system/client.js
+++ b/src/system/client.js
@@ -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,
+ };
+ },
},
};
diff --git a/test/system/clientTest.js b/test/system/clientTest.js
index 0b18838..1b52185 100644
--- a/test/system/clientTest.js
+++ b/test/system/clientTest.js
@@ -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();
+
+ // 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;
- expect( Class.isA( Store, result ) )
+ // 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 ] );
+ } );
} );
} );