"use strict";
/**
 * Delta data access test
 *
 *  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 Affero 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 Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
Object.defineProperty(exports, "__esModule", { value: true });
var MongoDeltaDao_1 = require("../../../src/system/db/MongoDeltaDao");
var DaoError_1 = require("../../../src/error/DaoError");
var chai_1 = require("chai");
chai_1.use(require('chai-as-promised'));
describe('system.db.MongoDeltaDao', function () {
    describe('#getUnprocessedDocuments', function () {
        it('finds unprocessed documents that do not have rates pending', function () {
            var stub_env = 'foo';
            var find_called = false;
            var delta_docs = [
                {
                    id: 123,
                    programId: '',
                    agentName: '',
                    agentEntityId: 0,
                    startDate: 0,
                    lastUpdate: 0,
                    data: {},
                    ratedata: {},
                    rdelta: {},
                },
            ];
            var coll = {
                findAndModify: function () { },
                findOne: function () { },
                update: function () { },
                createIndex: function () { },
                insert: function () { },
                find: function (selector, _fields, callback) {
                    chai_1.expect(selector['ratedata.__rate_pending']).to.deep.equal({
                        $in: [[0], null],
                    });
                    chai_1.expect(selector.deltaError).to.deep.equal({ $ne: true });
                    chai_1.expect(selector.published).to.be.false;
                    chai_1.expect(selector.env).to.equal(stub_env);
                    find_called = true;
                    callback(null, {
                        toArray: function (c) { return c(null, delta_docs); },
                    });
                },
            };
            var sut = new MongoDeltaDao_1.MongoDeltaDao(coll, stub_env);
            return sut
                .getUnprocessedDocuments()
                .then(function () { return chai_1.expect(find_called).to.be.true; });
        });
        it('rejects with error on query failure', function () {
            var stub_env = 'foo';
            var find_called = false;
            var expected_error_msg = 'expected error!';
            var coll = {
                findAndModify: function () { },
                findOne: function () { },
                update: function () { },
                createIndex: function () { },
                insert: function () { },
                find: function (_selector, _fields, callback) {
                    find_called = true;
                    callback(new Error(expected_error_msg), {});
                },
            };
            var sut = new MongoDeltaDao_1.MongoDeltaDao(coll, stub_env);
            return chai_1.expect(sut.getUnprocessedDocuments())
                .to.eventually.rejectedWith(DaoError_1.DaoError, expected_error_msg)
                .then(function () { return chai_1.expect(find_called).to.be.true; });
        });
    });
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTW9uZ29EZWx0YURhb1Rlc3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJNb25nb0RlbHRhRGFvVGVzdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7R0FtQkc7O0FBRUgsc0VBQTBFO0FBRzFFLHdEQUFxRDtBQUNyRCw2QkFBNkM7QUFFN0MsVUFBUSxDQUFDLE9BQU8sQ0FBQyxrQkFBa0IsQ0FBQyxDQUFDLENBQUM7QUFFdEMsUUFBUSxDQUFDLHlCQUF5QixFQUFFO0lBQ2xDLFFBQVEsQ0FBQywwQkFBMEIsRUFBRTtRQUNuQyxFQUFFLENBQUMsNERBQTRELEVBQUU7WUFDL0QsSUFBTSxRQUFRLEdBQUcsS0FBSyxDQUFDO1lBQ3ZCLElBQUksV0FBVyxHQUFHLEtBQUssQ0FBQztZQUV4QixJQUFNLFVBQVUsR0FBb0I7Z0JBQ2xDO29CQUNFLEVBQUUsRUFBYyxHQUFHO29CQUNuQixTQUFTLEVBQUUsRUFBRTtvQkFDYixTQUFTLEVBQUUsRUFBRTtvQkFDYixhQUFhLEVBQUUsQ0FBQztvQkFDaEIsU0FBUyxFQUFpQixDQUFDO29CQUMzQixVQUFVLEVBQWlCLENBQUM7b0JBQzVCLElBQUksRUFBRSxFQUFFO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