"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
require("../../../src/api/BookingAPI");
const RoomRate_1 = require("../../../src/models/Room/RoomRate");
const dayjs_1 = __importDefault(require("dayjs"));
const roomNightFactory = (obj) => {
    const partial = Object.assign({ date: (0, dayjs_1.default)(), cost: '0', tax: '0', fee: '0', discount: '0', available: '0', total: '0' }, obj);
    partial.total = [partial.cost, partial.tax, partial.fee].reduce((previousValue, currentValue) => {
        return parseFloat(previousValue) + parseFloat(currentValue) + '';
    });
    return partial;
};
const roomRateFactory = (name, code, nightRates, description, isMemberOnly) => {
    return RoomRate_1.RoomRate.fromData({
        name,
        code,
        nightRates,
        description,
        isMemberOnly,
    });
};
const rateIncludingFeesAndTaxes = roomRateFactory('Generic Rate', 'ABCD', {
    '20/06/2022': roomNightFactory({
        cost: '20',
    }),
});
const rateExcludingFeesAndTaxes = roomRateFactory('Generic Rate', 'ABCD', {
    '20/06/2022': roomNightFactory({
        cost: '20',
        fee: '20',
        tax: '20',
    }),
});
const rateExcludingTaxes = roomRateFactory('Generic Rate', 'ABCD', {
    '20/06/2022': roomNightFactory({
        cost: '20',
        fee: '20',
    }),
});
const rateExcludingFees = roomRateFactory('Generic Rate', 'ABCD', {
    '20/06/2022': roomNightFactory({
        cost: '20',
        tax: '20',
    }),
});
const rateWithTaxLast = roomRateFactory('Generic Rate', 'ABCD', {
    '20/06/2022': roomNightFactory({
        cost: '20',
    }),
    '21/06/2022': roomNightFactory({
        cost: '20',
        fee: '10',
    }),
});
const rateWithDiscountApplied = roomRateFactory('Rate with Tax', 'DISCOUNT', {
    '20/06/22': roomNightFactory({
        cost: '50',
        fee: '20',
        discount: '15',
    }),
    '21/06/22': roomNightFactory({
        cost: '90',
        fee: '20',
        discount: '15',
    }),
});
const memberOnlyRate = roomRateFactory('MOD Rate', 'MOD', {}, '', true);
describe('Room Rate logic', () => {
    describe('Room Rate Tax Inclusion', () => {
        it('Returns correct pricing type for each rate', () => {
            expect(rateIncludingFeesAndTaxes.getPriceType()).toBe(RoomRate_1.RoomRatePriceInclusion.IncludingFeesAndTaxes);
            expect(rateExcludingFeesAndTaxes.getPriceType()).toBe(RoomRate_1.RoomRatePriceInclusion.ExcludingFeesAndTaxes);
            expect(rateExcludingTaxes.getPriceType()).toBe(RoomRate_1.RoomRatePriceInclusion.ExcludingTaxes);
            expect(rateExcludingFees.getPriceType()).toBe(RoomRate_1.RoomRatePriceInclusion.ExcludingFees);
        });
        it('Accurately picks up the correct average pricing type if more than one night is selected', () => {
            expect(rateWithTaxLast.getPriceType()).toBe(RoomRate_1.RoomRatePriceInclusion.ExcludingTaxes);
        });
    });
    describe('Total Price Calculations', () => {
        it('Calculates total price, with tax & fee inclusions', () => {
            expect(rateWithTaxLast.getTotalPrice()).toBe(50);
        });
        it('Calculates total cost, without tax & fee inclusions', () => {
            expect(rateWithTaxLast.getTotalPrice(true)).toBe(40);
        });
    });
    describe('Average Price Calculations', () => {
        it('Calculates average price, with tax & fee inclusions', () => {
            expect(rateWithTaxLast.getAveragePrice()).toBe(25);
        });
        it('Calculates total cost, without tax & fee inclusions', () => {
            expect(rateWithTaxLast.getAveragePrice(true)).toBe(20);
        });
    });
    describe('Total Price With Discount', () => {
        it('Returns Total price Before Discount applied', () => {
            expect(rateWithDiscountApplied.getTotalPriceBeforeDiscount()).toBe(210);
        });
        it('Returns total cost before Discount is applied', () => {
            expect(rateWithDiscountApplied.getTotalPriceBeforeDiscount(true)).toBe(170);
        });
    });
    describe('Average Price With Discount', () => {
        it('Returns Total price Before Discount applied', () => {
            expect(rateWithDiscountApplied.getAveragePriceBeforeDiscount()).toBe(105);
        });
        it('Returns total cost before Discount is applied', () => {
            expect(rateWithDiscountApplied.getAveragePriceBeforeDiscount(true)).toBe(85);
        });
    });
    describe('Sort Value', () => {
        it('Sort Value to be the average price', () => {
            expect(rateWithDiscountApplied.getPriceSortValue()).toBe(90);
        });
    });
    describe('Total fees included', () => {
        it('Displays the full only fees ammount', () => {
            expect(rateExcludingFeesAndTaxes.getTotalFees()).toBe(20);
            expect(rateWithDiscountApplied.getTotalFees()).toBe(40);
        });
    });
    describe('Total Taxes included', () => {
        it('Displays the full only tax ammount', () => {
            expect(rateExcludingFeesAndTaxes.getTotalTaxes()).toBe(20);
            expect(rateWithDiscountApplied.getTotalTaxes()).toBe(0);
        });
    });
});
//# sourceMappingURL=RoomRate.test.js.map