@labdigital/commercetools-mock 0.5.19 → 0.5.20

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.
@@ -1610,11 +1610,11 @@ class CategoryRepository extends AbstractResourceRepository {
1610
1610
  var _resource$assets;
1611
1611
 
1612
1612
  (_resource$assets = resource.assets) == null ? void 0 : _resource$assets.forEach(asset => {
1613
- if (assetId && assetId == asset.id) {
1613
+ if (assetId && assetId === asset.id) {
1614
1614
  asset.name = name;
1615
1615
  }
1616
1616
 
1617
- if (assetKey && assetKey == asset.key) {
1617
+ if (assetKey && assetKey === asset.key) {
1618
1618
  asset.name = name;
1619
1619
  }
1620
1620
  });
@@ -1637,11 +1637,11 @@ class CategoryRepository extends AbstractResourceRepository {
1637
1637
  var _resource$assets2;
1638
1638
 
1639
1639
  (_resource$assets2 = resource.assets) == null ? void 0 : _resource$assets2.forEach(asset => {
1640
- if (assetId && assetId == asset.id) {
1640
+ if (assetId && assetId === asset.id) {
1641
1641
  asset.description = description;
1642
1642
  }
1643
1643
 
1644
- if (assetKey && assetKey == asset.key) {
1644
+ if (assetKey && assetKey === asset.key) {
1645
1645
  asset.description = description;
1646
1646
  }
1647
1647
  });
@@ -1654,11 +1654,11 @@ class CategoryRepository extends AbstractResourceRepository {
1654
1654
  var _resource$assets3;
1655
1655
 
1656
1656
  (_resource$assets3 = resource.assets) == null ? void 0 : _resource$assets3.forEach(asset => {
1657
- if (assetId && assetId == asset.id) {
1657
+ if (assetId && assetId === asset.id) {
1658
1658
  asset.sources = sources;
1659
1659
  }
1660
1660
 
1661
- if (assetKey && assetKey == asset.key) {
1661
+ if (assetKey && assetKey === asset.key) {
1662
1662
  asset.sources = sources;
1663
1663
  }
1664
1664
  });
@@ -1807,6 +1807,17 @@ class CustomerGroupService extends AbstractService {
1807
1807
  }
1808
1808
 
1809
1809
  class CustomerRepository extends AbstractResourceRepository {
1810
+ constructor() {
1811
+ super(...arguments);
1812
+ this.actions = {
1813
+ changeEmail: (_projectKey, resource, {
1814
+ email
1815
+ }) => {
1816
+ resource.email = email;
1817
+ }
1818
+ };
1819
+ }
1820
+
1810
1821
  getTypeId() {
1811
1822
  return 'customer';
1812
1823
  }
@@ -1845,6 +1856,24 @@ class CustomerService extends AbstractService {
1845
1856
  return 'customers';
1846
1857
  }
1847
1858
 
1859
+ extraRoutes(parent) {
1860
+ parent.post('/password-token', (request, response) => {
1861
+ const customer = this.repository.query(request.params.projectKey, {
1862
+ where: [`email="${request.body.email}"`]
1863
+ });
1864
+ const ttlMinutes = request.params.ttlMinutes ? +request.params.ttlMinutes : 34560;
1865
+ const {
1866
+ version,
1867
+ ...rest
1868
+ } = getBaseResourceProperties();
1869
+ return response.status(200).send({ ...rest,
1870
+ customerId: customer.results[0].id,
1871
+ expiresAt: new Date(Date.now() + ttlMinutes * 60).toISOString(),
1872
+ value: uuid.v4()
1873
+ });
1874
+ });
1875
+ }
1876
+
1848
1877
  }
1849
1878
 
1850
1879
  class CustomObjectRepository extends AbstractResourceRepository {
@@ -2932,7 +2961,7 @@ class ProductTypeRepository extends AbstractResourceRepository {
2932
2961
  switch (type.name) {
2933
2962
  case 'lenum':
2934
2963
  type.values.forEach(v => {
2935
- if (v.key == newValue.key) {
2964
+ if (v.key === newValue.key) {
2936
2965
  v.label = newValue.label;
2937
2966
  }
2938
2967
  });
@@ -2945,7 +2974,7 @@ class ProductTypeRepository extends AbstractResourceRepository {
2945
2974
  };
2946
2975
 
2947
2976
  (_resource$attributes = resource.attributes) == null ? void 0 : _resource$attributes.forEach(value => {
2948
- if (value.name == attributeName) {
2977
+ if (value.name === attributeName) {
2949
2978
  updateAttributeType(value.type);
2950
2979
  }
2951
2980
  });
@@ -2957,7 +2986,7 @@ class ProductTypeRepository extends AbstractResourceRepository {
2957
2986
  var _resource$attributes2;
2958
2987
 
2959
2988
  (_resource$attributes2 = resource.attributes) == null ? void 0 : _resource$attributes2.forEach(value => {
2960
- if (value.name == attributeName) {
2989
+ if (value.name === attributeName) {
2961
2990
  value.label = label;
2962
2991
  }
2963
2992
  });
@@ -3037,7 +3066,7 @@ const maskSecretValue = (resource, path) => {
3037
3066
  const part = parts[i];
3038
3067
  val = val[part];
3039
3068
 
3040
- if (val == undefined) {
3069
+ if (val === undefined) {
3041
3070
  return resource;
3042
3071
  }
3043
3072
  }
@@ -3129,8 +3158,6 @@ class ProjectRepository extends AbstractRepository {
3129
3158
  }
3130
3159
 
3131
3160
  get(projectKey) {
3132
- const data = this._storage.getProject(projectKey);
3133
-
3134
3161
  const resource = this._storage.getProject(projectKey);
3135
3162
 
3136
3163
  const masked = maskSecretValue(resource, 'externalOAuth.authorizationHeader');
@@ -3184,7 +3211,7 @@ class ProjectService {
3184
3211
  return response.status(404).send({});
3185
3212
  }
3186
3213
 
3187
- const updatedResource = this.repository.processUpdateActions(request.params.projectKey, project, updateRequest.actions);
3214
+ this.repository.processUpdateActions(request.params.projectKey, project, updateRequest.actions);
3188
3215
  return response.status(200).send({});
3189
3216
  }
3190
3217
 
@@ -3212,14 +3239,14 @@ class ShippingMethodRepository extends AbstractResourceRepository {
3212
3239
  };
3213
3240
 
3214
3241
  this.actions = {
3215
- addShippingRate: (projectKey, resource, {
3242
+ addShippingRate: (_projectKey, resource, {
3216
3243
  shippingRate,
3217
3244
  zone
3218
3245
  }) => {
3219
3246
  const rate = this._transformShippingRate(shippingRate);
3220
3247
 
3221
3248
  resource.zoneRates.forEach(zoneRate => {
3222
- if (zoneRate.zone.id == zone.id) {
3249
+ if (zoneRate.zone.id === zone.id) {
3223
3250
  zoneRate.shippingRates.push(rate);
3224
3251
  return;
3225
3252
  }
@@ -3232,14 +3259,14 @@ class ShippingMethodRepository extends AbstractResourceRepository {
3232
3259
  shippingRates: [rate]
3233
3260
  });
3234
3261
  },
3235
- removeShippingRate: (projectKey, resource, {
3262
+ removeShippingRate: (_projectKey, resource, {
3236
3263
  shippingRate,
3237
3264
  zone
3238
3265
  }) => {
3239
3266
  const rate = this._transformShippingRate(shippingRate);
3240
3267
 
3241
3268
  resource.zoneRates.forEach(zoneRate => {
3242
- if (zoneRate.zone.id == zone.id) {
3269
+ if (zoneRate.zone.id === zone.id) {
3243
3270
  zoneRate.shippingRates = zoneRate.shippingRates.filter(otherRate => {
3244
3271
  return !deepEqual(rate, otherRate);
3245
3272
  });
@@ -3260,39 +3287,39 @@ class ShippingMethodRepository extends AbstractResourceRepository {
3260
3287
  shippingRates: []
3261
3288
  });
3262
3289
  },
3263
- removeZone: (projectKey, resource, {
3290
+ removeZone: (_projectKey, resource, {
3264
3291
  zone
3265
3292
  }) => {
3266
3293
  resource.zoneRates = resource.zoneRates.filter(zoneRate => {
3267
3294
  return zoneRate.zone.id !== zone.id;
3268
3295
  });
3269
3296
  },
3270
- setKey: (projectKey, resource, {
3297
+ setKey: (_projectKey, resource, {
3271
3298
  key
3272
3299
  }) => {
3273
3300
  resource.key = key;
3274
3301
  },
3275
- setDescription: (projectKey, resource, {
3302
+ setDescription: (_projectKey, resource, {
3276
3303
  description
3277
3304
  }) => {
3278
3305
  resource.description = description;
3279
3306
  },
3280
- setLocalizedDescription: (projectKey, resource, {
3307
+ setLocalizedDescription: (_projectKey, resource, {
3281
3308
  localizedDescription
3282
3309
  }) => {
3283
3310
  resource.localizedDescription = localizedDescription;
3284
3311
  },
3285
- setPredicate: (projectKey, resource, {
3312
+ setPredicate: (_projectKey, resource, {
3286
3313
  predicate
3287
3314
  }) => {
3288
3315
  resource.predicate = predicate;
3289
3316
  },
3290
- changeIsDefault: (projectKey, resource, {
3317
+ changeIsDefault: (_projectKey, resource, {
3291
3318
  isDefault
3292
3319
  }) => {
3293
3320
  resource.isDefault = isDefault;
3294
3321
  },
3295
- changeName: (projectKey, resource, {
3322
+ changeName: (_projectKey, resource, {
3296
3323
  name
3297
3324
  }) => {
3298
3325
  resource.name = name;
@@ -3488,6 +3515,22 @@ class StoreRepository extends AbstractResourceRepository {
3488
3515
  return channels.map(ref => getReferenceFromResourceIdentifier(ref, projectKey, this._storage));
3489
3516
  }
3490
3517
 
3518
+ getWithKey(projectKey, key) {
3519
+ const result = this._storage.query(projectKey, this.getTypeId(), {
3520
+ where: [`key="${key}"`]
3521
+ });
3522
+
3523
+ if (result.count === 1) {
3524
+ return result.results[0];
3525
+ }
3526
+
3527
+ if (result.count > 1) {
3528
+ throw new Error('Duplicate store key');
3529
+ }
3530
+
3531
+ return;
3532
+ }
3533
+
3491
3534
  }
3492
3535
 
3493
3536
  class StoreService extends AbstractService {
@@ -3500,6 +3543,20 @@ class StoreService extends AbstractService {
3500
3543
  return 'stores';
3501
3544
  }
3502
3545
 
3546
+ extraRoutes(router) {
3547
+ router.get('/key=:key', this.getWithKey.bind(this));
3548
+ }
3549
+
3550
+ getWithKey(request, response) {
3551
+ const resource = this.repository.getWithKey(request.params.projectKey, request.params.key);
3552
+
3553
+ if (resource) {
3554
+ return response.status(200).send(resource);
3555
+ }
3556
+
3557
+ return response.status(404).send('Not found');
3558
+ }
3559
+
3503
3560
  }
3504
3561
 
3505
3562
  class SubscriptionRepository extends AbstractResourceRepository {
@@ -3510,11 +3567,11 @@ class SubscriptionRepository extends AbstractResourceRepository {
3510
3567
  create(projectKey, draft) {
3511
3568
  // TODO: We could actually test this here by using the aws sdk. For now
3512
3569
  // hardcode a failed check when account id is 0000000000
3513
- if (draft.destination.type == 'SQS') {
3570
+ if (draft.destination.type === 'SQS') {
3514
3571
  const queueURL = new URL(draft.destination.queueUrl);
3515
3572
  const accountId = queueURL.pathname.split('/')[1];
3516
3573
 
3517
- if (accountId == '0000000000') {
3574
+ if (accountId === '0000000000') {
3518
3575
  const dest = draft.destination;
3519
3576
  throw new CommercetoolsError({
3520
3577
  code: 'InvalidInput',
@@ -3594,7 +3651,7 @@ class TaxCategoryRepository extends AbstractResourceRepository {
3594
3651
  for (let i = 0; i < resource.rates.length; i++) {
3595
3652
  const rate = resource.rates[i];
3596
3653
 
3597
- if (rate.id == taxRateId) {
3654
+ if (rate.id === taxRateId) {
3598
3655
  resource.rates[i] = taxRateObj;
3599
3656
  }
3600
3657
  }
@@ -3732,11 +3789,11 @@ class TypeRepository extends AbstractResourceRepository {
3732
3789
  value
3733
3790
  }) => {
3734
3791
  resource.fieldDefinitions.forEach(field => {
3735
- if (field.name == fieldName) {
3792
+ if (field.name === fieldName) {
3736
3793
  // TODO, should be done better i suppose
3737
- if (field.type.name == 'Enum') {
3794
+ if (field.type.name === 'Enum') {
3738
3795
  field.type.values.push(value);
3739
- } else if (field.type.name == 'Set' && field.type.elementType.name == 'Enum') {
3796
+ } else if (field.type.name === 'Set' && field.type.elementType.name === 'Enum') {
3740
3797
  field.type.elementType.values.push(value);
3741
3798
  } else {
3742
3799
  throw new Error('Type is not a Enum (or Set of Enum)');
@@ -3749,17 +3806,17 @@ class TypeRepository extends AbstractResourceRepository {
3749
3806
  value
3750
3807
  }) => {
3751
3808
  resource.fieldDefinitions.forEach(field => {
3752
- if (field.name == fieldName) {
3809
+ if (field.name === fieldName) {
3753
3810
  // TODO, should be done better i suppose
3754
- if (field.type.name == 'Enum') {
3811
+ if (field.type.name === 'Enum') {
3755
3812
  field.type.values.forEach(v => {
3756
- if (v.key == value.key) {
3813
+ if (v.key === value.key) {
3757
3814
  v.label = value.label;
3758
3815
  }
3759
3816
  });
3760
- } else if (field.type.name == 'Set' && field.type.elementType.name == 'Enum') {
3817
+ } else if (field.type.name === 'Set' && field.type.elementType.name === 'Enum') {
3761
3818
  field.type.elementType.values.forEach(v => {
3762
- if (v.key == value.key) {
3819
+ if (v.key === value.key) {
3763
3820
  v.label = value.label;
3764
3821
  }
3765
3822
  });
@@ -3815,7 +3872,7 @@ class ZoneRepository extends AbstractResourceRepository {
3815
3872
  location
3816
3873
  }) => {
3817
3874
  resource.locations = resource.locations.filter(loc => {
3818
- return !(loc.country == location.country && loc.state == location.state);
3875
+ return !(loc.country === location.country && loc.state === location.state);
3819
3876
  });
3820
3877
  },
3821
3878
  changeName: (projectKey, resource, {