@labdigital/commercetools-mock 2.12.2 → 2.13.0
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/index.cjs +46 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/repositories/customer.ts +16 -0
- package/src/repositories/order.ts +38 -0
- package/src/services/my-customer.test.ts +26 -0
- package/src/services/my-customer.ts +9 -0
- package/src/services/order.test.ts +34 -0
package/package.json
CHANGED
|
@@ -73,6 +73,22 @@ export class CustomerRepository extends AbstractResourceRepository<'customer'> {
|
|
|
73
73
|
return
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
deleteMe(context: RepositoryContext): Customer | undefined {
|
|
77
|
+
// grab the first customer you can find for now. In the future we should
|
|
78
|
+
// use the customer id from the scope of the token
|
|
79
|
+
const results = this._storage.query(
|
|
80
|
+
context.projectKey,
|
|
81
|
+
this.getTypeId(),
|
|
82
|
+
{}
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
if (results.count > 0) {
|
|
86
|
+
return this.delete(context, results.results[0].id) as Customer
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
|
|
76
92
|
actions = {
|
|
77
93
|
changeEmail: (
|
|
78
94
|
_context: RepositoryContext,
|
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
OrderChangePaymentStateAction,
|
|
16
16
|
OrderFromCartDraft,
|
|
17
17
|
OrderImportDraft,
|
|
18
|
+
OrderUpdateSyncInfoAction,
|
|
18
19
|
OrderSetBillingAddressAction,
|
|
19
20
|
OrderSetCustomerEmailAction,
|
|
20
21
|
OrderSetCustomFieldAction,
|
|
@@ -30,6 +31,7 @@ import type {
|
|
|
30
31
|
ReturnInfo,
|
|
31
32
|
State,
|
|
32
33
|
Store,
|
|
34
|
+
SyncInfo,
|
|
33
35
|
} from '@commercetools/platform-sdk'
|
|
34
36
|
import assert from 'assert'
|
|
35
37
|
import { CommercetoolsError } from '../exceptions.js'
|
|
@@ -301,6 +303,7 @@ export class OrderRepository extends AbstractResourceRepository<'order'> {
|
|
|
301
303
|
id: payment.id!,
|
|
302
304
|
})
|
|
303
305
|
},
|
|
306
|
+
|
|
304
307
|
addReturnInfo: (
|
|
305
308
|
context: RepositoryContext,
|
|
306
309
|
resource: Writable<Order>,
|
|
@@ -472,5 +475,40 @@ export class OrderRepository extends AbstractResourceRepository<'order'> {
|
|
|
472
475
|
key: storeReference.key,
|
|
473
476
|
}
|
|
474
477
|
},
|
|
478
|
+
updateSyncInfo: (
|
|
479
|
+
context: RepositoryContext,
|
|
480
|
+
resource: Writable<Order>,
|
|
481
|
+
{ channel, externalId, syncedAt }: OrderUpdateSyncInfoAction
|
|
482
|
+
) => {
|
|
483
|
+
if (!channel) return
|
|
484
|
+
const resolvedType = this._storage.getByResourceIdentifier(
|
|
485
|
+
context.projectKey,
|
|
486
|
+
channel
|
|
487
|
+
)
|
|
488
|
+
if (!resolvedType) {
|
|
489
|
+
throw new Error(`Channel ${channel} not found`)
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
const syncData: SyncInfo = {
|
|
493
|
+
channel: {
|
|
494
|
+
typeId: 'channel',
|
|
495
|
+
id: resolvedType.id,
|
|
496
|
+
},
|
|
497
|
+
externalId,
|
|
498
|
+
syncedAt: syncedAt ?? new Date().toISOString(),
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
if (!resource.syncInfo?.length) {
|
|
502
|
+
resource.syncInfo = [syncData]
|
|
503
|
+
} else {
|
|
504
|
+
const lastSyncInfo = resource.syncInfo[resource.syncInfo.length - 1]
|
|
505
|
+
if (
|
|
506
|
+
lastSyncInfo.channel.id !== syncData.channel.id ||
|
|
507
|
+
lastSyncInfo.externalId !== syncData.externalId
|
|
508
|
+
) {
|
|
509
|
+
resource.syncInfo.push(syncData)
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
},
|
|
475
513
|
}
|
|
476
514
|
}
|
|
@@ -94,6 +94,32 @@ describe('/me', () => {
|
|
|
94
94
|
})
|
|
95
95
|
})
|
|
96
96
|
|
|
97
|
+
test('Delete me', async () => {
|
|
98
|
+
const response = await supertest(ctMock.app).delete('/dummy/me')
|
|
99
|
+
|
|
100
|
+
expect(response.status).toBe(200)
|
|
101
|
+
expect(response.body).toEqual({
|
|
102
|
+
id: '123',
|
|
103
|
+
createdAt: '2021-03-18T14:00:00.000Z',
|
|
104
|
+
version: 2,
|
|
105
|
+
lastModifiedAt: '2021-03-18T14:00:00.000Z',
|
|
106
|
+
email: 'foo@example.org',
|
|
107
|
+
addresses: [],
|
|
108
|
+
isEmailVerified: true,
|
|
109
|
+
authenticationMode: 'password',
|
|
110
|
+
custom: {
|
|
111
|
+
fields: {},
|
|
112
|
+
type: {
|
|
113
|
+
id: '',
|
|
114
|
+
typeId: 'type',
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
const newResponse = await supertest(ctMock.app).get('/dummy/me')
|
|
120
|
+
expect(newResponse.status).toBe(404)
|
|
121
|
+
})
|
|
122
|
+
|
|
97
123
|
test('setCustomField', async () => {
|
|
98
124
|
const response = await supertest(ctMock.app)
|
|
99
125
|
.post(`/dummy/me`)
|
|
@@ -26,6 +26,7 @@ export class MyCustomerService extends AbstractService {
|
|
|
26
26
|
|
|
27
27
|
router.get('', this.getMe.bind(this))
|
|
28
28
|
router.post('', this.updateMe.bind(this))
|
|
29
|
+
router.delete('', this.deleteMe.bind(this))
|
|
29
30
|
|
|
30
31
|
router.post('/signup', this.signUp.bind(this))
|
|
31
32
|
|
|
@@ -59,6 +60,14 @@ export class MyCustomerService extends AbstractService {
|
|
|
59
60
|
const result = this._expandWithId(request, updatedResource.id)
|
|
60
61
|
return response.status(200).send(result)
|
|
61
62
|
}
|
|
63
|
+
deleteMe(request: Request, response: Response) {
|
|
64
|
+
const resource = this.repository.deleteMe(getRepositoryContext(request))
|
|
65
|
+
if (!resource) {
|
|
66
|
+
return response.status(404).send('Not found')
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return response.status(200).send(resource)
|
|
70
|
+
}
|
|
62
71
|
|
|
63
72
|
signUp(request: Request, response: Response) {
|
|
64
73
|
const draft = request.body
|
|
@@ -366,6 +366,40 @@ describe('Order Update Actions', () => {
|
|
|
366
366
|
expect(response.body.orderState).toBe('Cancelled')
|
|
367
367
|
expect(response.body.paymentState).toBe('Failed')
|
|
368
368
|
})
|
|
369
|
+
|
|
370
|
+
test('updateSyncInfo', async () => {
|
|
371
|
+
assert(order, 'order not created')
|
|
372
|
+
|
|
373
|
+
const channelResponse = await supertest(ctMock.app)
|
|
374
|
+
.post('/dummy/channels')
|
|
375
|
+
.send({
|
|
376
|
+
key: 'order-sync',
|
|
377
|
+
roles: ['OrderImport', 'OrderExport'],
|
|
378
|
+
})
|
|
379
|
+
expect(channelResponse.status).toBe(201)
|
|
380
|
+
const channel = channelResponse.body
|
|
381
|
+
|
|
382
|
+
const response = await supertest(ctMock.app)
|
|
383
|
+
.post(`/dummy/orders/${order.id}`)
|
|
384
|
+
.send({
|
|
385
|
+
version: 1,
|
|
386
|
+
actions: [
|
|
387
|
+
{
|
|
388
|
+
action: 'updateSyncInfo',
|
|
389
|
+
channel: { typeId: 'channel', key: 'order-sync' },
|
|
390
|
+
externalId: '1234',
|
|
391
|
+
},
|
|
392
|
+
],
|
|
393
|
+
})
|
|
394
|
+
expect(response.status).toBe(200)
|
|
395
|
+
expect(response.body.version).toBe(2)
|
|
396
|
+
expect(response.body.syncInfo).toMatchObject([
|
|
397
|
+
{
|
|
398
|
+
channel: { typeId: 'channel', id: channel.id },
|
|
399
|
+
externalId: '1234',
|
|
400
|
+
},
|
|
401
|
+
])
|
|
402
|
+
})
|
|
369
403
|
})
|
|
370
404
|
|
|
371
405
|
describe('Order Import', () => {
|