"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const BasketRow_1 = __importDefault(require("../../../src/models/BasketRow"));
const RoomRate_1 = require("../../../src/models/Room/RoomRate");
const BasketReducer_1 = require("../../../src/reducers/BasketReducer");
describe('Basket Management Suite', () => {
    describe('Adding basket rows', () => {
        it('Adds a basket row to the list of basket rows', () => {
            const initialState = [];
            const newRow = new BasketRow_1.default();
            const updatedState = (0, BasketReducer_1.BasketReducer)(initialState, { method: 'Add', row: newRow });
            expect(updatedState.length).toBe(1);
        });
        it('Sets the default values if none are provided', () => {
            const initialState = [];
            const newRow = new BasketRow_1.default();
            const updatedState = (0, BasketReducer_1.BasketReducer)(initialState, { method: 'Add', row: newRow });
            expect(updatedState[0].getAdults()).toBe(1);
            expect(updatedState[0].getPromoCodeStatus()).toBe('new');
        });
    });
    describe('Removing a row from the basket', () => {
        it('Decreases the row array', () => {
            const newRow = new BasketRow_1.default();
            const initialState = [newRow];
            const updatedState = (0, BasketReducer_1.BasketReducer)(initialState, { method: 'Remove', row: newRow });
            expect(updatedState.length).toBe(0);
        });
        it('Removes the correct basket row from the list', () => {
            const newRow = new BasketRow_1.default();
            const otherNewRow = new BasketRow_1.default();
            const initialState = [newRow, otherNewRow];
            const updatedState = (0, BasketReducer_1.BasketReducer)(initialState, { method: 'Remove', row: newRow });
            expect(updatedState.includes(newRow)).toBeFalsy();
            expect(updatedState.includes(otherNewRow)).toBeTruthy();
        });
        it('Returns original state of no row is passed', () => {
            const newRow = new BasketRow_1.default();
            const otherNewRow = new BasketRow_1.default();
            const initialState = [newRow, otherNewRow];
            const updatedState = (0, BasketReducer_1.BasketReducer)(initialState, { method: 'Remove' });
            expect(updatedState).toEqual(initialState);
        });
        it('Clear removes all rows in the basket', () => {
            const newRow = new BasketRow_1.default();
            const otherNewRow = new BasketRow_1.default();
            const initialState = [newRow, otherNewRow];
            const updatedState = (0, BasketReducer_1.BasketReducer)(initialState, { method: 'Clear' });
            expect(updatedState).toEqual([]);
        });
    });
    describe('Updating a row from the basket', () => {
        it('Updates the date on the new object', () => {
            const newRow = new BasketRow_1.default();
            const otherNewRow = new BasketRow_1.default();
            const initialState = [newRow, otherNewRow];
            newRow.setPromoCode('Updated');
            const updatedState = (0, BasketReducer_1.BasketReducer)(initialState, { method: 'Update', row: newRow });
            expect(updatedState[0].getPromoCode()).toBe('UPDATED');
        });
        it('Returns original state if no row is passed', () => {
            const newRow = new BasketRow_1.default();
            const initialState = [newRow];
            newRow.setPromoCode('Updated');
            const updatedState = (0, BasketReducer_1.BasketReducer)(initialState, { method: 'Update' });
            expect(updatedState[0].getPromoCode()).toBe('UPDATED');
        });
    });
    describe('Adding a Room to the basket', () => {
        it('Returns original state if no Rate or Room is passed', () => __awaiter(void 0, void 0, void 0, function* () {
            const newRow = new BasketRow_1.default();
            const rate = new RoomRate_1.RoomRate();
            rate.code = 'TEST';
            const initialState = [newRow];
            let updatedState = (0, BasketReducer_1.BasketReducer)(initialState, { method: 'AddRate' });
            expect(updatedState[0].getRate()).toBeFalsy();
            updatedState = (0, BasketReducer_1.BasketReducer)(initialState, { method: 'AddRate', row: newRow });
            expect(updatedState[0].getRate()).toBeFalsy();
        }));
        it('Adds a rate to basket row', () => __awaiter(void 0, void 0, void 0, function* () {
            var _a;
            const newRow = new BasketRow_1.default();
            const rate = new RoomRate_1.RoomRate();
            rate.code = 'TEST';
            const initialState = [newRow];
            const updatedState = (0, BasketReducer_1.BasketReducer)(initialState, { method: 'AddRate', row: newRow, rate });
            expect((_a = updatedState[0].getRate()) === null || _a === void 0 ? void 0 : _a.code).toBe('TEST');
        }));
    });
});
//# sourceMappingURL=BasketReducer.test.js.map