UNPKG

@api-platform/client-generator

Version:

Generate apps built with Next, Nuxt, Quasar, React, React Native, Vue or Vuetify for any API documented using Hydra or OpenAPI

48 lines 2.07 kB
import { Api, Resource, Field } from "@api-platform/api-doc-parser"; import path from "path"; import { fileURLToPath } from "url"; import fs from "fs"; import tmp from "tmp"; import NextGenerator from "./NextGenerator.js"; var dirname = path.dirname(fileURLToPath(import.meta.url)); var generator = new NextGenerator({ hydraPrefix: "hydra:", templateDirectory: "".concat(dirname, "/../../templates") }); afterEach(function () { jest.resetAllMocks(); }); describe("generate", function () { test("Generate a Next app", function () { var tmpobj = tmp.dirSync({ unsafeCleanup: true }); var fields = [new Field("bar", { id: "http://schema.org/url", range: "http://www.w3.org/2001/XMLSchema#string", reference: null, required: true, description: "An URL" })]; var resource = new Resource("prefix/aBe_cd", "http://example.com/foos", { id: "abc", title: "abc", readableFields: fields, writableFields: fields }); var api = new Api("http://example.com", { entrypoint: "http://example.com:8080", title: "My API", resources: [resource] }); generator.generate(api, resource, tmpobj.name); ["/config/entrypoint.ts", "/components/abc/List.tsx", "/components/abc/Show.tsx", "/components/abc/Form.tsx", "/components/common/Layout.tsx", "/components/common/ReferenceLinks.tsx", "/components/common/Pagination.tsx", "/types/Abc.ts", "/types/collection.ts", "/types/item.ts", "/pages/abcs/[id]/index.tsx", "/pages/abcs/[id]/edit.tsx", "/pages/abcs/index.tsx", "/pages/abcs/create.tsx", "/pages/_app.tsx", "/utils/dataAccess.ts", "/utils/mercure.ts"].forEach(function (file) { return expect(fs.existsSync(tmpobj.name + file)).toBe(true); }); ["/components/abc/List.tsx", "/components/abc/Show.tsx", "/components/abc/Form.tsx", "/types/Abc.ts"].forEach(function (file) { expect(fs.existsSync(tmpobj.name + file)).toBe(true); expect(fs.readFileSync(tmpobj.name + file, "utf8")).toMatch(/bar/); }); tmpobj.removeCallback(); }); });