prisma-mock 0.4.0 → 0.4.1

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 +14 -9
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -96,9 +96,9 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
96
96
  };
97
97
  const getFieldRelationshipWhere = (item, field) => {
98
98
  if (field.relationToFields.length === 0) {
99
- field = getJoinField(field);
99
+ const otherfield = getJoinField(field);
100
100
  return {
101
- [field.relationFromFields[0]]: item[field.relationToFields[0]],
101
+ [otherfield.relationFromFields[0]]: item[otherfield.relationToFields[0]],
102
102
  };
103
103
  }
104
104
  return {
@@ -487,10 +487,12 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
487
487
  return getCamelCase(model.name) === childName;
488
488
  });
489
489
  const delegate = Delegate(getCamelCase(childName), submodel);
490
- const res = delegate.findMany({
490
+ const res = delegate._findMany({
491
491
  where: {
492
- ...childWhere,
493
- ...getFieldRelationshipWhere(item, info),
492
+ AND: [
493
+ childWhere,
494
+ getFieldRelationshipWhere(item, info)
495
+ ]
494
496
  },
495
497
  });
496
498
  if (filter.every) {
@@ -596,7 +598,7 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
596
598
  return true;
597
599
  };
598
600
  const matchAnd = (item, where) => {
599
- return where.filter((child) => matchItems(item, child)).length > 0;
601
+ return where.filter((child) => matchItems(item, child)).length === where.length;
600
602
  };
601
603
  const matchOr = (item, where) => {
602
604
  return where.some((child) => matchItems(item, child));
@@ -626,7 +628,9 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
626
628
  return found;
627
629
  };
628
630
  const findMany = (args) => {
629
- let res = data[prop].filter(matchFnc(args?.where)).map(includes(args));
631
+ let res = data[prop]
632
+ .filter(matchFnc(args?.where))
633
+ .map(includes(args));
630
634
  if (args?.distinct) {
631
635
  let values = {};
632
636
  res = res.filter((item) => {
@@ -778,13 +782,13 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
778
782
  // Add relation
779
783
  newItem = {
780
784
  ...newItem,
781
- [key]: delegate.findMany(subArgs),
785
+ [key]: delegate._findMany(subArgs),
782
786
  };
783
787
  }
784
788
  else {
785
789
  newItem = {
786
790
  ...newItem,
787
- [key]: delegate.findUnique(subArgs),
791
+ [key]: delegate._findMany(subArgs)?.[0] || null,
788
792
  };
789
793
  }
790
794
  });
@@ -881,6 +885,7 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
881
885
  return res.length;
882
886
  },
883
887
  _sortFunc: sortFunc,
888
+ _findMany: findMany
884
889
  };
885
890
  };
886
891
  datamodel.models.forEach((model) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-mock",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Mock prisma for unit testing database",
5
5
  "main": "lib/index.js",
6
6
  "repository": "https://github.com/demonsters/prisma-mock",