prisma-mock 0.1.4 → 0.1.6

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 +18 -6
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -83,13 +83,22 @@ const createPrismaMock = (data = {}, datamodel, client = (0, jest_mock_extended_
83
83
  for (const key of keys) {
84
84
  const dir = orderBy[key];
85
85
  if (typeof dir === "object") {
86
- return sortFunc(dir)(incl(a)[key], incl(b)[key]);
87
- }
88
- if (a[key] > b[key]) {
89
- return dir === "asc" ? 1 : -1;
86
+ const submodel = datamodel.models.find(model => {
87
+ return getCamelCase(model.name) === key;
88
+ });
89
+ const delegate = Delegate(key, submodel);
90
+ const res = delegate._sortFunc(dir)(incl(a)[key], incl(b)[key]);
91
+ if (res !== 0) {
92
+ return res;
93
+ }
90
94
  }
91
- else if (a[key] < b[key]) {
92
- return dir === "asc" ? -1 : 1;
95
+ else {
96
+ if (a[key] > b[key]) {
97
+ return dir === "asc" ? 1 : -1;
98
+ }
99
+ else if (a[key] < b[key]) {
100
+ return dir === "asc" ? -1 : 1;
101
+ }
93
102
  }
94
103
  }
95
104
  return 0;
@@ -617,6 +626,7 @@ const createPrismaMock = (data = {}, datamodel, client = (0, jest_mock_extended_
617
626
  const res = findMany(args);
618
627
  return res.length;
619
628
  },
629
+ _sortFunc: sortFunc,
620
630
  };
621
631
  };
622
632
  datamodel.models.forEach(model => {
@@ -629,6 +639,8 @@ const createPrismaMock = (data = {}, datamodel, client = (0, jest_mock_extended_
629
639
  data = removeMultiFieldIds(model, data);
630
640
  const objs = Delegate(c, model);
631
641
  Object.keys(objs).forEach(fncName => {
642
+ if (fncName.indexOf("_") === 0)
643
+ return;
632
644
  client[c][fncName].mockImplementation(async (...params) => {
633
645
  return objs[fncName](...params);
634
646
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-mock",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Mock prisma for unit testing database",
5
5
  "main": "lib/index.js",
6
6
  "repository": "https://github.com/demonsters/prisma-mock",