@labdigital/commercetools-mock 0.5.18 → 0.5.21

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.
@@ -1,7 +1,11 @@
1
- import { Customer, CustomerDraft, ReferenceTypeId } from '@commercetools/platform-sdk';
1
+ import { Customer, CustomerChangeEmailAction, CustomerDraft, ReferenceTypeId } from '@commercetools/platform-sdk';
2
+ import { Writable } from 'types';
2
3
  import { AbstractResourceRepository } from './abstract';
3
4
  export declare class CustomerRepository extends AbstractResourceRepository {
4
5
  getTypeId(): ReferenceTypeId;
5
6
  create(projectKey: string, draft: CustomerDraft): Customer;
6
7
  getMe(projectKey: string): Customer | undefined;
8
+ actions: {
9
+ changeEmail: (_projectKey: string, resource: Writable<Customer>, { email }: CustomerChangeEmailAction) => void;
10
+ };
7
11
  }
@@ -1,4 +1,4 @@
1
- import { Payment, PaymentAddTransactionAction, PaymentDraft, PaymentSetCustomFieldAction, PaymentSetCustomTypeAction, ReferenceTypeId, TransactionDraft } from '@commercetools/platform-sdk';
1
+ import { Payment, PaymentAddTransactionAction, PaymentChangeTransactionStateAction, PaymentDraft, PaymentSetCustomFieldAction, PaymentSetCustomTypeAction, PaymentTransitionStateAction, ReferenceTypeId, TransactionDraft } from '@commercetools/platform-sdk';
2
2
  import { AbstractResourceRepository } from './abstract';
3
3
  import { Writable } from '../types';
4
4
  export declare class PaymentRepository extends AbstractResourceRepository {
@@ -17,5 +17,7 @@ export declare class PaymentRepository extends AbstractResourceRepository {
17
17
  setCustomField: (projectKey: string, resource: Payment, { name, value }: PaymentSetCustomFieldAction) => void;
18
18
  setCustomType: (projectKey: string, resource: Writable<Payment>, { type, fields }: PaymentSetCustomTypeAction) => void;
19
19
  addTransaction: (projectKey: string, resource: Writable<Payment>, { transaction }: PaymentAddTransactionAction) => void;
20
+ changeTransactionState: (_projectKey: string, resource: Writable<Payment>, { transactionId, state }: PaymentChangeTransactionStateAction) => void;
21
+ transitionState: (projectKey: string, resource: Writable<Payment>, { state }: PaymentTransitionStateAction) => void;
20
22
  };
21
23
  }
@@ -5,5 +5,6 @@ export declare class StoreRepository extends AbstractResourceRepository {
5
5
  getTypeId(): ReferenceTypeId;
6
6
  create(projectKey: string, draft: StoreDraft): Store;
7
7
  private transformChannels;
8
+ getWithKey(projectKey: string, key: string): Store | undefined;
8
9
  actions: Partial<Record<StoreUpdateAction['action'], (projectKey: string, resource: Writable<Store>, action: any) => void>>;
9
10
  }
@@ -6,4 +6,5 @@ export declare class CustomerService extends AbstractService {
6
6
  repository: CustomerRepository;
7
7
  constructor(parent: Router, storage: AbstractStorage);
8
8
  getBasePath(): string;
9
+ extraRoutes(parent: Router): void;
9
10
  }
@@ -9,4 +9,5 @@ export declare class MyCustomerService extends AbstractService {
9
9
  registerRoutes(parent: Router): void;
10
10
  getMe(request: Request, response: Response): Response<any, Record<string, any>>;
11
11
  signUp(request: Request, response: Response): Response<any, Record<string, any>>;
12
+ signIn(request: Request, response: Response): Response<any, Record<string, any>>;
12
13
  }
@@ -1,9 +1,11 @@
1
1
  import AbstractService from './abstract';
2
- import { Router } from 'express';
2
+ import { Router, Request, Response } from 'express';
3
3
  import { StoreRepository } from '../repositories/store';
4
4
  import { AbstractStorage } from '../storage';
