@labdigital/commercetools-mock 0.5.18 → 0.5.19

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,7 +10,6 @@ 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';
14
13
 
15
14
  const parseExpandClause = clause => {
16
15
  const result = {
@@ -1692,6 +1691,7 @@ class CategoryRepository extends AbstractResourceRepository {
1692
1691
  name: draft.name,
1693
1692
  slug: draft.slug,
1694
1693
  orderHint: draft.orderHint || '',
1694
+ externalId: draft.externalId || '',
1695
1695
  parent: draft.parent ? {
1696
1696
  typeId: 'category',
1697
1697
  id: draft.parent.id
@@ -2271,6 +2271,31 @@ class PaymentRepository extends AbstractResourceRepository {
2271
2271
  transaction
2272
2272
  }) => {
2273
2273
  resource.transactions = [...resource.transactions, this.transactionFromTransactionDraft(transaction, projectKey)];
2274
+ },
2275
+ changeTransactionState: (_projectKey, resource, {
2276
+ transactionId,
2277
+ state
2278
+ }) => {
2279
+ const index = resource.transactions.findIndex(e => e.id === transactionId);
2280
+ const updatedTransaction = { ...resource.transactions[index],
2281
+ state
2282
+ };
2283
+ resource.transactions[index] = updatedTransaction;
2284
+ },
2285
+ transitionState: (projectKey, resource, {
2286
+ state
2287
+ }) => {
2288
+ const stateObj = this._storage.getByResourceIdentifier(projectKey, state);
2289
+
2290
+ if (!stateObj) {
2291
+ throw new Error(`State ${state} not found`);
2292
+ }
2293
+
2294
+ resource.paymentStatus.state = {
2295
+ typeId: 'state',
2296
+ id: stateObj.id,
2297
+ obj: stateObj
2298
+ };
2274
2299
  }
2275
2300
  };
2276
2301
  }
@@ -3833,6 +3858,51 @@ class ZoneService extends AbstractService {
3833
3858
 
3834
3859
  }
3835
3860
 
3861
+ class MyCustomerService extends AbstractService {
3862
+ constructor(parent, storage) {
3863
+ super(parent);
3864
+ this.repository = new CustomerRepository(storage);
3865
+ }
3866
+
3867
+ getBasePath() {
3868
+ return 'me';
3869
+ }
3870
+
3871
+ registerRoutes(parent) {
3872
+ // Overwrite this function to be able to handle /me path.
3873
+ const basePath = this.getBasePath();
3874
+ const router = Router({
3875
+ mergeParams: true
3876
+ });
3877
+ this.extraRoutes(router);
3878
+ router.get('', this.getMe.bind(this));
3879
+ router.post('/signup', this.signUp.bind(this));
3880
+ parent.use(`/${basePath}`, router);
3881
+ }
3882
+
3883
+ getMe(request, response) {
3884
+ const resource = this.repository.getMe(request.params.projectKey);
3885
+
3886
+ if (!resource) {
3887
+ return response.status(404).send('Not found');
3888
+ }
3889
+
3890
+ return response.status(200).send(resource);
3891
+ }
3892
+
3893
+ signUp(request, response) {
3894
+ const draft = request.body;
3895
+ const resource = this.repository.create(request.params.projectKey, draft);
3896
+
3897
+ const result = this._expandWithId(request, resource.id);
3898
+
3899
+ return response.status(this.createStatusCode).send({
3900
+ customer: result
3901
+ });
3902
+ }
3903
+
3904
+ }
3905
+
3836
3906
  const DEFAULT_OPTIONS = {
3837
3907
  enableAuthentication: false,
3838
3908
  validateCredentials: false,