@labdigital/commercetools-mock 0.5.15 → 0.5.18

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.
@@ -17,6 +17,7 @@ var bodyParser = _interopDefault(require('body-parser'));
17
17
  var crypto = require('crypto');
18
18
  var uuid = require('uuid');
19
19
  var deepEqual = _interopDefault(require('deep-equal'));
20
+ var myCustomer = require('services/my-customer');
20
21
 
21
22
  const parseExpandClause = clause => {
22
23
  const result = {
@@ -985,9 +986,15 @@ class AbstractService {
985
986
  }
986
987
 
987
988
  get(request, response) {
989
+ const limit = this._parseParam(request.query.limit);
990
+
991
+ const offset = this._parseParam(request.query.offset);
992
+
988
993
  const result = this.repository.query(request.params.projectKey, {
989
994
  expand: this._parseParam(request.query.expand),
990
- where: this._parseParam(request.query.where)
995
+ where: this._parseParam(request.query.where),
996
+ limit: limit !== undefined ? Number(limit) : undefined,
997
+ offset: offset !== undefined ? Number(offset) : undefined
991
998
  });
992
999
  return response.status(200).send(result);
993
1000
  }
@@ -999,7 +1006,6 @@ class AbstractService {
999
1006
  return response.status(404).send();
1000
1007
  }
1001
1008
 
1002
- console.log(JSON.stringify(result, null, 4));
1003
1009
  return response.status(200).send(result);
1004
1010
  }
1005
1011
 
@@ -1128,7 +1134,9 @@ class AbstractResourceRepository extends AbstractRepository {
1128
1134
  query(projectKey, params = {}) {
1129
1135
  return this._storage.query(projectKey, this.getTypeId(), {
1130
1136
  expand: params.expand,
1131
- where: params.where
1137
+ where: params.where,
1138
+ offset: params.offset,
1139
+ limit: params.limit
1132
1140
  });
1133
1141
  }
1134
1142
 
@@ -1806,7 +1814,7 @@ class CustomerRepository extends AbstractResourceRepository {
1806
1814
  create(projectKey, draft) {
1807
1815
  const resource = { ...getBaseResourceProperties(),
1808
1816
  email: draft.email,
1809
- password: draft.password,
1817
+ password: Buffer.from(draft.password).toString('base64'),
1810
1818
  isEmailVerified: draft.isEmailVerified || false,
1811
1819
  addresses: []
1812
1820
  };
@@ -1814,6 +1822,17 @@ class CustomerRepository extends AbstractResourceRepository {
1814
1822
  return resource;
1815
1823
  }
1816
1824
 
1825
+ getMe(projectKey) {
1826
+ const results = this._storage.query(projectKey, this.getTypeId(), {}); // grab the first customer you can find
1827
+
1828
+
1829
+ if (results.count > 0) {
1830
+ return results.results[0];
1831
+ }
1832
+
1833
+ return;
1834
+ }
1835
+
1817
1836
  }
1818
1837
 
1819
1838
  class CustomerService extends AbstractService {
@@ -1989,7 +2008,6 @@ class DiscountCodeRepository extends AbstractResourceRepository {
1989
2008
  }
1990
2009
 
1991
2010
  create(projectKey, draft) {
1992
- console.log(draft);
1993
2011
  const resource = { ...getBaseResourceProperties(),
1994
2012
  applicationVersion: 1,
1995
2013
  cartDiscounts: draft.cartDiscounts.map(obj => ({
@@ -2661,10 +2679,15 @@ class ProductProjectionRepository extends AbstractResourceRepository {
2661
2679
  }
2662
2680
 
2663
2681
  search(projectKey, query) {
2664
- const wherePredicate = parseFilterExpression(query.filter);
2682
+ var _query$filterQuery;
2683
+
2684
+ const filter = (_query$filterQuery = query['filter.query']) != null ? _query$filterQuery : query.filter;
2685
+ const wherePredicate = filter ? parseFilterExpression(filter) : undefined;
2665
2686
 
2666
2687
  const results = this._storage.query(projectKey, this.getTypeId(), {
2667
- where: wherePredicate
2688
+ where: wherePredicate,
2689
+ offset: query.offset ? Number(query.offset) : undefined,
2690
+ limit: query.limit ? Number(query.limit) : undefined
2668
2691
  }); //TODO: this is a partial implementation, but I don't really have the time to implement an actual search API right now
2669
2692
 
2670
2693
 
@@ -3072,7 +3095,6 @@ class ProjectRepository extends AbstractRepository {
3072
3095
  changeCartsConfiguration: (projectKey, resource, {
3073
3096
  cartsConfiguration
3074
3097
  }) => {
3075
- console.log(cartsConfiguration);
3076
3098
  resource.carts = cartsConfiguration || {
3077
3099
  countryTaxRateFallbackEnabled: false,
3078
3100
  deleteDaysAfterLastModification: 90
@@ -3276,12 +3298,17 @@ class ShippingMethodService extends AbstractService {
3276
3298
  constructor(parent, storage) {
3277
3299
  super(parent);
3278
3300
  this.repository = new ShippingMethodRepository(storage);
3301
+ this.registerRoutes(parent);
3279
3302
  }
3280
3303
 
3281
3304
  getBasePath() {
3282
3305
  return 'shipping-methods';
3283
3306
  }
3284
3307
 
3308
+ extraRoutes(parent) {
3309
+ parent.get('/matching-cart', this.get.bind(this));
3310
+ }
3311
+
3285
3312
  }
3286
3313
 
3287
3314
  class ShoppingListRepository extends AbstractResourceRepository {
@@ -3911,6 +3938,7 @@ class CommercetoolsMock {
3911
3938
  order: new OrderService(projectRouter, this._storage),
3912
3939
  payment: new PaymentService(projectRouter, this._storage),
3913
3940
  'my-cart': new MyCartService(projectRouter, this._storage),
3941
+ 'my-customer': new myCustomer.MyCustomerService(projectRouter, this._storage),
3914
3942
  'my-payment': new MyPaymentService(projectRouter, this._storage),
3915
3943
  'shipping-method': new ShippingMethodService(projectRouter, this._storage),
3916
3944
  'product-type': new ProductTypeService(projectRouter, this._storage),