5
5
use Algolia \AlgoliaSearch \Api \InsightsClient ;
6
6
use Algolia \AlgoliaSearch \Service \Insights \EventProcessor ;
7
7
use Magento \Sales \Model \Order \Item as OrderItem ;
8
+ use Magento \Store \Model \Store ;
8
9
use Magento \Store \Model \StoreManagerInterface ;
10
+ use Magento \Tax \Model \Config as TaxConfig ;
9
11
use PHPUnit \Framework \TestCase ;
10
12
11
13
class EventProcessorTest extends TestCase
12
14
{
15
+ protected ?TaxConfig $ taxConfig ;
13
16
protected ?InsightsClient $ client ;
14
17
protected ?string $ userToken ;
15
18
protected ?string $ authenticatedUserToken ;
@@ -23,7 +26,13 @@ protected function setUp(): void
23
26
$ this ->authenticatedUserToken = 'authenticated-foo ' ;
24
27
$ this ->storeManager = $ this ->createMock (StoreManagerInterface::class);
25
28
29
+ $ store = $ this ->createMock (Store::class);
30
+ $ store ->method ('getId ' )->willReturn (1 );
31
+ $ this ->storeManager ->method ('getStore ' )->willReturn ($ store );
32
+ $ this ->taxConfig = $ this ->createMock (TaxConfig::class);
33
+
26
34
$ this ->eventProcessor = new EventProcessorTestable (
35
+ $ this ->taxConfig ,
27
36
$ this ->client ,
28
37
$ this ->userToken ,
29
38
$ this ->authenticatedUserToken ,
@@ -34,8 +43,10 @@ protected function setUp(): void
34
43
/**
35
44
* @dataProvider orderItemsProvider
36
45
*/
37
- public function testObjectDataForPurchase ($ orderItemsData , $ expectedResult , $ expectedTotalRevenue ): void
46
+ public function testObjectDataForPurchase ($ priceIncludesTax , $ orderItemsData , $ expectedResult , $ expectedTotalRevenue ): void
38
47
{
48
+ $ this ->taxConfig ->method ('priceIncludesTax ' )->willReturn ($ priceIncludesTax );
49
+
39
50
$ orderItems = [];
40
51
41
52
foreach ($ orderItemsData as $ orderItemData ) {
@@ -61,8 +72,10 @@ public function orderItemsProvider(): array
61
72
{
62
73
return [
63
74
[ // One item
75
+ 'priceIncludesTax ' => true ,
64
76
'orderItemsData ' => [
65
77
[
78
+ 'getPrice ' => 32.00 ,
66
79
'getPriceInclTax ' => 32.00 ,
67
80
'getOriginalPrice ' => 32.00 ,
68
81
'getDiscountAmount ' => 0.00 ,
@@ -78,9 +91,31 @@ public function orderItemsProvider(): array
78
91
],
79
92
'expectedTotalRevenue ' => 32.00
80
93
],
94
+ [ // One item (tax excluded)
95
+ 'priceIncludesTax ' => false ,
96
+ 'orderItemsData ' => [
97
+ [
98
+ 'getPrice ' => 25.00 ,
99
+ 'getPriceInclTax ' => 32.00 ,
100
+ 'getOriginalPrice ' => 25.00 ,
101
+ 'getDiscountAmount ' => 0.00 ,
102
+ 'getQtyOrdered ' => 1 ,
103
+ ]
104
+ ],
105
+ 'expectedResult ' => [
106
+ [
107
+ 'price ' => 25.00 ,
108
+ 'discount ' => 0.00 ,
109
+ 'quantity ' => 1 ,
110
+ ]
111
+ ],
112
+ 'expectedTotalRevenue ' => 25.00
113
+ ],
81
114
[ // One item with discount
115
+ 'priceIncludesTax ' => true ,
82
116
'orderItemsData ' => [
83
117
[
118
+ 'getPrice ' => 32.00 ,
84
119
'getPriceInclTax ' => 32.00 ,
85
120
'getOriginalPrice ' => 32.00 ,
86
121
'getDiscountAmount ' => 7.00 ,
@@ -96,15 +131,38 @@ public function orderItemsProvider(): array
96
131
],
97
132
'expectedTotalRevenue ' => 25.00
98
133
],
134
+ [ // One item with discount (tax excluded)
135
+ 'priceIncludesTax ' => false ,
136
+ 'orderItemsData ' => [
137
+ [
138
+ 'getPrice ' => 25.00 ,
139
+ 'getPriceInclTax ' => 32.00 ,
140
+ 'getOriginalPrice ' => 25.00 ,
141
+ 'getDiscountAmount ' => 7.00 ,
142
+ 'getQtyOrdered ' => 1 ,
143
+ ]
144
+ ],
145
+ 'expectedResult ' => [
146
+ [
147
+ 'price ' => 18.00 ,
148
+ 'discount ' => 7.00 ,
149
+ 'quantity ' => 1 ,
150
+ ]
151
+ ],
152
+ 'expectedTotalRevenue ' => 18.00
153
+ ],
99
154
[ // Two items
155
+ 'priceIncludesTax ' => true ,
100
156
'orderItemsData ' => [
101
157
[
158
+ 'getPrice ' => 32.00 ,
102
159
'getPriceInclTax ' => 32.00 ,
103
160
'getOriginalPrice ' => 32.00 ,
104
161
'getDiscountAmount ' => 7.00 ,
105
162
'getQtyOrdered ' => 1 ,
106
163
],
107
164
[
165
+ 'getPrice ' => 32.00 ,
108
166
'getPriceInclTax ' => 32.00 ,
109
167
'getOriginalPrice ' => 32.00 ,
110
168
'getDiscountAmount ' => 0.00 ,
0 commit comments