"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const bson_1 = require("bson");
const chai_1 = require("chai");
const sinon = __importStar(require("sinon"));
const wallet_1 = require("../../../src/models/wallet");
const walletAddress_1 = require("../../../src/models/walletAddress");
const helpers_1 = require("../../helpers");
const unit_1 = require("../../helpers/unit");
describe('Wallet Model', function () {
    before(unit_1.unitBeforeHelper);
    after(unit_1.unitAfterHelper);
    describe('_apiTransform', () => {
        it('should return the transform object with wallet info', () => {
            const wallet = {
                name: 'Wallet1',
                singleAddress: true,
                pubKey: 'xpub661MyMwAqRbcFa63vSTa3vmRiVWbpLWhgUsyvjfMFP7ePR5osC1rtPUkgJrB94V1YEQathfWLm9U5zaZttYPDPWhASwJGUvYvPGtofqnTGN',
                path: "m/44'/0'/0'"
            };
            const result = wallet_1.WalletStorage._apiTransform(wallet, { object: false });
            const parseResult = JSON.parse(result.toString());
            (0, chai_1.expect)(parseResult).to.deep.equal({
                name: 'Wallet1',
                pubKey: 'xpub661MyMwAqRbcFa63vSTa3vmRiVWbpLWhgUsyvjfMFP7ePR5osC1rtPUkgJrB94V1YEQathfWLm9U5zaZttYPDPWhASwJGUvYvPGtofqnTGN'
            });
        });
        it('should return the raw transform object if options field exists and set to true', () => {
            const wallet = {
                name: 'Wallet1',
                singleAddress: true,
                pubKey: 'xpub661MyMwAqRbcFa63vSTa3vmRiVWbpLWhgUsyvjfMFP7ePR5osC1rtPUkgJrB94V1YEQathfWLm9U5zaZttYPDPWhASwJGUvYvPGtofqnTGN',
                path: "m/44'/0'/0'"
            };
            const result = wallet_1.WalletStorage._apiTransform(wallet, { object: true });
            (0, chai_1.expect)(result).to.deep.equal({
                name: 'Wallet1',
                pubKey: 'xpub661MyMwAqRbcFa63vSTa3vmRiVWbpLWhgUsyvjfMFP7ePR5osC1rtPUkgJrB94V1YEQathfWLm9U5zaZttYPDPWhASwJGUvYvPGtofqnTGN'
            });
        });
    });
    describe('updateCoins', () => {
        let sandbox;
        beforeEach(() => {
            sandbox = sinon.sandbox.create();
        });
        afterEach(() => {
            sandbox.restore();
        });
        it('should call wallet address model update coins', async () => {
            Object.assign(walletAddress_1.WalletAddressStorage.collection, (0, helpers_1.mockCollection)([]));
            const walletAddressModelSpy = sandbox.stub(walletAddress_1.WalletAddressStorage, 'updateCoins').returns({
                wallet: sandbox.stub().returnsThis(),
                addresses: sandbox.stub().returnsThis()
            });
            const wallet = {
                _id: new bson_1.ObjectID(),
                name: 'Wallet1',
                singleAddress: true,
                pubKey: 'xpub661MyMwAqRbcFa63vSTa3vmRiVWbpLWhgUsyvjfMFP7ePR5osC1rtPUkgJrB94V1YEQathfWLm9U5zaZttYPDPWhASwJGUvYvPGtofqnTGN',
                path: "m/44'/0'/0'",
                chain: 'BTC',
                network: 'regtest'
            };
            await wallet_1.WalletStorage.updateCoins(wallet);
            (0, chai_1.expect)(walletAddressModelSpy.calledOnce).to.be.true;
        });
    });
});
//# sourceMappingURL=wallet.test.js.map