@labdigital/commercetools-mock 0.6.0 → 0.6.3
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 +423 -352
- 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 +423 -352
- package/dist/commercetools-mock.esm.js.map +1 -1
- package/dist/repositories/abstract.d.ts +13 -9
- package/dist/repositories/cart-discount.d.ts +3 -3
- package/dist/repositories/cart.d.ts +13 -13
- package/dist/repositories/category.d.ts +11 -11
- package/dist/repositories/channel.d.ts +2 -2
- package/dist/repositories/custom-object.d.ts +3 -3
- package/dist/repositories/customer-group.d.ts +4 -4
- package/dist/repositories/customer.d.ts +4 -4
- package/dist/repositories/discount-code.d.ts +3 -3
- package/dist/repositories/extension.d.ts +3 -3
- package/dist/repositories/helpers.d.ts +3 -0
- package/dist/repositories/inventory-entry.d.ts +7 -7
- package/dist/repositories/my-order.d.ts +6 -0
- package/dist/repositories/order.d.ts +18 -17
- package/dist/repositories/payment.d.ts +8 -8
- package/dist/repositories/product-projection.d.ts +3 -3
- package/dist/repositories/product-type.d.ts +5 -5
- package/dist/repositories/product.d.ts +4 -4
- package/dist/repositories/project.d.ts +4 -4
- package/dist/repositories/shipping-method.d.ts +3 -3
- package/dist/repositories/shopping-list.d.ts +2 -2
- package/dist/repositories/state.d.ts +3 -3
- package/dist/repositories/store.d.ts +4 -4
- package/dist/repositories/subscription.d.ts +2 -2
- package/dist/repositories/tax-category.d.ts +4 -4
- package/dist/repositories/type.d.ts +3 -3
- package/dist/repositories/zone.d.ts +3 -3
- package/dist/services/my-order.d.ts +2 -2
- package/package.json +1 -1
- package/src/ctMock.ts +6 -0
- package/src/repositories/abstract.ts +37 -17
- package/src/repositories/cart-discount.ts +11 -11
- package/src/repositories/cart.ts +88 -36
- package/src/repositories/category.ts +17 -13
- package/src/repositories/channel.ts +3 -3
- package/src/repositories/custom-object.ts +16 -8
- package/src/repositories/customer-group.ts +5 -5
- package/src/repositories/customer.ts +10 -6
- package/src/repositories/discount-code.ts +14 -14
- package/src/repositories/extension.ts +12 -8
- package/src/repositories/helpers.ts +9 -0
- package/src/repositories/inventory-entry.ts +17 -10
- package/src/repositories/my-order.ts +19 -0
- package/src/repositories/order.test.ts +79 -3
- package/src/repositories/order.ts +77 -37
- package/src/repositories/payment.ts +21 -17
- package/src/repositories/product-projection.ts +5 -5
- package/src/repositories/product-type.ts +14 -10
- package/src/repositories/product.ts +5 -5
- package/src/repositories/project.ts +21 -17
- package/src/repositories/shipping-method.ts +27 -20
- package/src/repositories/shopping-list.ts +10 -6
- package/src/repositories/state.ts +13 -9
- package/src/repositories/store.ts +18 -14
- package/src/repositories/subscription.ts +3 -3
- package/src/repositories/tax-category.ts +16 -12
- package/src/repositories/type.ts +15 -11
- package/src/repositories/zone.ts +13 -9
- package/src/services/abstract.ts +21 -10
- package/src/services/cart.test.ts +48 -8
- package/src/services/cart.ts +17 -11
- package/src/services/custom-object.ts +8 -4
- package/src/services/customer.ts +5 -2
- package/src/services/my-customer.ts +7 -3
- package/src/services/my-order.ts +3 -3
- package/src/services/order.ts +3 -2
- package/src/services/product-projection.ts +2 -1
- package/src/services/product-type.ts +2 -1
- package/src/services/project.ts +4 -3
- package/src/services/store.ts +2 -1
- package/src/services/tax-category.ts +2 -1
|
@@ -7,32 +7,32 @@ import {
|
|
|
7
7
|
} from '@commercetools/platform-sdk'
|
|
8
8
|
import { Writable } from 'types'
|
|
9
9
|
import { getBaseResourceProperties } from '../helpers'
|
|
10
|
-
import { AbstractResourceRepository } from './abstract'
|
|
10
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
11
11
|
|
|
12
12
|
export class CustomerGroupRepository extends AbstractResourceRepository {
|
|
13
13
|
getTypeId(): ReferenceTypeId {
|
|
14
14
|
return 'customer'
|
|
15
15
|
}
|
|
16
|
-
create(
|
|
16
|
+
create(context: RepositoryContext, draft: CustomerGroupDraft): CustomerGroup {
|
|
17
17
|
const resource: CustomerGroup = {
|
|
18
18
|
...getBaseResourceProperties(),
|
|
19
19
|
key: draft.key,
|
|
20
20
|
name: draft.groupName,
|
|
21
21
|
}
|
|
22
|
-
this.save(
|
|
22
|
+
this.save(context, resource)
|
|
23
23
|
return resource
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
actions = {
|
|
27
27
|
setKey: (
|
|
28
|
-
|
|
28
|
+
context: RepositoryContext,
|
|
29
29
|
resource: Writable<CustomerGroup>,
|
|
30
30
|
{ key }: CustomerGroupSetKeyAction
|
|
31
31
|
) => {
|
|
32
32
|
resource.key = key
|
|
33
33
|
},
|
|
34
34
|
changeName: (
|
|
35
|
-
|
|
35
|
+
context: RepositoryContext,
|
|
36
36
|
resource: Writable<CustomerGroup>,
|
|
37
37
|
{ name }: CustomerGroupChangeNameAction
|
|
38
38
|
) => {
|
|
@@ -6,14 +6,14 @@ import {
|
|
|
6
6
|
} from '@commercetools/platform-sdk'
|
|
7
7
|
import { Writable } from 'types'
|
|
8
8
|
import { getBaseResourceProperties } from '../helpers'
|
|
9
|
-
import { AbstractResourceRepository } from './abstract'
|
|
9
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
10
10
|
|
|
11
11
|
export class CustomerRepository extends AbstractResourceRepository {
|
|
12
12
|
getTypeId(): ReferenceTypeId {
|
|
13
13
|
return 'customer'
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
create(
|
|
16
|
+
create(context: RepositoryContext, draft: CustomerDraft): Customer {
|
|
17
17
|
const resource: Customer = {
|
|
18
18
|
...getBaseResourceProperties(),
|
|
19
19
|
email: draft.email,
|
|
@@ -23,12 +23,16 @@ export class CustomerRepository extends AbstractResourceRepository {
|
|
|
23
23
|
isEmailVerified: draft.isEmailVerified || false,
|
|
24
24
|
addresses: [],
|
|
25
25
|
}
|
|
26
|
-
this.save(
|
|
26
|
+
this.save(context, resource)
|
|
27
27
|
return resource
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
getMe(
|
|
31
|
-
const results = this._storage.query(
|
|
30
|
+
getMe(context: RepositoryContext): Customer | undefined {
|
|
31
|
+
const results = this._storage.query(
|
|
32
|
+
context.projectKey,
|
|
33
|
+
this.getTypeId(),
|
|
34
|
+
{}
|
|
35
|
+
) // grab the first customer you can find
|
|
32
36
|
if (results.count > 0) {
|
|
33
37
|
return results.results[0] as Customer
|
|
34
38
|
}
|
|
@@ -38,7 +42,7 @@ export class CustomerRepository extends AbstractResourceRepository {
|
|
|
38
42
|
|
|
39
43
|
actions = {
|
|
40
44
|
changeEmail: (
|
|
41
|
-
|
|
45
|
+
_context: RepositoryContext,
|
|
42
46
|
resource: Writable<Customer>,
|
|
43
47
|
{ email }: CustomerChangeEmailAction
|
|
44
48
|
) => {
|
|
@@ -17,14 +17,14 @@ import {
|
|
|
17
17
|
} from '@commercetools/platform-sdk'
|
|
18
18
|
import { Writable } from 'types'
|
|
19
19
|
import { getBaseResourceProperties } from '../helpers'
|
|
20
|
-
import { AbstractResourceRepository } from './abstract'
|
|
20
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
21
21
|
|
|
22
22
|
export class DiscountCodeRepository extends AbstractResourceRepository {
|
|
23
23
|
getTypeId(): ReferenceTypeId {
|
|
24
24
|
return 'cart-discount'
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
create(
|
|
27
|
+
create(context: RepositoryContext, draft: DiscountCodeDraft): DiscountCode {
|
|
28
28
|
const resource: DiscountCode = {
|
|
29
29
|
...getBaseResourceProperties(),
|
|
30
30
|
applicationVersion: 1,
|
|
@@ -46,7 +46,7 @@ export class DiscountCodeRepository extends AbstractResourceRepository {
|
|
|
46
46
|
maxApplications: draft.maxApplications,
|
|
47
47
|
maxApplicationsPerCustomer: draft.maxApplicationsPerCustomer,
|
|
48
48
|
}
|
|
49
|
-
this.save(
|
|
49
|
+
this.save(context, resource)
|
|
50
50
|
return resource
|
|
51
51
|
}
|
|
52
52
|
|
|
@@ -54,21 +54,21 @@ export class DiscountCodeRepository extends AbstractResourceRepository {
|
|
|
54
54
|
Record<
|
|
55
55
|
DiscountCodeUpdateAction['action'],
|
|
56
56
|
(
|
|
57
|
-
|
|
57
|
+
context: RepositoryContext,
|
|
58
58
|
resource: Writable<DiscountCode>,
|
|
59
59
|
action: any
|
|
60
60
|
) => void
|
|
61
61
|
>
|
|
62
62
|
> = {
|
|
63
63
|
changeIsActive: (
|
|
64
|
-
|
|
64
|
+
context: RepositoryContext,
|
|
65
65
|
resource: Writable<DiscountCode>,
|
|
66
66
|
{ isActive }: DiscountCodeChangeIsActiveAction
|
|
67
67
|
) => {
|
|
68
68
|
resource.isActive = isActive
|
|
69
69
|
},
|
|
70
70
|
changeCartDiscounts: (
|
|
71
|
-
|
|
71
|
+
context: RepositoryContext,
|
|
72
72
|
resource: Writable<DiscountCode>,
|
|
73
73
|
{ cartDiscounts }: DiscountCodeChangeCartDiscountsAction
|
|
74
74
|
) => {
|
|
@@ -80,35 +80,35 @@ export class DiscountCodeRepository extends AbstractResourceRepository {
|
|
|
80
80
|
)
|
|
81
81
|
},
|
|
82
82
|
setDescription: (
|
|
83
|
-
|
|
83
|
+
context: RepositoryContext,
|
|
84
84
|
resource: Writable<DiscountCode>,
|
|
85
85
|
{ description }: DiscountCodeSetDescriptionAction
|
|
86
86
|
) => {
|
|
87
87
|
resource.description = description
|
|
88
88
|
},
|
|
89
89
|
setCartPredicate: (
|
|
90
|
-
|
|
90
|
+
context: RepositoryContext,
|
|
91
91
|
resource: Writable<DiscountCode>,
|
|
92
92
|
{ cartPredicate }: DiscountCodeSetCartPredicateAction
|
|
93
93
|
) => {
|
|
94
94
|
resource.cartPredicate = cartPredicate
|
|
95
95
|
},
|
|
96
96
|
setName: (
|
|
97
|
-
|
|
97
|
+
context: RepositoryContext,
|
|
98
98
|
resource: Writable<DiscountCode>,
|
|
99
99
|
{ name }: DiscountCodeSetNameAction
|
|
100
100
|
) => {
|
|
101
101
|
resource.name = name
|
|
102
102
|
},
|
|
103
103
|
setMaxApplications: (
|
|
104
|
-
|
|
104
|
+
context: RepositoryContext,
|
|
105
105
|
resource: Writable<DiscountCode>,
|
|
106
106
|
{ maxApplications }: DiscountCodeSetMaxApplicationsAction
|
|
107
107
|
) => {
|
|
108
108
|
resource.maxApplications = maxApplications
|
|
109
109
|
},
|
|
110
110
|
setMaxApplicationsPerCustomer: (
|
|
111
|
-
|
|
111
|
+
context: RepositoryContext,
|
|
112
112
|
resource: Writable<DiscountCode>,
|
|
113
113
|
{
|
|
114
114
|
maxApplicationsPerCustomer,
|
|
@@ -117,21 +117,21 @@ export class DiscountCodeRepository extends AbstractResourceRepository {
|
|
|
117
117
|
resource.maxApplicationsPerCustomer = maxApplicationsPerCustomer
|
|
118
118
|
},
|
|
119
119
|
setValidFrom: (
|
|
120
|
-
|
|
120
|
+
context: RepositoryContext,
|
|
121
121
|
resource: Writable<DiscountCode>,
|
|
122
122
|
{ validFrom }: DiscountCodeSetValidFromAction
|
|
123
123
|
) => {
|
|
124
124
|
resource.validFrom = validFrom
|
|
125
125
|
},
|
|
126
126
|
setValidUntil: (
|
|
127
|
-
|
|
127
|
+
context: RepositoryContext,
|
|
128
128
|
resource: Writable<DiscountCode>,
|
|
129
129
|
{ validUntil }: DiscountCodeSetValidUntilAction
|
|
130
130
|
) => {
|
|
131
131
|
resource.validUntil = validUntil
|
|
132
132
|
},
|
|
133
133
|
setValidFromAndUntil: (
|
|
134
|
-
|
|
134
|
+
context: RepositoryContext,
|
|
135
135
|
resource: Writable<DiscountCode>,
|
|
136
136
|
{ validFrom, validUntil }: DiscountCodeSetValidFromAndUntilAction
|
|
137
137
|
) => {
|
|
@@ -10,14 +10,14 @@ import {
|
|
|
10
10
|
} from '@commercetools/platform-sdk'
|
|
11
11
|
import { Writable } from '../types'
|
|
12
12
|
import { getBaseResourceProperties } from '../helpers'
|
|
13
|
-
import { AbstractResourceRepository } from './abstract'
|
|
13
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
14
14
|
|
|
15
15
|
export class ExtensionRepository extends AbstractResourceRepository {
|
|
16
16
|
getTypeId(): ReferenceTypeId {
|
|
17
17
|
return 'extension'
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
create(
|
|
20
|
+
create(context: RepositoryContext, draft: ExtensionDraft): Extension {
|
|
21
21
|
const resource: Extension = {
|
|
22
22
|
...getBaseResourceProperties(),
|
|
23
23
|
key: draft.key,
|
|
@@ -25,37 +25,41 @@ export class ExtensionRepository extends AbstractResourceRepository {
|
|
|
25
25
|
destination: draft.destination,
|
|
26
26
|
triggers: draft.triggers,
|
|
27
27
|
}
|
|
28
|
-
this.save(
|
|
28
|
+
this.save(context, resource)
|
|
29
29
|
return resource
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
actions: Record<
|
|
33
33
|
ExtensionUpdateAction['action'],
|
|
34
|
-
(
|
|
34
|
+
(
|
|
35
|
+
context: RepositoryContext,
|
|
36
|
+
resource: Writable<Extension>,
|
|
37
|
+
action: any
|
|
38
|
+
) => void
|
|
35
39
|
> = {
|
|
36
40
|
setKey: (
|
|
37
|
-
|
|
41
|
+
context: RepositoryContext,
|
|
38
42
|
resource: Writable<Extension>,
|
|
39
43
|
{ key }: ExtensionSetKeyAction
|
|
40
44
|
) => {
|
|
41
45
|
resource.key = key
|
|
42
46
|
},
|
|
43
47
|
setTimeoutInMs: (
|
|
44
|
-
|
|
48
|
+
context: RepositoryContext,
|
|
45
49
|
resource: Writable<Extension>,
|
|
46
50
|
{ timeoutInMs }: ExtensionSetTimeoutInMsAction
|
|
47
51
|
) => {
|
|
48
52
|
resource.timeoutInMs = timeoutInMs
|
|
49
53
|
},
|
|
50
54
|
changeTriggers: (
|
|
51
|
-
|
|
55
|
+
context: RepositoryContext,
|
|
52
56
|
resource: Writable<Extension>,
|
|
53
57
|
{ triggers }: ExtensionChangeTriggersAction
|
|
54
58
|
) => {
|
|
55
59
|
resource.triggers = triggers
|
|
56
60
|
},
|
|
57
61
|
changeDestination: (
|
|
58
|
-
|
|
62
|
+
context: RepositoryContext,
|
|
59
63
|
resource: Writable<Extension>,
|
|
60
64
|
{ destination }: ExtensionChangeDestinationAction
|
|
61
65
|
) => {
|
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
TypedMoney,
|
|
15
15
|
} from '@commercetools/platform-sdk'
|
|
16
16
|
import { AbstractStorage } from '../storage'
|
|
17
|
+
import { RepositoryContext } from './abstract'
|
|
18
|
+
import { Request } from 'express'
|
|
17
19
|
|
|
18
20
|
export const createCustomFields = (
|
|
19
21
|
draft: CustomFieldsDraft | undefined,
|
|
@@ -96,3 +98,10 @@ export const getReferenceFromResourceIdentifier = <T extends Reference>(
|
|
|
96
98
|
id: resource?.id,
|
|
97
99
|
} as unknown) as T
|
|
98
100
|
}
|
|
101
|
+
|
|
102
|
+
export const getRepositoryContext = (request: Request): RepositoryContext => {
|
|
103
|
+
return {
|
|
104
|
+
projectKey: request.params.projectKey,
|
|
105
|
+
storeKey: request.params.storeKey,
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
ReferenceTypeId,
|
|
10
10
|
} from '@commercetools/platform-sdk'
|
|
11
11
|
import { getBaseResourceProperties } from '../helpers'
|
|
12
|
-
import { AbstractResourceRepository } from './abstract'
|
|
12
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
13
13
|
import { createCustomFields } from './helpers'
|
|
14
14
|
import { Writable } from '../types'
|
|
15
15
|
|
|
@@ -18,7 +18,10 @@ export class InventoryEntryRepository extends AbstractResourceRepository {
|
|
|
18
18
|
return 'inventory-entry'
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
create(
|
|
21
|
+
create(
|
|
22
|
+
context: RepositoryContext,
|
|
23
|
+
draft: InventoryEntryDraft
|
|
24
|
+
): InventoryEntry {
|
|
22
25
|
const resource: InventoryEntry = {
|
|
23
26
|
...getBaseResourceProperties(),
|
|
24
27
|
sku: draft.sku,
|
|
@@ -31,15 +34,19 @@ export class InventoryEntryRepository extends AbstractResourceRepository {
|
|
|
31
34
|
typeId: 'channel',
|
|
32
35
|
id: draft.supplyChannel?.id ?? '',
|
|
33
36
|
},
|
|
34
|
-
custom: createCustomFields(
|
|
37
|
+
custom: createCustomFields(
|
|
38
|
+
draft.custom,
|
|
39
|
+
context.projectKey,
|
|
40
|
+
this._storage
|
|
41
|
+
),
|
|
35
42
|
}
|
|
36
|
-
this.save(
|
|
43
|
+
this.save(context, resource)
|
|
37
44
|
return resource
|
|
38
45
|
}
|
|
39
46
|
|
|
40
47
|
actions = {
|
|
41
48
|
changeQuantity: (
|
|
42
|
-
|
|
49
|
+
context: RepositoryContext,
|
|
43
50
|
resource: Writable<InventoryEntry>,
|
|
44
51
|
{ quantity }: InventoryEntryChangeQuantityAction
|
|
45
52
|
) => {
|
|
@@ -48,14 +55,14 @@ export class InventoryEntryRepository extends AbstractResourceRepository {
|
|
|
48
55
|
resource.availableQuantity = quantity
|
|
49
56
|
},
|
|
50
57
|
setExpectedDelivery: (
|
|
51
|
-
|
|
58
|
+
context: RepositoryContext,
|
|
52
59
|
resource: Writable<InventoryEntry>,
|
|
53
60
|
{ expectedDelivery }: InventoryEntrySetExpectedDeliveryAction
|
|
54
61
|
) => {
|
|
55
62
|
resource.expectedDelivery = new Date(expectedDelivery!).toISOString()
|
|
56
63
|
},
|
|
57
64
|
setCustomField: (
|
|
58
|
-
|
|
65
|
+
context: RepositoryContext,
|
|
59
66
|
resource: InventoryEntry,
|
|
60
67
|
{ name, value }: InventoryEntrySetCustomFieldAction
|
|
61
68
|
) => {
|
|
@@ -65,7 +72,7 @@ export class InventoryEntryRepository extends AbstractResourceRepository {
|
|
|
65
72
|
resource.custom.fields[name] = value
|
|
66
73
|
},
|
|
67
74
|
setCustomType: (
|
|
68
|
-
|
|
75
|
+
context: RepositoryContext,
|
|
69
76
|
resource: Writable<InventoryEntry>,
|
|
70
77
|
{ type, fields }: InventoryEntrySetCustomTypeAction
|
|
71
78
|
) => {
|
|
@@ -73,7 +80,7 @@ export class InventoryEntryRepository extends AbstractResourceRepository {
|
|
|
73
80
|
resource.custom = undefined
|
|
74
81
|
} else {
|
|
75
82
|
const resolvedType = this._storage.getByResourceIdentifier(
|
|
76
|
-
projectKey,
|
|
83
|
+
context.projectKey,
|
|
77
84
|
type
|
|
78
85
|
)
|
|
79
86
|
if (!resolvedType) {
|
|
@@ -90,7 +97,7 @@ export class InventoryEntryRepository extends AbstractResourceRepository {
|
|
|
90
97
|
}
|
|
91
98
|
},
|
|
92
99
|
setRestockableInDays: (
|
|
93
|
-
|
|
100
|
+
context: RepositoryContext,
|
|
94
101
|
resource: Writable<InventoryEntry>,
|
|
95
102
|
{ restockableInDays }: InventoryEntrySetRestockableInDaysAction
|
|
96
103
|
) => {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import assert from 'assert'
|
|
2
|
+
import {
|
|
3
|
+
CartReference,
|
|
4
|
+
MyOrderFromCartDraft,
|
|
5
|
+
Order,
|
|
6
|
+
} from '@commercetools/platform-sdk'
|
|
7
|
+
import { OrderRepository } from './order'
|
|
8
|
+
import { RepositoryContext } from './abstract'
|
|
9
|
+
|
|
10
|
+
export class MyOrderRepository extends OrderRepository {
|
|
11
|
+
create(context: RepositoryContext, draft: MyOrderFromCartDraft): Order {
|
|
12
|
+
assert(draft.id, 'draft.id is missing')
|
|
13
|
+
const cartIdentifier = {
|
|
14
|
+
id: draft.id,
|
|
15
|
+
typeId: 'cart',
|
|
16
|
+
} as CartReference
|
|
17
|
+
return this.createFromCart(context, cartIdentifier)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,10 +1,86 @@
|
|
|
1
|
-
import { OrderImportDraft } from '@commercetools/platform-sdk'
|
|
1
|
+
import { Cart, OrderImportDraft } from '@commercetools/platform-sdk'
|
|
2
2
|
import { OrderRepository } from './order'
|
|
3
3
|
import { InMemoryStorage } from '../storage'
|
|
4
4
|
|
|
5
|
-
describe('Order
|
|
5
|
+
describe('Order repository', () => {
|
|
6
6
|
const storage = new InMemoryStorage()
|
|
7
7
|
const repository = new OrderRepository(storage)
|
|
8
|
+
|
|
9
|
+
test('create from cart', async () => {
|
|
10
|
+
const cart: Cart = {
|
|
11
|
+
id: 'b3875a58-4ab2-4aaa-b399-184ce7561c27',
|
|
12
|
+
version: 1,
|
|
13
|
+
createdAt: '2021-09-02T12:23:30.036Z',
|
|
14
|
+
lastModifiedAt: '2021-09-02T12:23:30.546Z',
|
|
15
|
+
lineItems: [],
|
|
16
|
+
customLineItems: [],
|
|
17
|
+
totalPrice: {
|
|
18
|
+
type: 'centPrecision',
|
|
19
|
+
currencyCode: 'EUR',
|
|
20
|
+
centAmount: 10000,
|
|
21
|
+
fractionDigits: 2,
|
|
22
|
+
},
|
|
23
|
+
cartState: 'Active',
|
|
24
|
+
taxMode: 'Platform',
|
|
25
|
+
taxRoundingMode: 'HalfEven',
|
|
26
|
+
taxCalculationMode: 'UnitPriceLevel',
|
|
27
|
+
refusedGifts: [],
|
|
28
|
+
origin: 'Customer',
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
storage.add('dummy', 'cart', cart)
|
|
32
|
+
|
|
33
|
+
const result = repository.create(
|
|
34
|
+
{ projectKey: 'dummy' },
|
|
35
|
+
{
|
|
36
|
+
cart: {
|
|
37
|
+
id: cart.id,
|
|
38
|
+
typeId: 'cart',
|
|
39
|
+
},
|
|
40
|
+
version: cart.version,
|
|
41
|
+
}
|
|
42
|
+
)
|
|
43
|
+
expect(result.cart?.id).toBe(cart.id)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('create from cart - in store', async () => {
|
|
47
|
+
const cart: Cart = {
|
|
48
|
+
id: 'b3875a58-4ab2-4aaa-b399-184ce7561c27',
|
|
49
|
+
version: 1,
|
|
50
|
+
createdAt: '2021-09-02T12:23:30.036Z',
|
|
51
|
+
lastModifiedAt: '2021-09-02T12:23:30.546Z',
|
|
52
|
+
lineItems: [],
|
|
53
|
+
customLineItems: [],
|
|
54
|
+
totalPrice: {
|
|
55
|
+
type: 'centPrecision',
|
|
56
|
+
currencyCode: 'EUR',
|
|
57
|
+
centAmount: 10000,
|
|
58
|
+
fractionDigits: 2,
|
|
59
|
+
},
|
|
60
|
+
cartState: 'Active',
|
|
61
|
+
taxMode: 'Platform',
|
|
62
|
+
taxRoundingMode: 'HalfEven',
|
|
63
|
+
taxCalculationMode: 'UnitPriceLevel',
|
|
64
|
+
refusedGifts: [],
|
|
65
|
+
origin: 'Customer',
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
storage.add('dummy', 'cart', cart)
|
|
69
|
+
|
|
70
|
+
const result = repository.create(
|
|
71
|
+
{ projectKey: 'dummy', storeKey: 'some-store' },
|
|
72
|
+
{
|
|
73
|
+
cart: {
|
|
74
|
+
id: cart.id,
|
|
75
|
+
typeId: 'cart',
|
|
76
|
+
},
|
|
77
|
+
version: cart.version,
|
|
78
|
+
}
|
|
79
|
+
)
|
|
80
|
+
expect(result.cart?.id).toBe(cart.id)
|
|
81
|
+
expect(result.store?.key).toBe('some-store')
|
|
82
|
+
})
|
|
83
|
+
|
|
8
84
|
test('import exiting product', async () => {
|
|
9
85
|
storage.add('dummy', 'product', {
|
|
10
86
|
id: '15fc56ba-a74e-4cf8-b4b0-bada5c101541',
|
|
@@ -150,7 +226,7 @@ describe('Order Import', () => {
|
|
|
150
226
|
],
|
|
151
227
|
}
|
|
152
228
|
|
|
153
|
-
repository.import('dummy', draft)
|
|
229
|
+
repository.import({ projectKey: 'dummy' }, draft)
|
|
154
230
|
})
|
|
155
231
|
/*
|
|
156
232
|
test('import non exiting product', async () => {
|