"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 coll = getMockCollection();
            coll.find = function (selector) {
                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;
                return {
                    project: function () {
                        return {
                            toArray: function () {
                                return Promise.resolve();
                            },
                        };
                    },
                };
            };
            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 find_called = false;
            var stub_env = 'foo';
            var expected_error_msg = 'expected error!';
            var coll = getMockCollection();
            coll.find = function (_) {
                find_called = true;
                return {
                    project: function () {
                        return {
                            toArray: function () {
                                return Promise.reject(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; });
        });
    });
});
function getMockCollection() {
    return {
        findAndModify: function () { },
        findOne: function () { },
        update: function () { },
        createIndex: function () { },
        insert: function () { },
        find: function () { },
    };
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTW9uZ29EZWx0YURhb1Rlc3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJNb25nb0RlbHRhRGFvVGVzdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7R0FtQkc7O0FBRUgsc0VBQTBFO0FBRTFFLHdEQUFxRDtBQUNyRCw2QkFBNkM7QUFDN0MsVUFBUSxDQUFDLE9BQU8sQ0FBQyxrQkFBa0IsQ0FBQyxDQUFDLENBQUM7QUFFdEMsUUFBUSxDQUFDLHlCQUF5QixFQUFFO0lBQ2xDLFFBQVEsQ0FBQywwQkFBMEIsRUFBRTtRQUNuQyxFQUFFLENBQUMsNERBQTRELEVBQUU7WUFDL0QsSUFBTSxRQUFRLEdBQUcsS0FBSyxDQUFDO1lBQ3ZCLElBQUksV0FBVyxHQUFHLEtBQUssQ0FBQztZQUV4QixJQUFNLElBQUksR0FBRyxpQkFBaUIsRUFBRSxDQUFDO1lBRWpDLElBQUksQ0FBQyxJQUFJLEdBQUcsVUFBQyxRQUFhO2dCQUN4QixhQUFNLENBQUMsUUFBUSxDQUFDLHlCQUF5QixDQUFDLENBQUMsQ0FBQyxFQUFFLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQztvQkFDeEQsR0FBRyxFQUFFLENBQUMsQ0FBQyxDQUFDLENBQUMsRUFBRSxJQUFJLENBQUM7aUJBQ2pCLENBQUMsQ0FBQztnQkFDSCxhQUFNLENBQUMsUUFBUSx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