Skip to content

Commit

Permalink
fix: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
techsavvyash committed May 12, 2024
1 parent 6f1d3dc commit 4cfd4f4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
"dependencies": {
"@nestjs/testing": "^10.3.3",
"@prisma/client": "5.12.1",
"@prisma/internals": "^5.13.0",
"@prisma/sdk": "^4.0.0",
"@types/es6-promise": "^3.3.0",
"prisma-schema-dsl": "^2.2.0",
"prisma-schema-dsl-types": "^1.1.2"
"prisma-schema-dsl-types": "^1.1.2",
"@prisma/internals": "^5.12.1",
"@prisma/sdk": "^4.0.0"
},
"devDependencies": {
"@types/jest": "^29.5.12",
Expand Down
38 changes: 25 additions & 13 deletions test/schema-generation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as fs from "fs";
import { getDMMF } from "@prisma/internals";
// const = pkg;

import { generatePrismaSchemaFile } from "../src";
import {
Expand Down Expand Up @@ -35,19 +37,29 @@ describe("tests for schema generation", () => {

it("should generate a schema.prisma with dummy_id for a schema with no id and only unique field being optional", async () => {
const fileContent = readJsonFile("./test/schemas/optional_unique.json");
await generatePrismaSchemaFile(fileContent).then((migrationModels) => {
expect(migrationModels).toBeDefined();
expect(fs.existsSync("./prisma/schema.prisma")).toBe(true);
const schemaPrismaContent = fs.readFileSync(
"./prisma/schema.prisma",
"utf8"
);
expect(schemaPrismaContent).toBeDefined();
const models = parsePrismaSchemaModels(schemaPrismaContent);
expect(models).toContain("User");
expect(models).toContain("Post");
expect(models).toContain("Comment");
});
await generatePrismaSchemaFile(fileContent).then(
async (migrationModels) => {
expect(migrationModels).toBeDefined();
expect(fs.existsSync("./prisma/schema.prisma")).toBe(true);
const schemaPrismaContent = fs.readFileSync(
"./prisma/schema.prisma",
"utf8"
);
expect(schemaPrismaContent).toBeDefined();
const models = parsePrismaSchemaModels(schemaPrismaContent);
expect(models).toContain("questions01");

const dmmf = await getDMMF({
datamodel: schemaPrismaContent,
});
expect(dmmf.datamodel.models.length).toBe(1);
expect(
dmmf.datamodel.models[0].fields.some(
(obj) => obj["name"] === "dummy_id"
)
).toBe(true);
}
);
});

it("should generate a schema.prisma for a basic file with different casing for types ", async () => {
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@
tmp "0.2.1"
ts-pattern "4.3.0"

"@prisma/internals@^5.13.0":
"@prisma/internals@^5.12.1":
version "5.13.0"
resolved "https://registry.yarnpkg.com/@prisma/internals/-/internals-5.13.0.tgz#15ba677eec8789d3d36b6eebfa424eeee6b6b028"
integrity sha512-OPMzS+IBPzCLT4s+IfGUbOhGFY51CFbokIFMZuoSeLKWE8UvDlitiXZ3OlVqDPUc0AlH++ysQHzDISHbZD+ZUg==
Expand Down Expand Up @@ -1440,7 +1440,7 @@ caniuse-lite@^1.0.30001587:

[email protected], chalk@^4.0.0, chalk@^4.1.0:
version "4.1.2"
resolved "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
dependencies:
ansi-styles "^4.1.0"
Expand Down

0 comments on commit 4cfd4f4

Please sign in to comment.