import { Service } from "../partial-src/concept/service"
export function run() {
    describe("APIFactory test", () => {
        it("Monkey", (done) => {
            let factory = new Leaf.APIFactory({
                prefix: "/api/",
                bodyType: "json",
                errorMapper: (err: Error) => {
                    return err
                }
            })
            class APIService extends Service {
                public name: string = "APIService"
                register = factory.createAPIFunction<{
                    username: string
                    email: string
                    password: string
                }, boolean>({
                    method: "GET",
                    path: "user"
                })
                echo = factory.createAPIFunction<{
                    echo: string
                }, string>({
                    method: "GET",
                    path: "echo"
                })
                echoError = factory.createAPIFunction<{
                    message: string
                    detail: string
                }, null>({
                    method: "POST",
                    path: "echo/error"
                })
                test = factory.createAPIFunction<{
                    id: string
                    problem: string
                }, null>({
                    method: "POST",
                    path: "test/search/:id"
                })
            }
            let s = new APIService()
            s.test({ id: "debug", problem: "wrong" }, (err) => {
                console.error(err)
                done()
            })
            s.test({ id: "2", problem: "wrong" }, (err) => {
                console.error(err)
                done()
            })
            done()
        })
    })

}
