import * as fs from "fs";
import * as os from "os";
import Repo from "../lib/repo";
import {ensureDirSync, removeSync} from "fs-extra";

describe('nest repo setup', () => {

    let projectDir: string;

    beforeEach(() => {
        projectDir = `${os.tmpdir()}/fun-project`;
        console.log(projectDir);
        removeSync(projectDir);
        ensureDirSync(projectDir);
    });

    test('Creates modelnest.json', () => {
        const repo = new Repo(projectDir);
        repo.init();
        const exists = fs.existsSync(`${projectDir}/modelnest.json`);
        expect(exists).toBeTruthy();
    });

    test('modelnest.json contains empty list of assets', () => {
        const repo = new Repo(projectDir);
        repo.init();
        const packages = JSON.parse(
            fs.readFileSync(`${projectDir}/modelnest.json`, 'utf8')
        );

        expect(packages.assets).toEqual({});
        expect(packages.nest).toBe('nest_models');
        const exists = fs.existsSync(`${projectDir}/nest_models`);
        expect(exists).toBeTruthy();
    });

});