Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Generator: Add test for string filter #1490

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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