{"_id":"@distartin/prisma-mock","name":"@distartin/prisma-mock","dist-tags":{"latest":"0.10.3"},"versions":{"0.10.3":{"name":"@distartin/prisma-mock","version":"0.10.3","description":"Mock prisma for unit testing database. forked from demonsters/prisma-mock","main":"lib/index.js","repository":{"type":"git","url":"git+https://github.com/demonsters/prisma-mock.git"},"license":"MIT","types":"lib/","devDependencies":{"@prisma/client":"5.13.0","@types/jest":"^27.0.2","cross-spawn":"^7.0.3","env-cmd":"^10.1.0","jest":"^27.3.1","prisma":"5.13.0","ts-jest":"^27.0.7","typescript":"^4.4.4","uuid":"^9.0.0"},"scripts":{"preversion":"jest && tsc","build":"tsc","test":"jest","watch":"tsc --watch","test:postgres":"env-cmd -e postgres jest --maxWorkers=1"},"peerDependencies":{"@prisma/client":"^3.5.0 || ^4.7.0 || ^5.0.0"},"_id":"@distartin/prisma-mock@0.10.3","gitHead":"b685e03b363d71328459cc0ed559d32f54f1cf5e","bugs":{"url":"https://github.com/demonsters/prisma-mock/issues"},"homepage":"https://github.com/demonsters/prisma-mock#readme","_nodeVersion":"22.6.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-WNGsWI48bC9KgM9HXfk+jAgKAy1X4mxFlMHp01WRpBkuD9oRwrup83RZuw4sNFQYoq2PdxmKs3gbLa8IBD33Kw==","shasum":"f1615184e6cac4176c01cf663ee29f7af8bcb587","tarball":"https://registry.npmjs.org/@distartin/prisma-mock/-/prisma-mock-0.10.3.tgz","fileCount":14,"unpackedSize":66356,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHXha0pTFCFnIr9R2yMxcqiRDBkmAGA4R8V6SOo/SfSgAiEAquJJ3yBiiPoymJiQX3MD+/GzGA20p4716niEOkioNRU="}]},"_npmUser":{"name":"distartin","email":"distartin@gmail.com"},"directories":{},"maintainers":[{"name":"distartin","email":"distartin@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/prisma-mock_0.10.3_1730111505630_0.029549818953849893"},"_hasShrinkwrap":false}},"time":{"created":"2024-10-28T10:31:45.523Z","0.10.3":"2024-10-28T10:31:45.841Z","modified":"2024-10-28T10:31:46.195Z"},"maintainers":[{"name":"distartin","email":"distartin@gmail.com"}],"description":"Mock prisma for unit testing database. forked from demonsters/prisma-mock","homepage":"https://github.com/demonsters/prisma-mock#readme","repository":{"type":"git","url":"git+https://github.com/demonsters/prisma-mock.git"},"bugs":{"url":"https://github.com/demonsters/prisma-mock/issues"},"license":"MIT","readme":"# Prisma Mock\n\nThis is a mock of the Prisma API intended for unit testing. All the data is stored in memory.\n\nThe library `jest-mock-extended` is used, which means that if functionality you need is not implemented yet, you can mock it yourself.\n\n# Usage\n\nSimple example how to create a prisma mock instance:\n\n```js\nimport createPrismaMock from \"prisma-mock\"\n\nlet client\n\nbeforeEach(() => {\n  client = createPrismaMock()\n})\n```\n\nAn example how to mock a global prisma instance, as the default export in a \"db\" directory (like blitzjs):\n\n```js\nimport createPrismaMock from \"prisma-mock\"\nimport { mockDeep, mockReset } from \"jest-mock-extended\"\n\njest.mock(\"db\", () => ({\n  __esModule: true,\n  ...jest.requireActual(\"db\"),\n  default: mockDeep(),\n}))\n\nimport db, { Prisma } from \"db\"\n\nbeforeEach(() => {\n  mockReset(db)\n  createPrismaMock({}, Prisma.dmmf.datamodel)\n})\n```\n\n# API\n\n```ts\ncreatePrismaMock(\n  data: PrismaMockData<P> = {},\n  datamodel?: Prisma.DMMF.Datamodel,\n  client = mockDeep<P>(),\n  options: {\n    caseInsensitive?: boolean\n  } = {}\n): Promise<P>\n```\n\n#### Arg: `data`\n\nYou can optionally start up a pre-filled db, by passing in an object containing keys for tables, and values as arrays of objects (though using `create` is preferred). Example:\n\n```js\ncreatePrismaMock({\n  user: [\n    {\n      id: 1,\n      name: \"John Doe\",\n      accountId: 1,\n    },\n  ],\n  account: [\n    {\n      id: 1,\n      name: \"Company\",\n    },\n  ],\n})\n```\n\n#### Arg: `datamodel`\n\nThe datamodel of the prisma client, value of `Prisma.dmmf.datamodel`.\n\n#### Arg: `client`\n\nA `jest-mock-extended` instance. If not provided, a new instance is created.\n\n#### Arg: `caseInsensitive`\n\nIf true, all string comparisons are case insensitive.\n\n\n\n# Supported features\n\nMost common cases are covered, but not everything. Here is a rough list of the supported features:\n\n## Model queries\n\n- findUnique,\n- findUniqueOrThrow,\n- findMany,\n- findFirst,\n- findFirstOrThrow,\n- create,\n- createMany\n- delete,\n- update,\n- deleteMany,\n- updateMany\n- upsert\n- count\n- TODO: aggregate\n- TODO: groupBy\n\n## Model query options\n\n- distinct\n- include\n- where\n- select\n- orderBy\n- select: \\_count\n\n## Nested queries\n\n- create\n- createMany\n- update\n- updateMany\n- delete\n- deleteMany\n- connect\n- disconnect\n- set\n- upsert\n- TODO: connectOrCreate\n\n## Filter conditions and operators\n\n- equals\n- gt\n- gte\n- lt\n- lte\n- not\n- in\n- notIn\n- contains\n- startWith\n- endsWith\n- AND\n- OR\n- NOT\n- mode\n- TODO: search\n\n## Relation filters\n\n- some\n- every\n- none\n- TODO: is\n\n## Scalar list methods\n\nTODO (set, push)\n\n## Scalar list filters\n\nTODO (has, hasEvery, hasSome, isEmpty, equals)\n\n## Atomic number operations\n\n- increment\n- decrement\n- multiply\n- divide\n- set\n\n## JSON filters\n\n- path\n- string_contains\n- string_starts_with \n- string_ends_with\n- array_contains\n- array_starts_with\n- array_ends_with\n\n## Attributes\n\n- @@id\n- @default\n- @unique\n- @@unique (TODO: no error if duplicate)\n- @relation\n- @updatedAt: Partially supported, value is set at creation (TODO: update value on update)\n\n## Attribute functions\n\n- autoincrement()\n- TODO: auto()\n- cuid()\n- uuid()\n- now()\n- TODO: dbgenerated()\n\n## Referential actions\n\n- onDelete (SetNull, Cascade)\n- TODO: onDelete: Restrict, NoAction, SetDefault\n- TODO: onUpdate\n\n## Prisma Client methods\n\n- $transaction\n- $transaction (interactive)\n- TODO: $transaction (isolation)\n\n# Contribution\n\n## Requirements\n\nCreate a `.env-cmdrc` file in the root of your project with the following content:\n\n```json\n{\n  \"postgres\": {\n    \"PROVIDER\": \"postgresql\",\n    \"DATABASE_URL\": \"postgresql://postgres:postgres@localhost:5432/postgres?schema=public\"\n  }\n}\n```\n\n## Writing Tests\nCreate your tests in the `__tests__` directory. You can use snapshot testing with either `expect(res).toMatchSnapshot()` or `expect(res).toMatchInlineSnapshot()`. This captures the result of your tests in a snapshot, which you can use to compare agains prisma-mock results.\n\nNote: If you choose to use snapshot testing, make shore to first run your tests against the real database to create a snapshot of the expected result.\n\n## Running Tests\nTo run tests against a postgres database, run the following command:\n\n```bash\nyarn run test:postgres\n```\n\nTo run tests against prisma-mock (in-memory database), run:\n\n```bash\nyarn test\n```\n","readmeFilename":"README.md"}