@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.
- package/dist/commercetools-mock.cjs.development.js +72 -2
- package/dist/commercetools-mock.cjs.development.js.map +1 -1
- package/dist/commercetools-mock.cjs.production.min.js +1 -1
- package/dist/commercetools-mock.cjs.production.min.js.map +1 -1
- package/dist/commercetools-mock.esm.js +71 -1
- package/dist/commercetools-mock.esm.js.map +1 -1
- package/dist/repositories/payment.d.ts +3 -1
- package/package.json +1 -1
- package/src/ctMock.ts +1 -1
- package/src/repositories/category.ts +1 -0
- package/src/repositories/payment.ts +38 -2
|
@@ -17,7 +17,6 @@ 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');
|
|
21
20
|
|
|
22
21
|
const parseExpandClause = clause => {
|
|
23
22
|
const result = {
|
|
@@ -1699,6 +1698,7 @@ class CategoryRepository extends AbstractResourceRepository {
|
|
|
1699
1698
|
name: draft.name,
|
|
1700
1699
|
slug: draft.slug,
|
|
1701
1700
|
orderHint: draft.orderHint || '',
|
|
1701
|
+
externalId: draft.externalId || '',
|
|
1702
1702
|
parent: draft.parent ? {
|
|
1703
1703
|
typeId: 'category',
|
|
1704
1704
|
id: draft.parent.id
|
|
@@ -2278,6 +2278,31 @@ class PaymentRepository extends AbstractResourceRepository {
|
|
|
2278
2278
|
transaction
|
|
2279
2279
|
}) => {
|
|
2280
2280
|
resource.transactions = [...resource.transactions, this.transactionFromTransactionDraft(transaction, projectKey)];
|
|
2281
|
+
},
|
|
2282
|
+
changeTransactionState: (_projectKey, resource, {
|
|
2283
|
+
transactionId,
|
|
2284
|
+
state
|
|
2285
|
+
}) => {
|
|
2286
|
+
const index = resource.transactions.findIndex(e => e.id === transactionId);
|
|
2287
|
+
const updatedTransaction = { ...resource.transactions[index],
|
|
2288
|
+
state
|
|
2289
|
+
};
|
|
2290
|
+
resource.transactions[index] = updatedTransaction;
|
|
2291
|
+
},
|
|
2292
|
+
transitionState: (projectKey, resource, {
|
|
2293
|
+
state
|
|
2294
|
+
}) => {
|
|
2295
|
+
const stateObj = this._storage.getByResourceIdentifier(projectKey, state);
|
|
2296
|
+
|
|
2297
|
+
if (!stateObj) {
|
|
2298
|
+
throw new Error(`State ${state} not found`);
|
|
2299
|
+
}
|
|
2300
|
+
|
|
2301
|
+
resource.paymentStatus.state = {
|
|
2302
|
+
typeId: 'state',
|
|
2303
|
+
id: stateObj.id,
|
|
2304
|
+
obj: stateObj
|
|
2305
|
+
};
|
|
2281
2306
|
}
|
|
2282
2307
|
};
|
|
2283
2308
|
}
|
|
@@ -3840,6 +3865,51 @@ class ZoneService extends AbstractService {
|
|
|
3840
3865
|
|
|
3841
3866
|
}
|
|
3842
3867
|
|
|
3868
|
+
class MyCustomerService extends AbstractService {
|
|
3869
|
+
constructor(parent, storage) {
|
|
3870
|
+
super(parent);
|
|
3871
|
+
this.repository = new CustomerRepository(storage);
|
|
3872
|
+
}
|
|
3873
|
+
|
|
3874
|
+
getBasePath() {
|
|
3875
|
+
return 'me';
|
|
3876
|
+
}
|
|
3877
|
+
|
|
3878
|
+
registerRoutes(parent) {
|
|
3879
|
+
// Overwrite this function to be able to handle /me path.
|
|
3880
|
+
const basePath = this.getBasePath();
|
|
3881
|
+
const router = express.Router({
|
|
3882
|
+
mergeParams: true
|
|
3883
|
+
});
|
|
3884
|
+
this.extraRoutes(router);
|
|
3885
|
+
router.get('', this.getMe.bind(this));
|
|
3886
|
+
router.post('/signup', this.signUp.bind(this));
|
|
3887
|
+
parent.use(`/${basePath}`, router);
|
|
3888
|
+
}
|
|
3889
|
+
|
|
3890
|
+
getMe(request, response) {
|
|
3891
|
+
const resource = this.repository.getMe(request.params.projectKey);
|
|
3892
|
+
|
|
3893
|
+
if (!resource) {
|
|
3894
|
+
return response.status(404).send('Not found');
|
|
3895
|
+
}
|
|
3896
|
+
|
|
3897
|
+
return response.status(200).send(resource);
|
|
3898
|
+
}
|
|
3899
|
+
|
|
3900
|
+
signUp(request, response) {
|
|
3901
|
+
const draft = request.body;
|
|
3902
|
+
const resource = this.repository.create(request.params.projectKey, draft);
|
|
3903
|
+
|
|
3904
|
+
const result = this._expandWithId(request, resource.id);
|
|
3905
|
+
|
|
3906
|
+
return response.status(this.createStatusCode).send({
|
|
3907
|
+
customer: result
|
|
3908
|
+
});
|
|
3909
|
+
}
|
|
3910
|
+
|
|
3911
|
+
}
|
|
3912
|
+
|
|
3843
3913
|
const DEFAULT_OPTIONS = {
|
|
3844
3914
|
enableAuthentication: false,
|
|
3845
3915
|
validateCredentials: false,
|
|
@@ -3938,7 +4008,7 @@ class CommercetoolsMock {
|
|
|
3938
4008
|
order: new OrderService(projectRouter, this._storage),
|
|
3939
4009
|
payment: new PaymentService(projectRouter, this._storage),
|
|
3940
4010
|
'my-cart': new MyCartService(projectRouter, this._storage),
|
|
3941
|
-
'my-customer': new
|
|
4011
|
+
'my-customer': new MyCustomerService(projectRouter, this._storage),
|
|
3942
4012
|
'my-payment': new MyPaymentService(projectRouter, this._storage),
|
|
3943
4013
|
'shipping-method': new ShippingMethodService(projectRouter, this._storage),
|
|
3944
4014
|
'product-type': new ProductTypeService(projectRouter, this._storage),
|