prisma-mock 0.8.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/index.js +37 -34
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -38,7 +38,7 @@ function IsFieldDefault(f) {
38
38
  }
39
39
  const throwKnownError = (message, cause) => {
40
40
  const code = "P2025";
41
- const clientVersion = "1.2.3";
41
+ const clientVersion = client_1.Prisma.prismaVersion.client;
42
42
  // PrismaClientKnownRequestError prototype changed in version 4.7.0
43
43
  // from: constructor(message: string, code: string, clientVersion: string, meta?: any)
44
44
  // to: constructor(message: string, { code, clientVersion, meta, batchRequestIdx }: KnownErrorParams)
@@ -234,6 +234,7 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
234
234
  const c = d[field.name];
235
235
  if (field.kind === "object") {
236
236
  if (c.set) {
237
+ const { [field.name]: { set }, ...rest } = d;
237
238
  const otherModel = datamodel.models.find((model) => {
238
239
  return model.name === field.type;
239
240
  });
@@ -255,6 +256,7 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
255
256
  });
256
257
  });
257
258
  manyToManyData[field.relationName] = a;
259
+ d = rest;
258
260
  }
259
261
  if (c.connect) {
260
262
  const { [field.name]: { connect }, ...rest } = d;
@@ -464,36 +466,38 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
464
466
  const { [field.name]: _update, ...rest } = d;
465
467
  d = rest;
466
468
  }
467
- if (c.increment) {
468
- d = {
469
- ...d,
470
- [field.name]: item[field.name] + c.increment,
471
- };
472
- }
473
- if (c.decrement) {
474
- d = {
475
- ...d,
476
- [field.name]: item[field.name] - c.decrement,
477
- };
478
- }
479
- if (c.multiply) {
480
- d = {
481
- ...d,
482
- [field.name]: item[field.name] * c.multiply,
483
- };
484
- }
485
- if (c.divide) {
486
- const newValue = item[field.name] / c.divide;
487
- d = {
488
- ...d,
489
- [field.name]: field.type === "Int" ? Math.floor(newValue) : newValue,
490
- };
491
- }
492
- if (c.set) {
493
- d = {
494
- ...d,
495
- [field.name]: c.set,
496
- };
469
+ if (field.kind === "scalar") {
470
+ if (c.increment) {
471
+ d = {
472
+ ...d,
473
+ [field.name]: item[field.name] + c.increment,
474
+ };
475
+ }
476
+ if (c.decrement) {
477
+ d = {
478
+ ...d,
479
+ [field.name]: item[field.name] - c.decrement,
480
+ };
481
+ }
482
+ if (c.multiply) {
483
+ d = {
484
+ ...d,
485
+ [field.name]: item[field.name] * c.multiply,
486
+ };
487
+ }
488
+ if (c.divide) {
489
+ const newValue = item[field.name] / c.divide;
490
+ d = {
491
+ ...d,
492
+ [field.name]: field.type === "Int" ? Math.floor(newValue) : newValue,
493
+ };
494
+ }
495
+ if (c.set) {
496
+ d = {
497
+ ...d,
498
+ [field.name]: c.set,
499
+ };
500
+ }
497
501
  }
498
502
  }
499
503
  if ((isCreating || d[field.name] === null) &&
@@ -780,9 +784,7 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
780
784
  const findOrThrow = (args) => {
781
785
  const found = findOne(args);
782
786
  if (!found) {
783
- throw new client_1.Prisma.PrismaClientKnownRequestError(`No ${prop.slice(0, 1).toUpperCase()}${prop.slice(1)} found`, "P2025",
784
- // @ts-ignore
785
- "1.2.3");
787
+ throwKnownError(`No ${prop.slice(0, 1).toUpperCase()}${prop.slice(1)} found`);
786
788
  }
787
789
  return found;
788
790
  };
@@ -1000,6 +1002,7 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
1000
1002
  const newItems = data[prop].map((e) => {
1001
1003
  if (matchFnc(args.where)(e)) {
1002
1004
  let data = nestedUpdate(args, false, e);
1005
+ data; //?
1003
1006
  updatedItem = {
1004
1007
  ...e,
1005
1008
  ...data,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-mock",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "Mock prisma for unit testing database",
5
5
  "main": "lib/index.js",
6
6
  "repository": "https://github.com/demonsters/prisma-mock",