The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import { defineContract, model } from "@alchemy.run/prisma/ORM"; |
| 2 | import { expect, it } from "@alchemy.run/test"; |
| 3 | import { |
| 4 | defineContract as nativeDefineContract, |
| 5 | model as nativeModel, |
| 6 | } from "@prisma/orm-postgres/contract-builder"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import { contract } from "./fixtures/client/contract.ts"; |
| 9 | |
| 10 | it.effect( |
| 11 | "uses native Prisma functions and runtime metadata unchanged", |
| 12 | () => |
| 13 | Effect.sync(() => { |
| 14 | expect(defineContract).toBe(nativeDefineContract); |
| 15 | expect(model).toBe(nativeModel); |
| 16 | expect(contract.domain.namespaces.public.models.Post.relations.author).toMatchObject({ |
| 17 | cardinality: "N:1", |
| 18 | nullable: false, |
| 19 | to: { namespace: "public", model: "User" }, |
| 20 | }); |
| 21 | expect(contract.domain.namespaces.public.models.User.relations.posts).toMatchObject({ |
| 22 | cardinality: "1:N", |
| 23 | to: { namespace: "public", model: "Post" }, |
| 24 | }); |
| 25 | expect(contract.storage.namespaces.public.entries.table.user.columns.id).toMatchObject({ |
| 26 | codecId: "pg/int4@1", |
| 27 | default: { kind: "function", expression: "autoincrement()" }, |
| 28 | }); |
| 29 | expect( |
| 30 | contract.storage.namespaces.public.entries.table.user.columns.email, |
| 31 | ).not.toHaveProperty("many"); |
| 32 | expect(contract.storage.namespaces.public.entries.table.user.uniques).toContainEqual( |
| 33 | expect.objectContaining({ columns: ["email"] }), |
| 34 | ); |
| 35 | }), |
| 36 | { tags: ["unit", "provider:prisma", "provider:prisma:orm", "local"] }, |
| 37 | ); |
| 38 | |
| 39 | it.effect( |
| 40 | "preserves namespaces, defaults, and scalar lists", |
| 41 | () => |
| 42 | Effect.sync(() => { |
| 43 | const authored = defineContract({ namespaces: ["auth"] }, ({ field, model }) => ({ |
| 44 | models: { |
| 45 | Account: model("Account", { |
| 46 | namespace: "auth", |
| 47 | fields: { |
| 48 | id: field.int().id().defaultSql("1"), |
| 49 | tags: field.text().many(), |
| 50 | name: field.text().optional(), |
| 51 | }, |
| 52 | }).sql({ table: "account" }), |
| 53 | }, |
| 54 | })); |
| 55 | expect(authored.domain.namespaces.auth.models.Account.storage).toMatchObject({ |
| 56 | namespaceId: "auth", |
| 57 | table: "account", |
| 58 | }); |
| 59 | expect(authored.storage.namespaces.auth.entries.table.account.columns.tags).toMatchObject({ |
| 60 | codecId: "pg/text@1", |
| 61 | many: true, |
| 62 | }); |
| 63 | expect(authored.storage.namespaces.auth.entries.table.account.columns.name).toMatchObject({ |
| 64 | nullable: true, |
| 65 | }); |
| 66 | }), |
| 67 | { tags: ["unit", "provider:prisma", "provider:prisma:orm", "local"] }, |
| 68 | ); |