Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@rtspecialty.com>2019-02-12 09:18:48 -0500
committerMike Gerwitz <mike.gerwitz@rtspecialty.com>2019-02-12 09:18:48 -0500
commit20234bd90628d6fe6c1e02c383af304a23710316 (patch)
treef8d7a08d88b2fe371bbfb957b5754260776f0d16 /test
parent13716d240ba1ab522219c3a975900b2cf992af0c (diff)
downloadliza-20234bd90628d6fe6c1e02c383af304a23710316.tar.gz
liza-20234bd90628d6fe6c1e02c383af304a23710316.tar.bz2
liza-20234bd90628d6fe6c1e02c383af304a23710316.zip
db: Restore previous save-all-meta behavior
It looks like the metabucket is never initialized, so saving the quote is right now the only thing that sets default values. That should be fixed in the future. This also begins adding tests for the terrible MongoServerDao, that could use some refactoring. * src/server/db/MongoServerDao.js: Make `meta' mutable. I had forgotten to remove the code that mutates it (since our version of v8 right now does not blow up for const assignments), so this is all that's needed. * test/server/db/MongoServerDaoTest.js: New file to test this situation.
Diffstat (limited to 'test')
-rw-r--r--test/server/db/MongoServerDaoTest.js123
1 files changed, 123 insertions, 0 deletions
diff --git a/test/server/db/MongoServerDaoTest.js b/test/server/db/MongoServerDaoTest.js
new file mode 100644
index 0000000..fb637bd
--- /dev/null
+++ b/test/server/db/MongoServerDaoTest.js
@@ -0,0 +1,123 @@
+/**
+ * Tests MongoServerDao
+ *
+ * Copyright (C) 2019 R-T Specialty, LLC.
+ *
+ * This file is part of the Liza Data Collection Framework.
+ *
+ * liza is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+'use strict';
+
+const chai = require( 'chai' );
+const expect = chai.expect;
+const { MongoServerDao: Sut } = require( '../../../' ).server.db;
+
+
+describe( 'MongoServerDao', () =>
+{
+ describe( '#saveQuote', () =>
+ {
+ describe( "with no save data", () =>
+ {
+ it( "saves entire metabucket record individually", done =>
+ {
+ const metadata = {
+ foo: [ 'bar', 'baz' ],
+ bar: [ { quux: 'quuux' } ],
+ };
+
+ const quote = createStubQuote( metadata );
+
+ const sut = Sut( createMockDb(
+ // update
+ ( selector, data ) =>
+ {
+ expect( data.$set[ 'meta.foo' ] )
+ .to.deep.equal( metadata.foo );
+
+ expect( data.$set[ 'meta.bar' ] )
+ .to.deep.equal( metadata.bar );
+
+ done();
+ }
+ ) );
+
+ sut.init( () =>
+ sut.saveQuote( quote, () => {}, () => {} )
+ );
+ } );
+ } );
+ } );
+} );
+
+
+function createMockDb( on_update )
+{
+ const collection_quotes = {
+ update: on_update,
+ createIndex: ( _, __, c ) => c(),
+ };
+
+ const collection_seq = {
+ find( _, __, c )
+ {
+ c( null, {
+ toArray: c => c( null, { length: 5 } ),
+ } );
+ },
+ };
+
+ const db = {
+ collection( id, c )
+ {
+ const coll = ( id === 'quotes' )
+ ? collection_quotes
+ : collection_seq;
+
+ c( null, coll );
+ },
+ };
+
+ const driver = {
+ open: c => c( null, db ),
+ on: () => {},
+ };
+
+ return driver;
+}
+
+
+function createStubQuote( metadata )
+{
+ return {
+ getBucket: () => ( {
+ getData: () => {},
+ } ),
+
+ getMetabucket: () => ( {
+ getData: () => metadata,
+ } ),
+
+ getId: () => 1,
+ getProgramVersion: () => 0,
+ getLastPremiumDate: () => 0,
+ getRatedDate: () => 0,
+ getExplicitLockReason: () => "",
+ getExplicitLockStep: () => 0,
+ isImported: () => false,
+ isBound: () => false,
+ };
+}