@labdigital/commercetools-mock 0.5.16 → 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 +102 -7
- 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 +102 -7
- package/dist/commercetools-mock.esm.js.map +1 -1
- package/dist/repositories/abstract.d.ts +2 -0
- package/dist/repositories/customer.d.ts +1 -0
- package/dist/repositories/payment.d.ts +3 -1
- package/dist/services/my-customer.d.ts +12 -0
- package/dist/services/shipping-method.d.ts +2 -1
- package/dist/types.d.ts +1 -1
- package/package.json +2 -16
- package/src/ctMock.ts +2 -0
- package/src/repositories/abstract.ts +4 -0
- package/src/repositories/category.ts +1 -0
- package/src/repositories/customer.ts +9 -1
- package/src/repositories/discount-code.ts +0 -1
- package/src/repositories/payment.ts +38 -2
- package/src/repositories/product-projection.ts +2 -0
- package/src/repositories/project.ts +0 -1
- package/src/services/abstract.ts +5 -1
- package/src/services/my-customer.test.ts +51 -0
- package/src/services/my-customer.ts +46 -0
- package/src/services/product-projection.test.ts +20 -0
- package/src/services/shipping-method.test.ts +27 -0
- package/src/services/shipping-method.ts +6 -1
- package/src/types.ts +5 -1
|
@@ -985,9 +985,15 @@ class AbstractService {
|
|
|
985
985
|
}
|
|
986
986
|
|
|
987
987
|
get(request, response) {
|
|
988
|
+
const limit = this._parseParam(request.query.limit);
|
|
989
|
+
|
|
990
|
+
const offset = this._parseParam(request.query.offset);
|
|
991
|
+
|
|
988
992
|
const result = this.repository.query(request.params.projectKey, {
|
|
989
993
|
expand: this._parseParam(request.query.expand),
|
|
990
|
-
where: this._parseParam(request.query.where)
|
|
994
|
+
where: this._parseParam(request.query.where),
|
|
995
|
+
limit: limit !== undefined ? Number(limit) : undefined,
|
|
996
|
+
offset: offset !== undefined ? Number(offset) : undefined
|
|
991
997
|
});
|
|
992
998
|
return response.status(200).send(result);
|
|
993
999
|
}
|
|
@@ -999,7 +1005,6 @@ class AbstractService {
|
|
|
999
1005
|
return response.status(404).send();
|
|
1000
1006
|
}
|
|
1001
1007
|
|
|
1002
|
-
console.log(JSON.stringify(result, null, 4));
|
|
1003
1008
|
return response.status(200).send(result);
|
|
1004
1009
|
}
|
|
1005
1010
|
|
|
@@ -1128,7 +1133,9 @@ class AbstractResourceRepository extends AbstractRepository {
|
|
|
1128
1133
|
query(projectKey, params = {}) {
|
|
1129
1134
|
return this._storage.query(projectKey, this.getTypeId(), {
|
|
1130
1135
|
expand: params.expand,
|
|
1131
|
-
where: params.where
|
|
1136
|
+
where: params.where,
|
|
1137
|
+
offset: params.offset,
|
|
1138
|
+
limit: params.limit
|
|
1132
1139
|
});
|
|
1133
1140
|
}
|
|
1134
1141
|
|
|
@@ -1691,6 +1698,7 @@ class CategoryRepository extends AbstractResourceRepository {
|
|
|
1691
1698
|
name: draft.name,
|
|
1692
1699
|
slug: draft.slug,
|
|
1693
1700
|
orderHint: draft.orderHint || '',
|
|
1701
|
+
externalId: draft.externalId || '',
|
|
1694
1702
|
parent: draft.parent ? {
|
|
1695
1703
|
typeId: 'category',
|
|
1696
1704
|
id: draft.parent.id
|
|
@@ -1806,7 +1814,7 @@ class CustomerRepository extends AbstractResourceRepository {
|
|
|
1806
1814
|
create(projectKey, draft) {
|
|
1807
1815
|
const resource = { ...getBaseResourceProperties(),
|
|
1808
1816
|
email: draft.email,
|
|
1809
|
-
password: draft.password,
|
|
1817
|
+
password: Buffer.from(draft.password).toString('base64'),
|
|
1810
1818
|
isEmailVerified: draft.isEmailVerified || false,
|
|
1811
1819
|
addresses: []
|
|
1812
1820
|
};
|
|
@@ -1814,6 +1822,17 @@ class CustomerRepository extends AbstractResourceRepository {
|
|
|
1814
1822
|
return resource;
|
|
1815
1823
|
}
|
|
1816
1824
|
|
|
1825
|
+
getMe(projectKey) {
|
|
1826
|
+
const results = this._storage.query(projectKey, this.getTypeId(), {}); // grab the first customer you can find
|
|
1827
|
+
|
|
1828
|
+
|
|
1829
|
+
if (results.count > 0) {
|
|
1830
|
+
return results.results[0];
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
return;
|
|
1834
|
+
}
|
|
1835
|
+
|
|
1817
1836
|
}
|
|
1818
1837
|
|
|
1819
1838
|
class CustomerService extends AbstractService {
|
|
@@ -1989,7 +2008,6 @@ class DiscountCodeRepository extends AbstractResourceRepository {
|
|
|
1989
2008
|
}
|
|
1990
2009
|
|
|
1991
2010
|
create(projectKey, draft) {
|
|
1992
|
-
console.log(draft);
|
|
1993
2011
|
const resource = { ...getBaseResourceProperties(),
|
|
1994
2012
|
applicationVersion: 1,
|
|
1995
2013
|
cartDiscounts: draft.cartDiscounts.map(obj => ({
|
|
@@ -2260,6 +2278,31 @@ class PaymentRepository extends AbstractResourceRepository {
|
|
|
2260
2278
|
transaction
|
|
2261
2279
|
}) => {
|
|
2262
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
|
+
};
|
|
2263
2306
|
}
|
|
2264
2307
|
};
|
|
2265
2308
|
}
|
|
@@ -2667,7 +2710,9 @@ class ProductProjectionRepository extends AbstractResourceRepository {
|
|
|
2667
2710
|
const wherePredicate = filter ? parseFilterExpression(filter) : undefined;
|
|
2668
2711
|
|
|
2669
2712
|
const results = this._storage.query(projectKey, this.getTypeId(), {
|
|
2670
|
-
where: wherePredicate
|
|
2713
|
+
where: wherePredicate,
|
|
2714
|
+
offset: query.offset ? Number(query.offset) : undefined,
|
|
2715
|
+
limit: query.limit ? Number(query.limit) : undefined
|
|
2671
2716
|
}); //TODO: this is a partial implementation, but I don't really have the time to implement an actual search API right now
|
|
2672
2717
|
|
|
2673
2718
|
|
|
@@ -3075,7 +3120,6 @@ class ProjectRepository extends AbstractRepository {
|
|
|
3075
3120
|
changeCartsConfiguration: (projectKey, resource, {
|
|
3076
3121
|
cartsConfiguration
|
|
3077
3122
|
}) => {
|
|
3078
|
-
console.log(cartsConfiguration);
|
|
3079
3123
|
resource.carts = cartsConfiguration || {
|
|
3080
3124
|
countryTaxRateFallbackEnabled: false,
|
|
3081
3125
|
deleteDaysAfterLastModification: 90
|
|
@@ -3279,12 +3323,17 @@ class ShippingMethodService extends AbstractService {
|
|
|
3279
3323
|
constructor(parent, storage) {
|
|
3280
3324
|
super(parent);
|
|
3281
3325
|
this.repository = new ShippingMethodRepository(storage);
|
|
3326
|
+
this.registerRoutes(parent);
|
|
3282
3327
|
}
|
|
3283
3328
|
|
|
3284
3329
|
getBasePath() {
|
|
3285
3330
|
return 'shipping-methods';
|
|
3286
3331
|
}
|
|
3287
3332
|
|
|
3333
|
+
extraRoutes(parent) {
|
|
3334
|
+
parent.get('/matching-cart', this.get.bind(this));
|
|
3335
|
+
}
|
|
3336
|
+
|
|
3288
3337
|
}
|
|
3289
3338
|
|
|
3290
3339
|
class ShoppingListRepository extends AbstractResourceRepository {
|
|
@@ -3816,6 +3865,51 @@ class ZoneService extends AbstractService {
|
|
|
3816
3865
|
|
|
3817
3866
|
}
|
|
3818
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
|
+
|
|
3819
3913
|
const DEFAULT_OPTIONS = {
|
|
3820
3914
|
enableAuthentication: false,
|
|
3821
3915
|
validateCredentials: false,
|
|
@@ -3914,6 +4008,7 @@ class CommercetoolsMock {
|
|
|
3914
4008
|
order: new OrderService(projectRouter, this._storage),
|
|
3915
4009
|
payment: new PaymentService(projectRouter, this._storage),
|
|
3916
4010
|
'my-cart': new MyCartService(projectRouter, this._storage),
|
|
4011
|
+
'my-customer': new MyCustomerService(projectRouter, this._storage),
|
|
3917
4012
|
'my-payment': new MyPaymentService(projectRouter, this._storage),
|
|
3918
4013
|
'shipping-method': new ShippingMethodService(projectRouter, this._storage),
|
|
3919
4014
|
'product-type': new ProductTypeService(projectRouter, this._storage),
|