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.master
parent
13716d240b
commit
20234bd906
|
@ -287,8 +287,8 @@ module.exports = Class( 'MongoServerDao' )
|
|||
quote, success_callback, failure_callback, save_data
|
||||
)
|
||||
{
|
||||
var dao = this;
|
||||
const meta = {};
|
||||
var dao = this;
|
||||
var meta = {};
|
||||
|
||||
// if we're not ready, then we can't save the quote!
|
||||
if ( this._ready === false )
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue