@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.
@@ -10,6 +10,7 @@ import bodyParser from 'body-parser';
10
10
  import { randomBytes } from 'crypto';
11
11
  import { v4 } from 'uuid';
12
12
  import deepEqual from 'deep-equal';
13
+ import { MyCustomerService } from 'services/my-customer';
13
14
 
14
15
  const parseExpandClause = clause => {
15
16
  const result = {
@@ -978,9 +979,15 @@ class AbstractService {
978
979
  }
979
980
 
980
981
  get(request, response) {
982
+ const limit = this._parseParam(request.query.limit);
983
+
984
+ const offset = this._parseParam(request.query.offset);
985
+
981
986
  const result = this.repository.query(request.params.projectKey, {
982
987
  expand: this._parseParam(request.query.expand),
983
- where: this._parseParam(request.query.where)
988
+ where: this._parseParam(request.query.where),
989
+ limit: limit !== undefined ? Number(limit) : undefined,
990
+ offset: offset !== undefined ? Number(offset) : undefined
984
991
  });
985
992
  return response.status(200).send(result);
986
993
  }
@@ -992,7 +999,6 @@ class AbstractService {
992
999
  return response.status(404).send();
993
1000
  }
994
1001
 
995
- console.log(JSON.stringify(result, null, 4));
996
1002
  return response.status(200).send(result);
997
1003
  }
998
1004
 
@@ -1121,7 +1127,9 @@ class AbstractResourceRepository extends AbstractRepository {
1121
1127
  query(projectKey, params = {}) {
1122
1128
  return this._storage.query(projectKey, this.getTypeId(), {
1123
1129
  expand: params.expand,
1124
- where: params.where
1130
+ where: params.where,
1131
+ offset: params.offset,
1132
+ limit: params.limit
1125
1133
  });
1126
1134
  }
1127
1135
 
@@ -1799,7 +1807,7 @@ class CustomerRepository extends AbstractResourceRepository {
1799
1807
  create(projectKey, draft) {
1800
1808
  const resource = { ...getBaseResourceProperties(),
1801
1809
  email: draft.email,
1802
- password: draft.password,
1810
+ password: Buffer.from(draft.password).toString('base64'),
1803
1811
  isEmailVerified: draft.isEmailVerified || false,
1804
1812
  addresses: []
1805
1813
  };
@@ -1807,6 +1815,17 @@ class CustomerRepository extends AbstractResourceRepository {
1807
1815
  return resource;
1808
1816
  }
1809
1817
 
1818
+ getMe(projectKey) {
1819
+ const results = this._storage.query(projectKey, this.getTypeId(), {}); // grab the first customer you can find
1820
+
1821
+
1822
+ if (results.count > 0) {
1823
+ return results.results[0];
1824
+ }
1825
+
1826
+ return;
1827
+ }
1828
+
1810
1829
  }
1811
1830
 
1812
1831
  class CustomerService extends AbstractService {
@@ -1982,7 +2001,6 @@ class DiscountCodeRepository extends AbstractResourceRepository {
1982
2001
  }
1983
2002
 
1984
2003
  create(projectKey, draft) {
1985
- console.log(draft);
1986
2004
  const resource = { ...getBaseResourceProperties(),
1987
2005
  applicationVersion: 1,
1988
2006
  cartDiscounts: draft.cartDiscounts.map(obj => ({
@@ -2654,10 +2672,15 @@ class ProductProjectionRepository extends AbstractResourceRepository {
2654
2672
  }
2655
2673
 
2656
2674
  search(projectKey, query) {
2657
- const wherePredicate = parseFilterExpression(query.filter);
2675
+ var _query$filterQuery;
2676
+
2677
+ const filter = (_query$filterQuery = query['filter.query']) != null ? _query$filterQuery : query.filter;
2678
+ const wherePredicate = filter ? parseFilterExpression(filter) : undefined;
2658
2679
 
2659
2680
  const results = this._storage.query(projectKey, this.getTypeId(), {
2660
- where: wherePredicate
2681
+ where: wherePredicate,
2682
+ offset: query.offset ? Number(query.offset) : undefined,
2683
+ limit: query.limit ? Number(query.limit) : undefined
2661
2684
  }); //TODO: this is a partial implementation, but I don't really have the time to implement an actual search API right now
2662
2685
 
2663
2686
 
@@ -3065,7 +3088,6 @@ class ProjectRepository extends AbstractRepository {
3065
3088
  changeCartsConfiguration: (projectKey, resource, {
3066
3089
  cartsConfiguration
3067
3090
  }) => {
3068
- console.log(cartsConfiguration);
3069
3091
  resource.carts = cartsConfiguration || {
3070
3092
  countryTaxRateFallbackEnabled: false,
3071
3093
  deleteDaysAfterLastModification: 90
@@ -3269,12 +3291,17 @@ class ShippingMethodService extends AbstractService {
3269
3291
  constructor(parent, storage) {
3270
3292
  super(parent);
3271
3293
  this.repository = new ShippingMethodRepository(storage);
3294
+ this.registerRoutes(parent);
3272
3295
  }
3273
3296
 
3274
3297
  getBasePath() {
3275
3298
  return 'shipping-methods';
3276
3299
  }
3277
3300
 
3301
+ extraRoutes(parent) {
3302
+ parent.get('/matching-cart', this.get.bind(this));
3303
+ }
3304
+
3278
3305
  }
3279
3306
 
3280
3307
  class ShoppingListRepository extends AbstractResourceRepository {
@@ -3904,6 +3931,7 @@ class CommercetoolsMock {
3904
3931
  order: new OrderService(projectRouter, this._storage),
3905
3932
  payment: new PaymentService(projectRouter, this._storage),
3906
3933
  'my-cart': new MyCartService(projectRouter, this._storage),
3934
+ 'my-customer': new MyCustomerService(projectRouter, this._storage),
3907
3935
  'my-payment': new MyPaymentService(projectRouter, this._storage),
3908
3936
  'shipping-method': new ShippingMethodService(projectRouter, this._storage),
3909
3937
  'product-type': new ProductTypeService(projectRouter, this._storage),