Skip to content

Commit

Permalink
Merge pull request #1490 from vivid-planet/crud-generator-test-string…
Browse files Browse the repository at this point in the history
…-filter

API Generator: Add test for string filter
  • Loading branch information
nsams authored Dec 7, 2023
2 parents 5b13904 + 3bb1133 commit 1398520
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion packages/api/cms-api/src/generator/generate-crud.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class TestEntityWithString extends BaseEntity<TestEntityWithString, "id">
@PrimaryKey({ type: "uuid" })
id: string = uuid();

@Property()
@Property({ columnType: "text" })
title: string;
}

Expand Down Expand Up @@ -55,6 +55,40 @@ describe("GenerateCrud", () => {
});
});

describe("string filter", () => {
it("should be a valid generated ts file", async () => {
LazyMetadataStorage.load();
const orm = await MikroORM.init({
type: "postgresql",
dbName: "test-db",
entities: [TestEntityWithString],
});

const out = await generateCrud({ targetDirectory: __dirname }, orm.em.getMetadata().get("TestEntityWithString"));
const lintedOut = await lintGeneratedFiles(out);

const file = lintedOut.find((file) => file.name === "dto/test-entity-with-string.filter.ts");
if (!file) throw new Error("File not found");

const source = parseSource(file.content);

const classes = source.getClasses();
expect(classes.length).toBe(1);

const cls = classes[0];
expect(cls.getName()).toBe("TestEntityWithStringFilter");
const structure = cls.getStructure();

expect(structure.properties?.length).toBe(3);
if (!structure.properties || !structure.properties[0]) throw new Error("property not found");
const filterProp = structure.properties[0];
expect(filterProp.name).toBe("title");
expect(filterProp.type).toBe("StringFilter");

orm.close();
});
});

describe("number filter", () => {
it("should be a valid generated ts file", async () => {
LazyMetadataStorage.load();
Expand Down

0 comments on commit 1398520

Please sign in to comment.