#!/usr/bin/env node

'use strict';

/* rpcRunner and rpcEmulator test suite */
const unitTestUtils = require('../unitTestUtils');
const rpcEmulatorModel = require('./f126_orwdxaIsactoi').rpcEmulatorModel;

describe('Invoke RPCs : ORWDXA ISACTOI, ', () => {
    let db;
    let rpcRunner;
    let rpcEmulator;
    beforeAll(() => {
        const res = unitTestUtils.beforeAllScript(rpcEmulatorModel);
        db = res.database;
        rpcRunner = res.rpcR;
        rpcEmulator = res.rpcE;
    });

    /**
     * ORWDXA ISACTOI
     * @description : Checks if ord item is active
     * @param {NUMBER} IEN of Order item
     */

    const RPC_UNDER_TEST = 'ORWDXA ISACTOI';

    const test = (arg) => {
        const resE = rpcEmulator.run(RPC_UNDER_TEST, [arg]);
        const resR = rpcRunner.run(RPC_UNDER_TEST, [arg]);
        expect(resR.result).toEqual(resE.result);
    };

    // ************************************* rpc Emulator Tests **************************************
    it('Valid numeric param returns string', () => {
        test(156); // { result: 'PROTHROMBIN has been inactivated and may not be ordered anymore.' }
    });

    it('Invalid parameters return empty string', () => {
        test('bar');
        test('');
        test(1);
    });

    it('no param and null should throw an Error over rpc Emulator', () => {
        expect(() => { rpcRunner.run(RPC_UNDER_TEST, []); }).toThrow();
        expect(() => { rpcEmulator.run(RPC_UNDER_TEST, []); }).toThrow();
        expect(() => { rpcRunner.run(RPC_UNDER_TEST, [null]); }).toThrow();
        expect(() => { rpcEmulator.run(RPC_UNDER_TEST, [null]); }).toThrow();
    });

    afterAll(() => {
        unitTestUtils.afterAllScript();
    });
});
