import {expect} from "chai"
import {ExportBuilder} from "../../src/builder/ExportBuilder"

describe("Test ExportBuilder class", () => {
    let exportBuilder;

    beforeEach(() => {
        exportBuilder = new ExportBuilder()
    })

    describe("Test ExportBuilder.export(from) method", () => {
        it("Test ExportBuilder.export(from) where from = null",() => {
            expect(exportBuilder.export.bind({},null)).to.throw(ReferenceError)
        })

        it("Test ExportBuilder.export(from) where from = undefined",() => {
            expect(exportBuilder.export.bind({},undefined)).to.throw(ReferenceError)
        })

        it("Test ExportBuilder.export(from) where from is defined",() => {
            expect(exportBuilder.hasExports()).to.be.false
            exportBuilder.export("any")
            expect(exportBuilder.hasExports()).to.be.true
        })
    })

    describe("Test ExportBuilder.exportSpecifier(local, alias) method", () => {
        it("Test ExportBuilder.exportSpecifier(local, alias) method where member=null", () => {
            exportBuilder.export("from");
            expect(exportBuilder.exportSpecifier.bind({},null, "alias")).to.throw(ReferenceError)
        })

        it("Test ExportBuilder.exportSpecifier(local, alias) method where member=undefined", () => {
            exportBuilder.export("from");
            expect(exportBuilder.exportSpecifier.bind({}, undefined, "alias")).to.throw(ReferenceError)
        })

        it("Test ExportBuilder.exportSpecifier(local, alias) method where member=\"\"", () => {
            exportBuilder.export("from");
            expect(exportBuilder.exportSpecifier.bind({}, "", "alias")).to.throw(ReferenceError)
        })

        it("Test ExportBuilder.exportSpecifier(local, alias) method where alias=null", () => {
            exportBuilder.export("from");
            expect(exportBuilder.exportSpecifier.bind({}, "local", null)).to.throw(ReferenceError)
        })

        it("Test ExportBuilder.exportSpecifier(local, alias) method where alias=undefined", () => {
            exportBuilder.export("from");
            expect(exportBuilder.exportSpecifier.bind("local", undefined)).to.throw(ReferenceError)
        })

        it("Test ExportBuilder.exportSpecifier(local, alias) method where alias=\"\"", () => {
            exportBuilder.export("from");
            expect(exportBuilder.exportSpecifier.bind("local", "")).to.throw(ReferenceError)
        })

        it("Test ExportBuilder.exportSpecifier(local, alias) method where local and alias are defined", () => {
            let built = exportBuilder.export("from").exportSpecifier("local", "alias").build()
            expect(built.alias).to.deep.equal({
                from: "from",
                local: "local"
            })
        })
    })

    describe("Test ExportBuilder methods in special cases", () => {
        it("Test ExportBuilder in the case when we trying to call constructor as a function", () => {
            expect(ExportBuilder).to.throw(TypeError)
        })
    })
})