<commit_before>import { I18Next } from '../src/';
import { HandleRequest, BaseApp } from 'jovo-core';
import * as i18nData from './i18n/en-US.json';


describe('I18Next.constructor()', () => {
    test('without config', () => {
        const i18n = new I18Next();
        expect(i18n.config.filesDir).toEqual('./i18n');
    });

    test('with config', () => {
        const i18n = new I18Next({ filesDir: '../test' });
        expect(i18n.config.filesDir).toEqual('../test');
    });
});

describe('I18Next.loadFiles()', () => {
    test('with config.filesDir', async () => {
        const i18Next = new I18Next({
            filesDir: './test/i18n/'
        });

        const mockHR: HandleRequest = {
            app: new BaseApp(),
            host: {
                hasWriteFileAccess: true,
                headers: {},
                $request: {},
                getRequestObject() {

                },
                setResponse() {
                    return new Promise((res, rej) => {

                    });
                },
                fail() {

                }
            }
        };

        await i18Next.loadFiles(mockHR);

        // @ts-ignore
        expect(mockHR.app.config.platformSpecificResponses).toBe(true);
        expect(mockHR.app.$cms.I18Next.resources['en-US'].translation.WELCOME).toEqual('Welcome_Default');
        expect(mockHR.app.$cms.I18Next.resources['en-US'].AlexaSkill.translation.WELCOME).toEqual('Welcome_Alexa');
        expect(mockHR.app.$cms.I18Next.i18n).toBeDefined();
    });

    test('with config.resources', async () => {
        const i18Next = new I18Next({
            resources: {
                'en-US': i18nData
            }
        });

        const mockHR: HandleRequest = {
            app: new BaseApp(),
            host: {
                hasWriteFileAccess: true,
                headers: {},
                $request: {},
                getRequestObject() {

                },
                setResponse() {
                    return new Promise((res, rej) => {

                    });
                },
                fail() {

                }
            }
        };

        await i18Next.loadFiles(mockHR);

        // @ts-ignore
        expect(mockHR.app.config.platformSpecificResponses).toBe(true);
        expect(mockHR.app.$cms.I18Next.resources['en-US'].translation.WELCOME).toEqual('Welcome_Default');
        expect(mockHR.app.$cms.I18Next.resources['en-US'].AlexaSkill.translation.WELCOME).toEqual('Welcome_Alexa');
        expect(mockHR.app.$cms.I18Next.i18n).toBeDefined();
    });

    test('with config.resources without platform-specifics', async () => {
        const i18Next = new I18Next({
            resources: {
                'en-US': {
                    translation: i18nData.translation
                }
            }
        });

        const mockHR: HandleRequest = {
            app: new BaseApp(),
            host: {
                hasWriteFileAccess: true,
                headers: {},
                $request: {},
                getRequestObject() {

                },
                setResponse() {
                    return new Promise((res, rej) => {

                    });
                },
                fail() {

                }
            }
        };
<commit_msg>:white_check_mark: Update I18Next Tests<commit_after>import { I18Next } from '../src/';
import { HandleRequest, BaseApp } from 'jovo-core';
import * as i18nData from './i18n/en-US.json';


describe('I18Next.constructor()', () => {
    test('without config', () => {
        const i18n = new I18Next();
        expect(i18n.config.filesDir).toEqual('./i18n');
    });

    test('with config', () => {
        const i18n = new I18Next({ filesDir: '../test' });
        expect(i18n.config.filesDir).toEqual('../test');
    });
});

describe('I18Next.loadFiles()', () => {
    test('with config.filesDir', async () => {
        const i18Next = new I18Next({
            filesDir: './test/i18n/'
        });

        const mockHR: HandleRequest = {
            app: new BaseApp(),
            host: {
                hasWriteFileAccess: true,
                headers: {},
                $request: {},
                getRequestObject() {

                },
                setResponse() {
                    return new Promise((res, rej) => {

                    });
                },
                fail() {

                }
            }
        };

        mockHR.app.getAppTypes = () => {
            return ['AlexaSkill'];
        }

        await i18Next.loadFiles(mockHR);

        // @ts-ignore
        expect(mockHR.app.config.platformSpecificResponses).toBe(true);
        expect(mockHR.app.$cms.I18Next.resources['en-US'].translation.WELCOME).toEqual('Welcome_Default');
        expect(mockHR.app.$cms.I18Next.resources['en-US'].AlexaSkill.translation.WELCOME).toEqual('Welcome_Alexa');
        expect(mockHR.app.$cms.I18Next.i18n).toBeDefined();
    });

    test('with config.resources', async () => {
        const i18Next = new I18Next({
            resources: {
                'en-US': i18nData
            }
        });

        const mockHR: HandleRequest = {
            app: new BaseApp(),
            host: {
                hasWriteFileAccess: true,
                headers: {},
                $request: {},
                getRequestObject() {

                },
                setResponse() {
                    return new Promise((res, rej) => {

                    });
                },
                fail() {

                }
            }
        };

        mockHR.app.getAppTypes = () => {
            return ['AlexaSkill'];
        }

        await i18Next.loadFiles(mockHR);

        // @ts-ignore
        expect(mockHR.app.config.platformSpecificResponses).toBe(true);
        expect(mockHR.app.$cms.I18Next.resources['en-US'].translation.WELCOME).toEqual('Welcome_Default');
        expect(mockHR.app.$cms.I18Next.resources['en-US'].AlexaSkill.translation.WELCOME).toEqual('Welcome_Alexa');
        expect(mockHR.app.$cms.I18Next.i18n).toBeDefined();
    });

    test('with config.resources without platform-specifics', async () => {
        const i18Next = new I18Next({
            resources: {
                'en-US': {
                    translation: i18nData.translation
                }
            }
        });

        const mockHR: HandleRequest = {
            app: new BaseApp(),
            host: {
                hasWriteFileAccess: true,
                headers: {},
                $request: {},
                getRequestObject() {

                },
                setResponse() {
                    return new Promise((res, rej) => {

                    });
                },
                fail() {

                }
            }
        };

        mockHR.app.getAppTypes = () => {
            return ['AlexaSkill'];
        }
        
{'fraction_non_alphanumeric': 0.14444284272740376, 'fraction_numerical': 0.018163471241170535, 'mean_word_length': 1.3768413840356286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1559782', 'n_tokens_mistral': 2076, 'n_tokens_neox': 1883, 'n_words': 276}