@labdigital/commercetools-mock 0.6.2 → 0.6.5

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.
@@ -9,7 +9,6 @@ import auth from 'basic-auth';
9
9
  import bodyParser from 'body-parser';
10
10
  import { randomBytes } from 'crypto';
11
11
  import { v4 } from 'uuid';
12
- import { getRepositoryContext } from 'repositories/helpers';
13
12
  import deepEqual from 'deep-equal';
14
13
 
15
14
  const parseExpandClause = clause => {
@@ -951,6 +950,67 @@ const copyHeaders = headers => {
951
950
  const DEFAULT_API_HOSTNAME = /^https:\/\/api\..*?\.commercetools.com:443$/;
952
951
  const DEFAULT_AUTH_HOSTNAME = /^https:\/\/auth\..*?\.commercetools.com:443$/;
953
952
 
953
+ const createCustomFields = (draft, projectKey, storage) => {
954
+ if (!draft) return undefined;
955
+ if (!draft.type) return undefined;
956
+ if (!draft.type.typeId) return undefined;
957
+ if (!draft.fields) return undefined;
958
+ const typeResource = storage.getByResourceIdentifier(projectKey, draft.type);
959
+
960
+ if (!typeResource) {
961
+ throw new Error(`No type '${draft.type.typeId}' with id=${draft.type.id} or key=${draft.type.key}`);
962
+ }
963
+
964
+ return {
965
+ type: {
966
+ typeId: draft.type.typeId,
967
+ id: typeResource.id
968
+ },
969
+ fields: draft.fields
970
+ };
971
+ };
972
+ const createPrice = draft => {
973
+ return {
974
+ id: v4(),
975
+ value: createTypedMoney(draft.value)
976
+ };
977
+ };
978
+ const createTypedMoney = value => {
979
+ return {
980
+ type: 'centPrecision',
981
+ fractionDigits: 2,
982
+ ...value
983
+ };
984
+ };
985
+ const resolveStoreReference = (ref, projectKey, storage) => {
986
+ if (!ref) return undefined;
987
+ const resource = storage.getByResourceIdentifier(projectKey, ref);
988
+
989
+ if (!resource) {
990
+ throw new Error('No such store');
991
+ }
992
+
993
+ const store = resource;
994
+ return {
995
+ typeId: 'store',
996
+ key: store.key
997
+ };
998
+ };
999
+ const getReferenceFromResourceIdentifier = (resourceIdentifier, projectKey, storage) => {
1000
+ const resource = storage.getByResourceIdentifier(projectKey, resourceIdentifier);
1001
+ if (!resource) throw new Error(`resource type ${resourceIdentifier.typeId} with id ${resourceIdentifier.id} and key ${resourceIdentifier.key} not found`);
1002
+ return {
1003
+ typeId: resourceIdentifier.typeId,
1004
+ id: resource == null ? void 0 : resource.id
1005
+ };
1006
+ };
1007
+ const getRepositoryContext = request => {
1008
+ return {
1009
+ projectKey: request.params.projectKey,
1010
+ storeKey: request.params.storeKey
1011
+ };
1012
+ };
1013
+
954
1014
  class AbstractService {
955
1015
  constructor(parent) {
956
1016
  this.createStatusCode = 201;
@@ -1167,61 +1227,6 @@ class AbstractResourceRepository extends AbstractRepository {
1167
1227
 
1168
1228
  }
1169
1229
 
1170
- const createCustomFields = (draft, projectKey, storage) => {
1171
- if (!draft) return undefined;
1172
- if (!draft.type) return undefined;
1173
- if (!draft.type.typeId) return undefined;
1174
- if (!draft.fields) return undefined;
1175
- const typeResource = storage.getByResourceIdentifier(projectKey, draft.type);
1176
-
1177
- if (!typeResource) {
1178
- throw new Error(`No type '${draft.type.typeId}' with id=${draft.type.id} or key=${draft.type.key}`);
1179
- }
1180
-
1181
- return {
1182
- type: {
1183
- typeId: draft.type.typeId,
1184
- id: typeResource.id
1185
- },
1186
- fields: draft.fields
1187
- };
1188
- };
1189
- const createPrice = draft => {
1190
- return {
1191
- id: v4(),
1192
- value: createTypedMoney(draft.value)
1193
- };
1194
- };
1195
- const createTypedMoney = value => {
1196
- return {
1197
- type: 'centPrecision',
1198
- fractionDigits: 2,
1199
- ...value
1200
- };
1201
- };
1202
- const resolveStoreReference = (ref, projectKey, storage) => {
1203
- if (!ref) return undefined;
1204
- const resource = storage.getByResourceIdentifier(projectKey, ref);
1205
-
1206
- if (!resource) {
1207
- throw new Error('No such store');
1208
- }
1209
-
1210
- const store = resource;
1211
- return {
1212
- typeId: 'store',
1213
- key: store.key
1214
- };
1215
- };
1216
- const getReferenceFromResourceIdentifier = (resourceIdentifier, projectKey, storage) => {
1217
- const resource = storage.getByResourceIdentifier(projectKey, resourceIdentifier);
1218
- if (!resource) throw new Error(`resource type ${resourceIdentifier.typeId} with id ${resourceIdentifier.id} and key ${resourceIdentifier.key} not found`);
1219
- return {
1220
- typeId: resourceIdentifier.typeId,
1221
- id: resource == null ? void 0 : resource.id
1222
- };
1223
- };
1224
-
1225
1230
  class CartDiscountRepository extends AbstractResourceRepository {
1226
1231
  constructor() {
1227
1232
  super(...arguments);
@@ -2911,13 +2916,15 @@ class ProductProjectionRepository extends AbstractResourceRepository {
2911
2916
  search(context, query) {
2912
2917
  var _query$filterQuery;
2913
2918
 
2919
+ const expand = query.expand ? query.expand : undefined;
2914
2920
  const filter = (_query$filterQuery = query['filter.query']) != null ? _query$filterQuery : query.filter;
2915
2921
  const wherePredicate = filter ? parseFilterExpression(filter) : undefined;
2916
2922
 
2917
2923
  const results = this._storage.query(context.projectKey, this.getTypeId(), {
2918
2924
  where: wherePredicate,
2919
2925
  offset: query.offset ? Number(query.offset) : undefined,
2920
- limit: query.limit ? Number(query.limit) : undefined
2926
+ limit: query.limit ? Number(query.limit) : undefined,
2927
+ expand
2921
2928
  }); //TODO: this is a partial implementation, but I don't really have the time to implement an actual search API right now
2922
2929
 
2923
2930