prisma-mock 0.8.2 → 0.9.0
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.
- package/README.md +2 -2
- package/lib/index.js +32 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -116,7 +116,7 @@ Most common cases are covered, but not everything. Here is a rough list of the s
|
|
|
116
116
|
- where
|
|
117
117
|
- select
|
|
118
118
|
- orderBy
|
|
119
|
-
-
|
|
119
|
+
- select: \_count
|
|
120
120
|
|
|
121
121
|
## Nested queries
|
|
122
122
|
|
|
@@ -129,8 +129,8 @@ Most common cases are covered, but not everything. Here is a rough list of the s
|
|
|
129
129
|
- connect
|
|
130
130
|
- disconnect
|
|
131
131
|
- set
|
|
132
|
+
- upsert
|
|
132
133
|
- TODO: connectOrCreate
|
|
133
|
-
- TODO: upsert
|
|
134
134
|
|
|
135
135
|
## Filter conditions and operators
|
|
136
136
|
|
package/lib/index.js
CHANGED
|
@@ -819,6 +819,10 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
|
|
|
819
819
|
return newItem;
|
|
820
820
|
});
|
|
821
821
|
}
|
|
822
|
+
if (args?.cursor !== undefined) {
|
|
823
|
+
const cursorVal = res.findIndex((r) => Object.keys(args?.cursor).every((key) => r[key] === args?.cursor[key]));
|
|
824
|
+
res = res.slice(cursorVal);
|
|
825
|
+
}
|
|
822
826
|
if (args?.skip !== undefined || args?.take !== undefined) {
|
|
823
827
|
const start = args?.skip !== undefined ? args?.skip : 0;
|
|
824
828
|
const end = args?.take !== undefined ? start + args.take : undefined;
|
|
@@ -952,6 +956,34 @@ const createPrismaMock = (data = {}, datamodel = client_1.Prisma.dmmf.datamodel,
|
|
|
952
956
|
const model = datamodel.models.find((model) => {
|
|
953
957
|
return getCamelCase(model.name) === prop;
|
|
954
958
|
});
|
|
959
|
+
if (key === "_count") {
|
|
960
|
+
const select = obj[key]?.select;
|
|
961
|
+
const subkeys = Object.keys(select);
|
|
962
|
+
let _count = {};
|
|
963
|
+
subkeys.forEach((subkey) => {
|
|
964
|
+
const schema = model.fields.find((field) => {
|
|
965
|
+
return field.name === subkey;
|
|
966
|
+
});
|
|
967
|
+
if (!schema?.relationName) {
|
|
968
|
+
return;
|
|
969
|
+
}
|
|
970
|
+
const submodel = datamodel.models.find((model) => {
|
|
971
|
+
return model.name === schema.type;
|
|
972
|
+
});
|
|
973
|
+
// Get delegate for relation
|
|
974
|
+
const delegate = Delegate(getCamelCase(schema.type), submodel);
|
|
975
|
+
const joinWhere = getFieldRelationshipWhere(item, schema, model);
|
|
976
|
+
_count = {
|
|
977
|
+
..._count,
|
|
978
|
+
[subkey]: delegate.count({ where: joinWhere }),
|
|
979
|
+
};
|
|
980
|
+
});
|
|
981
|
+
newItem = {
|
|
982
|
+
...newItem,
|
|
983
|
+
_count
|
|
984
|
+
};
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
955
987
|
const schema = model.fields.find((field) => {
|
|
956
988
|
return field.name === key;
|
|
957
989
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prisma-mock",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Mock prisma for unit testing database",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"repository": "https://github.com/demonsters/prisma-mock",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"test:postgres": "env-cmd -e postgres jest --maxWorkers=1"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@prisma/client": "^3.5.0 || ^4.7.0"
|
|
32
|
+
"@prisma/client": "^3.5.0 || ^4.7.0 || ^5.0.0"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {}
|
|
35
35
|
}
|