"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const defaultV1preset_1 = require("../constant/defaultV1preset");
const defaultV2preset_1 = require("../constant/defaultV2preset");
const presetConversion_1 = require("../preset/presetConversion");
describe("Convert preset from V1 to V2", () => {
    const convertedV2Preset = presetConversion_1.convertPresetToV2(defaultV2preset_1.defaultV2Preset, defaultV1preset_1.v1TestingPreset);
    const permissions = convertedV2Preset.permissions;
    const theme = convertedV2Preset.theme;
    const cases = [{
            name: "accept_waiting_requests",
            value: permissions.accept_waiting_requests,
            expected: defaultV1preset_1.v1TestingPreset.role.permissions.acceptWaitingRequests,
        }, {
            name: "can_allow_participant_audio",
            value: permissions.can_allow_participant_audio,
            expected: defaultV1preset_1.v1TestingPreset.role.permissions.disableParticipantAudio,
        }, {
            name: "can_allow_participant_screensharing",
            value: permissions.can_allow_participant_screensharing,
            expected: defaultV1preset_1.v1TestingPreset.role.permissions.disableParticipantScreensharing,
        }, {
            name: "can_allow_participant_video",
            value: permissions.can_allow_participant_video,
            expected: defaultV1preset_1.v1TestingPreset.role.permissions.disableParticipantVideo,
        }, {
            name: "kick_participant",
            value: permissions.kick_participant,
            expected: defaultV1preset_1.v1TestingPreset.role.permissions.kickParticipants,
        }, {
            name: "pin_participant",
            value: permissions.pin_participant,
            expected: defaultV1preset_1.v1TestingPreset.role.permissions.pinParticipant,
        }, {
            name: "can_record",
            value: permissions.can_record,
            expected: defaultV1preset_1.v1TestingPreset.role.permissions.allowRecording,
        }, {
            name: "show_participant_list",
            value: permissions.show_participant_list,
            expected: defaultV1preset_1.v1TestingPreset.role.permissions.acceptWaitingRequests,
        }, {
            name: "can_edit_display_name",
            value: permissions.can_edit_display_name,
            expected: defaultV1preset_1.v1TestingPreset.role.permissions.editDisplayName,
        }];
    it("check if the preset convertor function return values or not ", () => {
        const convertedV2Preset = jest.fn(() => presetConversion_1.convertPresetToV2(defaultV2preset_1.defaultV2Preset, defaultV1preset_1.v1TestingPreset));
        convertedV2Preset();
        expect(convertedV2Preset).toHaveReturned();
    });
    it('check if the v2 preset contains mandatory fields', () => {
        expect(convertedV2Preset).toMatchObject({
            theme: expect.any(Object),
            permissions: expect.any(Object),
            version: expect.any(String)
        });
    });
    it('check mandatory fields inside theme', () => {
        const expectedKeys = [
            'accept_waiting_requests',
            'request_produce',
            'can_allow_participant_audio',
            'can_allow_participant_screensharing',
            'can_allow_participant_video',
            'request_kick_participant',
            'kick_participant',
            'pin_participant',
            'can_record',
            'waiting_room_type',
            'plugins',
            'polls',
            'produce',
            'chat',
            'reactions',
            'show_participant_list',
            'can_present',
            'can_change_participant_role',
            'view_type',
        ];
        const newSet = new Set(Object.keys(permissions));
        expectedKeys.forEach((el) => {
            expect(newSet).toContain(el);
        });
    });
    it("check if view_type matches correct  ", () => {
        expect(typeof permissions.view_type).toBe('string');
        expect(permissions.view_type).not.toBeUndefined();
        expect(permissions.view_type).toEqual(expect.stringMatching(/GROUP_CALL|WEBINAR|AUDIO_ROOM/));
    });
    it("check if waiting_room_type matches correct  ", () => {
        expect(typeof permissions.waiting_room_type).toBe('string');
        expect(permissions.waiting_room_type).not.toBeUndefined();
        expect(permissions.waiting_room_type).toEqual(expect.stringMatching(/SKIP|ON_ACCEPT|SKIP_ON_PRIVILEGED_USER_ENTRY/));
    });
    it.each(cases)("check if %o.name matches correct", ({ value, expected }) => {
        expect(typeof value).toBe('boolean');
        expect(value).not.toBeUndefined();
        expect(value).toBe(expected);
    });
    it("plugin conversion check ", () => {
        expect(permissions.plugins).not.toBeUndefined();
        expect(permissions.plugins.can_close).toBe(defaultV1preset_1.v1TestingPreset.role.plugins.close);
        expect(permissions.plugins.can_start).toBe(defaultV1preset_1.v1TestingPreset.role.plugins.start);
        expect(permissions.plugins.can_edit_acl).toBe(defaultV1preset_1.v1TestingPreset.role.plugins.canEditAcl);
    });
    it("polls conversion check ", () => {
        expect(permissions.polls).not.toBeUndefined();
        expect(permissions.polls.can_create).toBe(defaultV1preset_1.v1TestingPreset.role.produce.polls);
        expect(typeof permissions.polls.can_view).toBe('boolean');
        expect(typeof permissions.polls.can_vote).toBe('boolean');
    });
    it("polls conversion check ", () => {
        expect(permissions.polls).not.toBeUndefined();
        expect(permissions.polls.can_create).toBe(defaultV1preset_1.v1TestingPreset.role.produce.polls);
        expect(typeof permissions.polls.can_view).toBe('boolean');
        expect(typeof permissions.polls.can_vote).toBe('boolean');
    });
    it("produce conversion check ", () => {
        expect(permissions.produce).not.toBeUndefined();
        expect(permissions.produce).toMatchObject({
            video: expect.any(Object),
            audio: expect.any(Boolean),
            screenshare: expect.any(Object)
        });
        expect(permissions.produce.video).toMatchObject({
            allow: expect.any(Boolean),
            quality: expect.stringMatching(/hd|vga|qvga|full/),
            frame_rate: expect.any(Number),
        });
        expect(permissions.produce.screenshare).toMatchObject({
            allow: expect.any(Boolean),
            quality: expect.stringMatching(/hd|vga|qvga|full/),
            frame_rate: expect.any(Number),
        });
        expect(permissions.produce.audio).toBe(defaultV1preset_1.v1TestingPreset.role.produce.audio);
        expect(permissions.produce.video.allow).toBe(defaultV1preset_1.v1TestingPreset.role.produce.video);
        expect(permissions.produce.screenshare.allow).toBe(defaultV1preset_1.v1TestingPreset.role.produce.screenshare);
    });
    it("chat conversion check ", () => {
        expect(permissions.chat).not.toBeUndefined();
        expect(permissions.chat).toMatchObject({
            public: expect.any(Object),
            private: expect.any(Object)
        });
        expect(permissions.chat.public).toMatchObject({
            can_send: expect.any(Boolean),
            text: expect.any(Boolean),
            files: expect.any(Boolean),
        });
        expect(permissions.chat.private).toMatchObject({
            can_send: expect.any(Boolean),
            can_receive: expect.any(Boolean),
            files: expect.any(Boolean),
            text: expect.any(Boolean),
        });
        expect(permissions.chat.public.text).toBe(defaultV1preset_1.v1TestingPreset.role.produce.chat.text),
            expect(permissions.chat.public.files).toBe(defaultV1preset_1.v1TestingPreset.role.produce.chat.files);
    });
    it("check alone_here conversion", () => {
        expect(theme.alone_here).not.toBeUndefined();
        expect(theme.alone_here).toMatchObject({
            is_enabled: expect.any(Boolean)
        });
        expect(theme.alone_here.is_enabled).toBe(defaultV1preset_1.v1TestingPreset.uiConfig.aloneHereElement);
    });
    it("check control_bar conversion", () => {
        expect(theme.control_bar).not.toBeUndefined();
        expect(theme.control_bar).toMatchObject({
            is_enabled: expect.any(Boolean),
            elements: expect.any(Object)
        });
        const expectedKeys = [
            'plugins',
            'screenshare',
            'invite',
            'participants',
            'chat',
            'reactions',
            'polls',
            'fullscreen',
            'layout'
        ];
        const newSet = new Set(Object.keys(theme.control_bar.elements));
        expectedKeys.forEach((el) => {
            expect(newSet).toContain(el);
        });
        expect(theme.control_bar.is_enabled).toBe(defaultV1preset_1.v1TestingPreset.uiConfig.controlBar);
        expect(theme.control_bar.elements.chat).toBe(defaultV1preset_1.v1TestingPreset.uiConfig.controlBarElements.chat);
        expect(theme.control_bar.elements.fullscreen).toBe(defaultV1preset_1.v1TestingPreset.uiConfig.controlBarElements.fullscreen);
        expect(theme.control_bar.elements.invite).toBe(defaultV1preset_1.v1TestingPreset.uiConfig.controlBarElements.share);
        expect(theme.control_bar.elements.participants).toBe(defaultV1preset_1.v1TestingPreset.uiConfig.controlBarElements.participants);
        expect(theme.control_bar.elements.plugins).toBe(defaultV1preset_1.v1TestingPreset.uiConfig.controlBarElements.plugins);
        expect(theme.control_bar.elements.polls).toBe(defaultV1preset_1.v1TestingPreset.uiConfig.controlBarElements.polls);
        expect(theme.control_bar.elements.screenshare).toBe(defaultV1preset_1.v1TestingPreset.uiConfig.controlBarElements.screenShare);
    });
    it('check header conversion', () => {
        expect(theme.header).not.toBeUndefined();
        expect(theme.header).toMatchObject({
            is_enabled: expect.any(Boolean),
            elements: expect.any(Object)
        });
        expect(theme.header.elements).toMatchObject({
            logo: expect.any(String),
            timer: expect.any(Boolean),
            title: expect.any(Boolean),
            participant_count: expect.any(Boolean),
            change_layout: expect.any(Boolean),
        });
        expect(theme.header.is_enabled).toBe(defaultV1preset_1.v1TestingPreset.uiConfig.header);
        expect(theme.header.elements.logo).toBe(defaultV1preset_1.v1TestingPreset.uiConfig.logo);
        expect(theme.header.elements.participant_count).toBe(defaultV1preset_1.v1TestingPreset.uiConfig.headerElements.participantCount);
        expect(theme.header.elements.timer).toBe(defaultV1preset_1.v1TestingPreset.uiConfig.headerElements.clock);
        expect(theme.header.elements.title).toBe(defaultV1preset_1.v1TestingPreset.uiConfig.headerElements.title);
    });
    it('check grid conversion', () => {
        expect(theme.grid).not.toBeUndefined();
        expect(theme.grid).toMatchObject({
            multi: expect.any(Object),
            single: expect.any(Object),
            defaultView: expect.any(String),
        });
        expect(theme.grid.multi.maxVideoCount).toBe(defaultV1preset_1.v1TestingPreset.uiConfig.grid.multi.maxVideoCount);
        expect(theme.grid.multi.videoFit).toBe(defaultV1preset_1.v1TestingPreset.uiConfig.grid.multi.videoFit);
        expect(theme.grid.single.maxVideoCount).toBe(defaultV1preset_1.v1TestingPreset.uiConfig.grid.single.maxVideoCount);
        expect(theme.grid.single.videoFit).toBe(defaultV1preset_1.v1TestingPreset.uiConfig.grid.single.videoFit);
    });
    console.log("✅ Theme ✅ ", theme, "✅ Permissions ✅ ", permissions);
});
//# sourceMappingURL=v1tov2.test.js.map