157 lines
12 KiB
JavaScript
157 lines
12 KiB
JavaScript
/**
|
|
* Tests MongoServerDao
|
|
*
|
|
* Copyright (C) 2010-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';
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
var MongoServerDao_1 = require("../../../src/server/db/MongoServerDao");
|
|
var chai_1 = require("chai");
|
|
chai_1.use(require('chai-as-promised'));
|
|
describe('MongoServerDao', function () {
|
|
describe('#saveQuote', function () {
|
|
describe("with no save data or push data", function () {
|
|
it("saves entire metabucket record individually", function (done) {
|
|
var metadata = {
|
|
foo: ['bar', 'baz'],
|
|
bar: [{ quux: 'quuux' }],
|
|
};
|
|
var quote = createStubQuote(metadata);
|
|
var sut = new MongoServerDao_1.MongoServerDao(createMockDb(
|
|
// update
|
|
function (_selector, data) {
|
|
chai_1.expect(data.$set['meta.foo'])
|
|
.to.deep.equal(metadata.foo);
|
|
chai_1.expect(data.$set['meta.bar'])
|
|
.to.deep.equal(metadata.bar);
|
|
chai_1.expect(data.$push).to.equal(undefined);
|
|
done();
|
|
}));
|
|
sut.init(function () {
|
|
return sut.saveQuote(quote, function () { }, function () { });
|
|
});
|
|
});
|
|
});
|
|
describe("with push data", function () {
|
|
it("adds push data to the collection", function (done) {
|
|
var push_data = {
|
|
foo: ['bar', 'baz'],
|
|
bar: [{ quux: 'quuux' }],
|
|
};
|
|
var quote = createStubQuote({});
|
|
var sut = new MongoServerDao_1.MongoServerDao(createMockDb(
|
|
// update
|
|
function (_selector, data) {
|
|
chai_1.expect(data.$push['foo'])
|
|
.to.deep.equal(push_data.foo);
|
|
chai_1.expect(data.$push['bar'])
|
|
.to.deep.equal(push_data.bar);
|
|
done();
|
|
}));
|
|
sut.init(function () {
|
|
return sut.saveQuote(quote, function () { }, function () { }, undefined, push_data);
|
|
});
|
|
});
|
|
it("skips push data when it is an empty object", function (done) {
|
|
var push_data = {};
|
|
var quote = createStubQuote({});
|
|
var sut = new MongoServerDao_1.MongoServerDao(createMockDb(
|
|
// update
|
|
function (_selector, data) {
|
|
chai_1.expect(data.$push).to.equal(undefined);
|
|
done();
|
|
}));
|
|
sut.init(function () {
|
|
return sut.saveQuote(quote, function () { }, function () { }, undefined, push_data);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
function createMockDb(on_update) {
|
|
var collection_quotes = {
|
|
update: on_update,
|
|
createIndex: function (_, __, c) { return c(); },
|
|
};
|
|
var collection_seq = {
|
|
find: function (_, __, c) {
|
|
c(null, {
|
|
toArray: function (c) { return c(null, { length: 5 }); },
|
|
});
|
|
},
|
|
};
|
|
var db = {
|
|
collection: function (id, c) {
|
|
var coll = (id === 'quotes')
|
|
? collection_quotes
|
|
: collection_seq;
|
|
c(null, coll);
|
|
},
|
|
};
|
|
var driver = {
|
|
open: function (c) { return c(null, db); },
|
|
on: function () { },
|
|
};
|
|
return driver;
|
|
}
|
|
function createStubQuote(metadata) {
|
|
var program = {
|
|
getId: function () { return '1'; },
|
|
ineligibleLockCount: 0,
|
|
apis: {},
|
|
internal: {},
|
|
meta: {
|
|
arefs: {},
|
|
fields: {},
|
|
groups: {},
|
|
qdata: {},
|
|
qtypes: {},
|
|
},
|
|
mapis: {},
|
|
initQuote: function () { },
|
|
};
|
|
var quote = {
|
|
getBucket: function () { return ({
|
|
getData: function () { },
|
|
}); },
|
|
getMetabucket: function () { return ({
|
|
getData: function () { return metadata; },
|
|
}); },
|
|
getId: function () { return 123; },
|
|
getProgramVersion: function () { return 'Foo'; },
|
|
getLastPremiumDate: function () { return 0; },
|
|
getRatedDate: function () { return 0; },
|
|
getExplicitLockReason: function () { return ""; },
|
|
getExplicitLockStep: function () { return 1; },
|
|
isImported: function () { return false; },
|
|
isBound: function () { return false; },
|
|
getTopVisitedStepId: function () { return 1; },
|
|
getTopSavedStepId: function () { return 1; },
|
|
setRatedDate: function () { return quote; },
|
|
setRateBucket: function () { return quote; },
|
|
setRatingData: function () { return quote; },
|
|
getRatingData: function () { return ({ _unavailable_all: '0' }); },
|
|
getProgram: function () { return program; },
|
|
setExplicitLock: function () { return quote; },
|
|
getProgramId: function () { return 'Foo'; },
|
|
getCurrentStepId: function () { return 0; },
|
|
setLastPremiumDate: function () { return quote; },
|
|
};
|
|
return quote;
|
|
}
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTW9uZ29TZXJ2ZXJEYW9UZXN0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiTW9uZ29TZXJ2ZXJEYW9UZXN0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBbUJHO0FBRUgsWUFBWSxDQUFDOztBQUViLHdFQUE4RTtBQUU5RSw2QkFBK0M7QUFRL0MsVUFBUSxDQUFFLE9BQU8sQ0FBRSxrQkFBa0IsQ0FBRSxDQUFFLENBQUM7QUFHMUMsUUFBUSxDQUFFLGdCQUFnQixFQUFFO0lBRXhCLFFBQVEsQ0FBRSxZQUFZLEVBQUU7UUFFcEIsUUFBUSxDQUFFLGdDQUFnQyxFQUFFO1lBRXhDLEVBQUUsQ0FBRSw2Q0FBNkMsRUFBRSxVQUFBLElBQUk7Z0JBRW5ELElBQU0sUUFBUSxHQUFHO29CQUNiLEdBQUcsRUFBRSxDQUFFLEtBQUssRUFBRSxLQUFLLENBQUU7b0JB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