5
5
  export declare class StoreService extends AbstractService {
6
6
  repository: StoreRepository;
7
7
  constructor(parent: Router, storage: AbstractStorage);
8
8
  getBasePath(): string;
9
+ extraRoutes(router: Router): void;
10
+ getWithKey(request: Request, response: Response): Response<any, Record<string, any>>;
9
11
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.5.18",
2
+ "version": "0.5.21",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
package/src/.env ADDED
File without changes
package/src/ctMock.ts CHANGED
@@ -37,7 +37,7 @@ import { SubscriptionService } from './services/subscription'
37
37
  import { TaxCategoryService } from './services/tax-category'
38
38
  import { TypeService } from './services/type'
39
39
  import { ZoneService } from './services/zone'
40
- import { MyCustomerService } from 'services/my-customer'
40
+ import { MyCustomerService } from './services/my-customer'
41
41
 
42
42
  export type CommercetoolsMockOptions = {
43
43
  validateCredentials: boolean
@@ -1,5 +1,3 @@
1
- import { json } from 'express'
2
-
3
1
  export const maskSecretValue = <T>(resource: T, path: string): T => {
4
2
  const parts = path.split('.')
5
3
  const clone = JSON.parse(JSON.stringify(resource))
@@ -10,7 +8,7 @@ export const maskSecretValue = <T>(resource: T, path: string): T => {
10
8
  const part = parts[i]
11
9
  val = val[part]
12
10
 
13
- if (val == undefined) {
11
+ if (val === undefined) {
14
12
  return resource
15
13
  }
16
14
  }
@@ -30,6 +30,7 @@ export class CategoryRepository extends AbstractResourceRepository {
30
30
  name: draft.name,
31
31
  slug: draft.slug,
32
32
  orderHint: draft.orderHint || '',
33
+ externalId: draft.externalId || '',
33
34
  parent: draft.parent
34
35
  ? { typeId: 'category', id: draft.parent.id! }
35
36
  : undefined,
@@ -58,10 +59,10 @@ export class CategoryRepository extends AbstractResourceRepository {
58
59
  { assetId, assetKey, name }: CategoryChangeAssetNameAction
59
60
  ) => {
60
61
  resource.assets?.forEach(asset => {
61
- if (assetId && assetId == asset.id) {
62
+ if (assetId && assetId === asset.id) {
62
63
  asset.name = name
63
64
  }
64
- if (assetKey && assetKey == asset.key) {
65
+ if (assetKey && assetKey === asset.key) {
65
66
  asset.name = name
66
67
  }
67
68
  })
@@ -86,10 +87,10 @@ export class CategoryRepository extends AbstractResourceRepository {
86
87
  { assetId, assetKey, description }: CategorySetAssetDescriptionAction
87
88
  ) => {
88
89
  resource.assets?.forEach(asset => {
89
- if (assetId && assetId == asset.id) {
90
+ if (assetId && assetId === asset.id) {
90
91
  asset.description = description
91
92
  }
92
- if (assetKey && assetKey == asset.key) {
93
+ if (assetKey && assetKey === asset.key) {
93
94
  asset.description = description
94
95
  }
95
96
  })
@@ -100,10 +101,10 @@ export class CategoryRepository extends AbstractResourceRepository {
100
101
  { assetId, assetKey, sources }: CategorySetAssetSourcesAction
101
102
  ) => {
102
103
  resource.assets?.forEach(asset => {
103
- if (assetId && assetId == asset.id) {
104
+ if (assetId && assetId === asset.id) {
104
105
  asset.sources = sources
105
106
  }
106
- if (assetKey && assetKey == asset.key) {
107
+ if (assetKey && assetKey === asset.key) {
107
108
  asset.sources = sources
108
109
  }
109
110
  })
@@ -1,8 +1,10 @@
1
1
  import {
2
2
  Customer,
3
+ CustomerChangeEmailAction,
3
4
  CustomerDraft,
4
5
  ReferenceTypeId,
5
6
  } from '@commercetools/platform-sdk'
7
+ import { Writable } from 'types'
6
8
  import { getBaseResourceProperties } from '../helpers'
7
9
  import { AbstractResourceRepository } from './abstract'
8
10
 
@@ -10,6 +12,7 @@ export class CustomerRepository extends AbstractResourceRepository {
10
12
  getTypeId(): ReferenceTypeId {
11
13
  return 'customer'
12
14
  }
15
+
13
16
  create(projectKey: string, draft: CustomerDraft): Customer {
14
17
  const resource: Customer = {
15
18
  ...getBaseResourceProperties(),
@@ -21,6 +24,7 @@ export class CustomerRepository extends AbstractResourceRepository {
21
24
  this.save(projectKey, resource)
22
25
  return resource
23
26
  }
27
+
24
28
  getMe(projectKey: string): Customer | undefined {
25
29
  const results = this._storage.query(projectKey, this.getTypeId(), {}) // grab the first customer you can find
26
30
  if (results.count > 0) {
@@ -29,4 +33,14 @@ export class CustomerRepository extends AbstractResourceRepository {
29
33
 
30
34
  return
31
35
  }
36
+
37
+ actions = {
38
+ changeEmail: (
39
+ _projectKey: string,
40
+ resource: Writable<Customer>,
41
+ { email }: CustomerChangeEmailAction
42
+ ) => {
43
+ resource.email = email
44
+ },
45
+ }
32
46
  }
@@ -1,11 +1,15 @@
1
1
  import {
2
2
  Payment,
3
3
  PaymentAddTransactionAction,
4
+ PaymentChangeTransactionStateAction,
4
5
  PaymentDraft,
5
6
  PaymentSetCustomFieldAction,
6
7
  PaymentSetCustomTypeAction,
8
+ PaymentTransitionStateAction,
7
9
  ReferenceTypeId,
10
+ State,
8
11
  StateReference,
12
+ Transaction,
9
13
  TransactionDraft,
10
14
  } from '@commercetools/platform-sdk'
11
15
  import { AbstractResourceRepository } from './abstract'
@@ -111,10 +115,43 @@ export class PaymentRepository extends AbstractResourceRepository {
111
115
  this.transactionFromTransactionDraft(transaction, projectKey),
112
116
  ]
113
117
  },
118
+ changeTransactionState: (
119
+ _projectKey: string,
120
+ resource: Writable<Payment>,
121
+ { transactionId, state }: PaymentChangeTransactionStateAction
122
+ ) => {
123
+ const index = resource.transactions.findIndex(
124
+ (e: Transaction) => e.id === transactionId
125
+ )
126
+ const updatedTransaction: Transaction = {
127
+ ...resource.transactions[index],
128
+ state,
129
+ }
130
+ resource.transactions[index] = updatedTransaction
131
+ },
132
+ transitionState: (
133
+ projectKey: string,
134
+ resource: Writable<Payment>,
135
+ { state }: PaymentTransitionStateAction
136
+ ) => {
137
+ const stateObj = this._storage.getByResourceIdentifier(
138
+ projectKey,
139
+ state
140
+ ) as State | null
141
+
142
+ if (!stateObj) {
143
+ throw new Error(`State ${state} not found`)
144
+ }
145
+
146
+ resource.paymentStatus.state = {
147
+ typeId: 'state',
148
+ id: stateObj.id,
149
+ obj: stateObj,
150
+ }
151
+ },
114
152
  // addInterfaceInteraction: () => {},
115
153
  // changeAmountPlanned: () => {},
116
154
  // changeTransactionInteractionId: () => {},
117
- // changeTransactionState: () => {},
118
155
  // changeTransactionTimestamp: () => {},
119
156
  // setAmountPaid: () => {},
120
157
  // setAmountRefunded: () => {},
@@ -129,6 +166,5 @@ export class PaymentRepository extends AbstractResourceRepository {
129
166
  // setMethodInfoName: () => {},
130
167
  // setStatusInterfaceCode: () => {},
131
168
  // setStatusInterfaceText: () => {},
132
- // transitionState: () => {},
133
169
  }
134
170
  }
@@ -77,7 +77,7 @@ export class ProductTypeRepository extends AbstractResourceRepository {
77
77
  switch (type.name) {
78
78
  case 'lenum':
79
79
  type.values.forEach(v => {
80
- if (v.key == newValue.key) {
80
+ if (v.key === newValue.key) {
81
81
  v.label = newValue.label
82
82
  }
83
83
  })
@@ -89,7 +89,7 @@ export class ProductTypeRepository extends AbstractResourceRepository {
89
89
  }
90
90
 
91
91
  resource.attributes?.forEach(value => {
92
- if (value.name == attributeName) {
92
+ if (value.name === attributeName) {
93
93
  updateAttributeType(value.type)
94
94
  }
95
95
  })
@@ -100,7 +100,7 @@ export class ProductTypeRepository extends AbstractResourceRepository {
100
100
  { attributeName, label }: ProductTypeChangeLabelAction
101
101
  ) => {
102
102
  resource.attributes?.forEach(value => {
103
- if (value.name == attributeName) {
103
+ if (value.name === attributeName) {
104
104
  value.label = label
105
105
  }
106
106
  })
@@ -22,7 +22,6 @@ import { maskSecretValue } from '../lib/masking'
22
22
 
23
23
  export class ProjectRepository extends AbstractRepository {
24
24
  get(projectKey: string): Project | null {
25
- const data = this._storage.getProject(projectKey)
26
25
  const resource = this._storage.getProject(projectKey)
27
26
  const masked = maskSecretValue<Project>(
28
27
  resource,
@@ -26,7 +26,6 @@ import {
26
26
  import { getBaseResourceProperties } from '../helpers'
27
27
  import { AbstractResourceRepository } from './abstract'
28
28
  import { Writable } from 'types'
29
- import { _ } from 'ajv'
30
29
  import deepEqual from 'deep-equal'
31
30
 
32
31
  export class ShippingMethodRepository extends AbstractResourceRepository {
@@ -84,14 +83,14 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
84
83
  >
85
84
  > = {
86
85
  addShippingRate: (
87
- projectKey: string,
86
+ _projectKey: string,
88
87
  resource: Writable<ShippingMethod>,
89
88
  { shippingRate, zone }: ShippingMethodAddShippingRateAction
90
89
  ) => {
91
90
  const rate = this._transformShippingRate(shippingRate)
92
91
 
93
92
  resource.zoneRates.forEach(zoneRate => {
94
- if (zoneRate.zone.id == zone.id) {
93
+ if (zoneRate.zone.id === zone.id) {
95
94
  zoneRate.shippingRates.push(rate)
96
95
  return
97
96
  }
@@ -105,14 +104,14 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
105
104
  })
106
105
  },
107
106
  removeShippingRate: (
108
- projectKey: string,
107
+ _projectKey: string,
109
108
  resource: Writable<ShippingMethod>,
110
109
  { shippingRate, zone }: ShippingMethodAddShippingRateAction
111
110
  ) => {
112
111
  const rate = this._transformShippingRate(shippingRate)
113
112
 
114
113
  resource.zoneRates.forEach(zoneRate => {
115
- if (zoneRate.zone.id == zone.id) {
114
+ if (zoneRate.zone.id === zone.id) {
116
115
  zoneRate.shippingRates = zoneRate.shippingRates.filter(otherRate => {
117
116
  return !deepEqual(rate, otherRate)
118
117
  })
@@ -140,7 +139,7 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
140
139
  })
141
140
  },
142
141
  removeZone: (
143
- projectKey: string,
142
+ _projectKey: string,
144
143
  resource: Writable<ShippingMethod>,
145
144
  { zone }: ShippingMethodRemoveZoneAction
146
145
  ) => {
@@ -149,42 +148,42 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
149
148
  })
150
149
  },
151
150
  setKey: (
152
- projectKey: string,
151
+ _projectKey: string,
153
152
  resource: Writable<ShippingMethod>,
154
153
  { key }: ShippingMethodSetKeyAction
155
154
  ) => {
156
155
  resource.key = key
157
156
  },
158
157
  setDescription: (
159
- projectKey: string,
158
+ _projectKey: string,
160
159
  resource: Writable<ShippingMethod>,
161
160
  { description }: ShippingMethodSetDescriptionAction
162
161
  ) => {
163
162
  resource.description = description
164
163
  },
165
164
  setLocalizedDescription: (
166
- projectKey: string,
165
+ _projectKey: string,
167
166
  resource: Writable<ShippingMethod>,
168
167
  { localizedDescription }: ShippingMethodSetLocalizedDescriptionAction
169
168
  ) => {
170
169
  resource.localizedDescription = localizedDescription
171
170
  },
172
171
  setPredicate: (
173
- projectKey: string,
172
+ _projectKey: string,
174
173
  resource: Writable<ShippingMethod>,
175
174
  { predicate }: ShippingMethodSetPredicateAction
176
175
  ) => {
177
176
  resource.predicate = predicate
178
177
  },
179
178
  changeIsDefault: (
180
- projectKey: string,
179
+ _projectKey: string,
181
180
  resource: Writable<ShippingMethod>,
182
181
  { isDefault }: ShippingMethodChangeIsDefaultAction
183
182
  ) => {
184
183
  resource.isDefault = isDefault
185
184
  },
186
185
  changeName: (
187
- projectKey: string,
186
+ _projectKey: string,
188
187
  resource: Writable<ShippingMethod>,
189
188
  { name }: ShippingMethodChangeNameAction
190
189
  ) => {
@@ -50,6 +50,21 @@ export class StoreRepository extends AbstractResourceRepository {
50
50
  )
51
51
  }
52
52
 
53
+ getWithKey(projectKey: string, key: string): Store | undefined {
54
+ const result = this._storage.query(projectKey, this.getTypeId(), {
55
+ where: [`key="${key}"`],
56
+ })
57
+ if (result.count === 1) {
58
+ return result.results[0] as Store
59
+ }
60
+
61
+ if (result.count > 1) {
62
+ throw new Error('Duplicate store key')
63
+ }
64
+
65
+ return
66
+ }
67
+
53
68
  actions: Partial<
54
69
  Record<
55
70
  StoreUpdateAction['action'],
@@ -15,10 +15,10 @@ export class SubscriptionRepository extends AbstractResourceRepository {
15
15
  create(projectKey: string, draft: SubscriptionDraft): Subscription {
16
16
  // TODO: We could actually test this here by using the aws sdk. For now
17
17
  // hardcode a failed check when account id is 0000000000
18
- if (draft.destination.type == 'SQS') {
18
+ if (draft.destination.type === 'SQS') {
19
19
  const queueURL = new URL(draft.destination.queueUrl)
20
20
  const accountId = queueURL.pathname.split('/')[1]
21
- if (accountId == '0000000000') {
21
+ if (accountId === '0000000000') {
22
22
  const dest = draft.destination
23
23
  throw new CommercetoolsError<InvalidInputError>(
24
24
  {
@@ -94,7 +94,7 @@ export class TaxCategoryRepository extends AbstractResourceRepository {
94
94
  const taxRateObj = this.taxRateFromTaxRateDraft(taxRate)
95
95
  for (let i = 0; i < resource.rates.length; i++) {
96
96
  const rate = resource.rates[i]
97
- if (rate.id == taxRateId) {
97
+ if (rate.id === taxRateId) {
98
98
  resource.rates[i] = taxRateObj
99
99
  }
100
100
  }
@@ -104,13 +104,13 @@ export class TypeRepository extends AbstractResourceRepository {
104
104
  { fieldName, value }: TypeAddEnumValueAction
105
105
  ) => {
106
106
  resource.fieldDefinitions.forEach(field => {
107
- if (field.name == fieldName) {
107
+ if (field.name === fieldName) {
108
108
  // TODO, should be done better i suppose
109
- if (field.type.name == 'Enum') {
109
+ if (field.type.name === 'Enum') {
110
110
  field.type.values.push(value)
111
111
  } else if (
112
- field.type.name == 'Set' &&
113
- field.type.elementType.name == 'Enum'
112
+ field.type.name === 'Set' &&
113
+ field.type.elementType.name === 'Enum'
114
114
  ) {
115
115
  field.type.elementType.values.push(value)
116
116
  } else {
@@ -125,20 +125,20 @@ export class TypeRepository extends AbstractResourceRepository {
125
125
  { fieldName, value }: TypeChangeEnumValueLabelAction
126
126
  ) => {
127
127
  resource.fieldDefinitions.forEach(field => {
128
- if (field.name == fieldName) {
128
+ if (field.name === fieldName) {
129
129
  // TODO, should be done better i suppose
130
- if (field.type.name == 'Enum') {
130
+ if (field.type.name === 'Enum') {
131
131
  field.type.values.forEach(v => {
132
- if (v.key == value.key) {
132
+ if (v.key === value.key) {
133
133
  v.label = value.label
134
134
  }
135
135
  })
136
136
  } else if (
137
- field.type.name == 'Set' &&
138
- field.type.elementType.name == 'Enum'
137
+ field.type.name === 'Set' &&
138
+ field.type.elementType.name === 'Enum'
139
139
  ) {
140
140
  field.type.elementType.values.forEach(v => {
141
- if (v.key == value.key) {
141
+ if (v.key === value.key) {
142
142
  v.label = value.label
143
143
  }
144
144
  })
@@ -49,7 +49,9 @@ export class ZoneRepository extends AbstractResourceRepository {
49
49
  { location }: ZoneRemoveLocationAction
50
50
  ) => {
51
51
  resource.locations = resource.locations.filter(loc => {
52
- return !(loc.country == location.country && loc.state == location.state)
52
+ return !(
53
+ loc.country === location.country && loc.state === location.state
54
+ )
53
55
  })
54
56
  },
55
57
  changeName: (
@@ -2,6 +2,8 @@ import AbstractService from './abstract'
2
2
  import { Router } from 'express'
3
3
  import { CustomerRepository } from '../repositories/customer'
4
4
  import { AbstractStorage } from '../storage'
5
+ import { getBaseResourceProperties } from '../helpers'
6
+ import { v4 as uuidv4 } from 'uuid'
5
7
 
6
8
  export class CustomerService extends AbstractService {
7
9
  public repository: CustomerRepository
@@ -14,4 +16,23 @@ export class CustomerService extends AbstractService {
14
16
  getBasePath() {
15
17
  return 'customers'
16
18
  }
19
+
20
+ extraRoutes(parent: Router) {
21
+ parent.post('/password-token', (request, response) => {
22
+ const customer = this.repository.query(request.params.projectKey, {
23
+ where: [`email="${request.body.email}"`],
24
+ })
25
+ const ttlMinutes: number = request.params.ttlMinutes
26
+ ? +request.params.ttlMinutes
27
+ : 34560
28
+ const { version, ...rest } = getBaseResourceProperties()
29
+
30
+ return response.status(200).send({
31
+ ...rest,
32
+ customerId: customer.results[0].id,
33
+ expiresAt: new Date(Date.now() + ttlMinutes * 60).toISOString(),
34
+ value: uuidv4(),
35
+ })
36
+ })
37
+ }
17
38
  }
@@ -26,6 +26,8 @@ export class MyCustomerService extends AbstractService {
26
26
 
27
27
  router.post('/signup', this.signUp.bind(this))
28
28
 
29
+ router.post('/login', this.signIn.bind(this))
30
+
29
31
  parent.use(`/${basePath}`, router)
30
32
  }
31
33
 
@@ -43,4 +45,27 @@ export class MyCustomerService extends AbstractService {
43
45
  const result = this._expandWithId(request, resource.id)
44
46
  return response.status(this.createStatusCode).send({ customer: result })
45
47
  }
48
+
49
+ signIn(request: Request, response: Response) {
50
+ const { email, password } = request.body
51
+ const encodedPassword = Buffer.from(password).toString('base64')
52
+
53
+ const result = this.repository.query(request.params.projectKey, {
54
+ where: [`email = "${email}"`, `password = "${encodedPassword}"`],
55
+ })
56
+
57
+ if (result.count === 0) {
58
+ return response.status(400).send({
59
+ message: 'Account with the given credentials not found.',
60
+ errors: [
61
+ {
62
+ code: 'InvalidCredentials',
63
+ message: 'Account with the given credentials not found.',
64
+ },
65
+ ],
66
+ })
67
+ }
68
+
69
+ return response.status(200).send({ customer: result.results[0] })
70
+ }
46
71
  }
@@ -1,8 +1,4 @@
1
- import {
2
- CentPrecisionMoney,
3
- Product,
4
- ProductDraft,
5
- } from '@commercetools/platform-sdk'
1
+ import { Product, ProductDraft } from '@commercetools/platform-sdk'
6
2
  import supertest from 'supertest'
7
3
  import { CommercetoolsMock } from '../index'
8
4
  import assert from 'assert'
@@ -31,7 +31,7 @@ export class ProjectService {
31
31
  return response.status(404).send({})
32
32
  }
33
33
 
34
- const updatedResource = this.repository.processUpdateActions(
34
+ this.repository.processUpdateActions(
35
35
  request.params.projectKey,
36
36
  project,
37
37
  updateRequest.actions
@@ -1,7 +1,7 @@
1
1
  import { ShippingMethodRepository } from '../repositories/shipping-method'
2
2
  import AbstractService from './abstract'
3
3
  import { AbstractStorage } from '../storage'
4
- import { Request, Response, Router } from 'express'
4
+ import { Router } from 'express'
5
5
 
6
6
  export class ShippingMethodService extends AbstractService {
7
7
  public repository: ShippingMethodRepository
@@ -1,5 +1,5 @@
1
1
  import AbstractService from './abstract'
2
- import { Router } from 'express'
2
+ import { Router, Request, Response } from 'express'
3
3
  import { StoreRepository } from '../repositories/store'
4
4
  import { AbstractStorage } from '../storage'
5
5
 
@@ -14,4 +14,19 @@ export class StoreService extends AbstractService {
14
14
  getBasePath() {
15
15
  return 'stores'
16
16
  }
17
+
18
+ extraRoutes(router: Router) {
19
+ router.get('/key=:key', this.getWithKey.bind(this))
20
+ }
21
+
22
+ getWithKey(request: Request, response: Response) {
23
+ const resource = this.repository.getWithKey(
24
+ request.params.projectKey,
25
+ request.params.key
26
+ )
27
+ if (resource) {
28
+ return response.status(200).send(resource)
29
+ }
30
+ return response.status(404).send('Not found')
31
+ }
17
32
  }