@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.
@@ -1603,11 +1603,11 @@ class CategoryRepository extends AbstractResourceRepository {
1603
1603
  var _resource$assets;
1604
1604
 
1605
1605
  (_resource$assets = resource.assets) == null ? void 0 : _resource$assets.forEach(asset => {
1606
- if (assetId && assetId == asset.id) {
1606
+ if (assetId && assetId === asset.id) {
1607
1607
  asset.name = name;
1608
1608
  }
1609
1609
 
1610
- if (assetKey && assetKey == asset.key) {
1610
+ if (assetKey && assetKey === asset.key) {
1611
1611
  asset.name = name;
1612
1612
  }
1613
1613
  });
@@ -1630,11 +1630,11 @@ class CategoryRepository extends AbstractResourceRepository {
1630
1630
  var _resource$assets2;
1631
1631
 
1632
1632
  (_resource$assets2 = resource.assets) == null ? void 0 : _resource$assets2.forEach(asset => {
1633
- if (assetId && assetId == asset.id) {
1633
+ if (assetId && assetId === asset.id) {
1634
1634
  asset.description = description;
1635
1635
  }
1636
1636
 
1637
- if (assetKey && assetKey == asset.key) {
1637
+ if (assetKey && assetKey === asset.key) {
1638
1638
  asset.description = description;
1639
1639
  }
1640
1640
  });
@@ -1647,11 +1647,11 @@ class CategoryRepository extends AbstractResourceRepository {
1647
1647
  var _resource$assets3;
1648
1648
 
1649
1649
  (_resource$assets3 = resource.assets) == null ? void 0 : _resource$assets3.forEach(asset => {
1650
- if (assetId && assetId == asset.id) {
1650
+ if (assetId && assetId === asset.id) {
1651
1651
  asset.sources = sources;
1652
1652
  }
1653
1653
 
1654
- if (assetKey && assetKey == asset.key) {
1654
+ if (assetKey && assetKey === asset.key) {
1655
1655
  asset.sources = sources;
1656
1656
  }
1657
1657
  });
@@ -1800,6 +1800,17 @@ class CustomerGroupService extends AbstractService {
1800
1800
  }
1801
1801
 
1802
1802
  class CustomerRepository extends AbstractResourceRepository {
1803
+ constructor() {
1804
+ super(...arguments);
1805
+ this.actions = {
1806
+ changeEmail: (_projectKey, resource, {
1807
+ email
1808
+ }) => {
1809
+ resource.email = email;
1810
+ }
1811
+ };
1812
+ }
1813
+
1803
1814
  getTypeId() {
1804
1815
  return 'customer';
1805
1816
  }
@@ -1838,6 +1849,24 @@ class CustomerService extends AbstractService {
1838
1849
  return 'customers';
1839
1850
  }
1840
1851
 
1852
+ extraRoutes(parent) {
1853
+ parent.post('/password-token', (request, response) => {
1854
+ const customer = this.repository.query(request.params.projectKey, {
1855
+ where: [`email="${request.body.email}"`]
1856
+ });
1857
+ const ttlMinutes = request.params.ttlMinutes ? +request.params.ttlMinutes : 34560;
1858
+ const {
1859
+ version,
1860
+ ...rest
1861
+ } = getBaseResourceProperties();
1862
+ return response.status(200).send({ ...rest,
1863
+ customerId: customer.results[0].id,
1864
+ expiresAt: new Date(Date.now() + ttlMinutes * 60).toISOString(),
1865
+ value: v4()
1866
+ });
1867
+ });
1868
+ }
1869
+
1841
1870
  }
1842
1871
 
1843
1872
  class CustomObjectRepository extends AbstractResourceRepository {
@@ -2925,7 +2954,7 @@ class ProductTypeRepository extends AbstractResourceRepository {
2925
2954
  switch (type.name) {
2926
2955
  case 'lenum':
2927
2956
  type.values.forEach(v => {
2928
- if (v.key == newValue.key) {
2957
+ if (v.key === newValue.key) {
2929
2958
  v.label = newValue.label;
2930
2959
  }
2931
2960
  });
@@ -2938,7 +2967,7 @@ class ProductTypeRepository extends AbstractResourceRepository {
2938
2967
  };
2939
2968
 
2940
2969
  (_resource$attributes = resource.attributes) == null ? void 0 : _resource$attributes.forEach(value => {
2941
- if (value.name == attributeName) {
2970
+ if (value.name === attributeName) {
2942
2971
  updateAttributeType(value.type);
2943
2972
  }
2944
2973
  });
@@ -2950,7 +2979,7 @@ class ProductTypeRepository extends AbstractResourceRepository {
2950
2979
  var _resource$attributes2;
2951
2980
 
2952
2981
  (_resource$attributes2 = resource.attributes) == null ? void 0 : _resource$attributes2.forEach(value => {
2953
- if (value.name == attributeName) {
2982
+ if (value.name === attributeName) {
2954
2983
  value.label = label;
2955
2984
  }
2956
2985
  });
@@ -3030,7 +3059,7 @@ const maskSecretValue = (resource, path) => {
3030
3059
  const part = parts[i];
3031
3060
  val = val[part];
3032
3061
 
3033
- if (val == undefined) {
3062
+ if (val === undefined) {
3034
3063
  return resource;
3035
3064
  }
3036
3065
  }
@@ -3122,8 +3151,6 @@ class ProjectRepository extends AbstractRepository {
3122
3151
  }
3123
3152
 
3124
3153
  get(projectKey) {
3125
- const data = this._storage.getProject(projectKey);
3126
-
3127
3154
  const resource = this._storage.getProject(projectKey);
3128
3155
 
3129
3156
  const masked = maskSecretValue(resource, 'externalOAuth.authorizationHeader');
@@ -3177,7 +3204,7 @@ class ProjectService {
3177
3204
  return response.status(404).send({});
3178
3205
  }
3179
3206
 
3180
- const updatedResource = this.repository.processUpdateActions(request.params.projectKey, project, updateRequest.actions);
3207
+ this.repository.processUpdateActions(request.params.projectKey, project, updateRequest.actions);
3181
3208
  return response.status(200).send({});
3182
3209
  }
3183
3210
 
@@ -3205,14 +3232,14 @@ class ShippingMethodRepository extends AbstractResourceRepository {
3205
3232
  };
3206
3233
 
3207
3234
  this.actions = {
3208
- addShippingRate: (projectKey, resource, {
3235
+ addShippingRate: (_projectKey, resource, {
3209
3236
  shippingRate,
3210
3237
  zone
3211
3238
  }) => {
3212
3239
  const rate = this._transformShippingRate(shippingRate);
3213
3240
 
3214
3241
  resource.zoneRates.forEach(zoneRate => {
3215
- if (zoneRate.zone.id == zone.id) {
3242
+ if (zoneRate.zone.id === zone.id) {
3216
3243
  zoneRate.shippingRates.push(rate);
3217
3244
  return;
3218
3245
  }
@@ -3225,14 +3252,14 @@ class ShippingMethodRepository extends AbstractResourceRepository {
3225
3252
  shippingRates: [rate]
3226
3253
  });
3227
3254
  },
3228
- removeShippingRate: (projectKey, resource, {
3255
+ removeShippingRate: (_projectKey, resource, {
3229
3256
  shippingRate,
3230
3257
  zone
3231
3258
  }) => {
3232
3259
  const rate = this._transformShippingRate(shippingRate);
3233
3260
 
3234
3261
  resource.zoneRates.forEach(zoneRate => {
3235
- if (zoneRate.zone.id == zone.id) {
3262
+ if (zoneRate.zone.id === zone.id) {
3236
3263
  zoneRate.shippingRates = zoneRate.shippingRates.filter(otherRate => {
3237
3264
  return !deepEqual(rate, otherRate);
3238
3265
  });
@@ -3253,39 +3280,39 @@ class ShippingMethodRepository extends AbstractResourceRepository {
3253
3280
  shippingRates: []
3254
3281
  });
3255
3282
  },
3256
- removeZone: (projectKey, resource, {
3283
+ removeZone: (_projectKey, resource, {
3257
3284
  zone
3258
3285
  }) => {
3259
3286
  resource.zoneRates = resource.zoneRates.filter(zoneRate => {
3260
3287
  return zoneRate.zone.id !== zone.id;
3261
3288
  });
3262
3289
  },
3263
- setKey: (projectKey, resource, {
3290
+ setKey: (_projectKey, resource, {
3264
3291
  key
3265
3292
  }) => {
3266
3293
  resource.key = key;
3267
3294
  },
3268
- setDescription: (projectKey, resource, {
3295
+ setDescription: (_projectKey, resource, {
3269
3296
  description
3270
3297
  }) => {
3271
3298
  resource.description = description;
3272
3299
  },
3273
- setLocalizedDescription: (projectKey, resource, {
3300
+ setLocalizedDescription: (_projectKey, resource, {
3274
3301
  localizedDescription
3275
3302
  }) => {
3276
3303
  resource.localizedDescription = localizedDescription;
3277
3304
  },
3278
- setPredicate: (projectKey, resource, {
3305
+ setPredicate: (_projectKey, resource, {
3279
3306
  predicate
3280
3307
  }) => {
3281
3308
  resource.predicate = predicate;
3282
3309
  },
3283
- changeIsDefault: (projectKey, resource, {
3310
+ changeIsDefault: (_projectKey, resource, {
3284
3311
  isDefault
3285
3312
  }) => {
3286
3313
  resource.isDefault = isDefault;
3287
3314
  },
3288
- changeName: (projectKey, resource, {
3315
+ changeName: (_projectKey, resource, {
3289
3316
  name
3290
3317
  }) => {
3291
3318
  resource.name = name;
@@ -3481,6 +3508,22 @@ class StoreRepository extends AbstractResourceRepository {
3481
3508
  return channels.map(ref => getReferenceFromResourceIdentifier(ref, projectKey, this._storage));
3482
3509
  }
3483
3510
 
3511
+ getWithKey(projectKey, key) {
3512
+ const result = this._storage.query(projectKey, this.getTypeId(), {
3513
+ where: [`key="${key}"`]
3514
+ });
3515
+
3516
+ if (result.count === 1) {
3517
+ return result.results[0];
3518
+ }
3519
+
3520
+ if (result.count > 1) {
3521
+ throw new Error('Duplicate store key');
3522
+ }
3523
+
3524
+ return;
3525
+ }
3526
+
3484
3527
  }
3485
3528
 
3486
3529
  class StoreService extends AbstractService {
@@ -3493,6 +3536,20 @@ class StoreService extends AbstractService {
3493
3536
  return 'stores';
3494
3537
  }
3495
3538
 
3539
+ extraRoutes(router) {
3540
+ router.get('/key=:key', this.getWithKey.bind(this));
3541
+ }
3542
+
3543
+ getWithKey(request, response) {
3544
+ const resource = this.repository.getWithKey(request.params.projectKey, request.params.key);
3545
+
3546
+ if (resource) {
3547
+ return response.status(200).send(resource);
3548
+ }
3549
+
3550
+ return response.status(404).send('Not found');
3551
+ }
3552
+
3496
3553
  }
3497
3554
 
3498
3555
  class SubscriptionRepository extends AbstractResourceRepository {
@@ -3503,11 +3560,11 @@ class SubscriptionRepository extends AbstractResourceRepository {
3503
3560
  create(projectKey, draft) {
3504
3561
  // TODO: We could actually test this here by using the aws sdk. For now
3505
3562
  // hardcode a failed check when account id is 0000000000
3506
- if (draft.destination.type == 'SQS') {
3563
+ if (draft.destination.type === 'SQS') {
3507
3564
  const queueURL = new URL(draft.destination.queueUrl);
3508
3565
  const accountId = queueURL.pathname.split('/')[1];
3509
3566
 
3510
- if (accountId == '0000000000') {
3567
+ if (accountId === '0000000000') {
3511
3568
  const dest = draft.destination;
3512
3569
  throw new CommercetoolsError({
3513
3570
  code: 'InvalidInput',
@@ -3587,7 +3644,7 @@ class TaxCategoryRepository extends AbstractResourceRepository {
3587
3644
  for (let i = 0; i < resource.rates.length; i++) {
3588
3645
  const rate = resource.rates[i];
3589
3646
 
3590
- if (rate.id == taxRateId) {
3647
+ if (rate.id === taxRateId) {
3591
3648
  resource.rates[i] = taxRateObj;
3592
3649
  }
3593
3650
  }
@@ -3725,11 +3782,11 @@ class TypeRepository extends AbstractResourceRepository {
3725
3782
  value
3726
3783
  }) => {
3727
3784
  resource.fieldDefinitions.forEach(field => {
3728
- if (field.name == fieldName) {
3785
+ if (field.name === fieldName) {
3729
3786
  // TODO, should be done better i suppose
3730
- if (field.type.name == 'Enum') {
3787
+ if (field.type.name === 'Enum') {
3731
3788
  field.type.values.push(value);
3732
- } else if (field.type.name == 'Set' && field.type.elementType.name == 'Enum') {
3789
+ } else if (field.type.name === 'Set' && field.type.elementType.name === 'Enum') {
3733
3790
  field.type.elementType.values.push(value);
3734
3791
  } else {
3735
3792
  throw new Error('Type is not a Enum (or Set of Enum)');
@@ -3742,17 +3799,17 @@ class TypeRepository extends AbstractResourceRepository {
3742
3799
  value
3743
3800
  }) => {
3744
3801
  resource.fieldDefinitions.forEach(field => {
3745
- if (field.name == fieldName) {
3802
+ if (field.name === fieldName) {
3746
3803
  // TODO, should be done better i suppose
3747
- if (field.type.name == 'Enum') {
3804
+ if (field.type.name === 'Enum') {
3748
3805
  field.type.values.forEach(v => {
3749
- if (v.key == value.key) {
3806
+ if (v.key === value.key) {
3750
3807
  v.label = value.label;
3751
3808
  }
3752
3809
  });
3753
- } else if (field.type.name == 'Set' && field.type.elementType.name == 'Enum') {
3810
+ } else if (field.type.name === 'Set' && field.type.elementType.name === 'Enum') {
3754
3811
  field.type.elementType.values.forEach(v => {
3755
- if (v.key == value.key) {
3812
+ if (v.key === value.key) {
3756
3813
  v.label = value.label;
3757
3814
  }
3758
3815
  });
@@ -3808,7 +3865,7 @@ class ZoneRepository extends AbstractResourceRepository {
3808
3865
  location
3809
3866
  }) => {
3810
3867
  resource.locations = resource.locations.filter(loc => {
3811
- return !(loc.country == location.country && loc.state == location.state);
3868
+ return !(loc.country === location.country && loc.state === location.state);
3812
3869
  });
3813
3870
  },
3814
3871
  changeName: (projectKey, resource, {