@@ -148,4 +148,154 @@ public function testSetCouponSuccess()
148
148
149
149
$ this ->assertEquals ($ quoteWithCoupon ->getCouponCode (), $ couponCode );
150
150
}
151
+
152
+ /**
153
+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_coupon_saved.php
154
+ */
155
+ public function testGetMyCoupon ()
156
+ {
157
+ $ this ->_markTestAsRestOnly ();
158
+
159
+ // get customer ID token
160
+ /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */
161
+ $ customerTokenService = $ this ->objectManager ->create (
162
+ 'Magento\Integration\Service\V1\CustomerTokenServiceInterface '
163
+ );
164
+ $ token = $ customerTokenService ->createCustomerAccessToken ('customer@example.com ' , 'password ' );
165
+
166
+ /** @var \Magento\Quote\Model\Quote $quote */
167
+ $ quote = $ this ->objectManager ->create ('Magento\Quote\Model\Quote ' );
168
+ $ quote ->load ('test_order_1 ' , 'reserved_order_id ' );
169
+ $ cartId = $ quote ->getId ();
170
+ $ couponCode = $ quote ->getCouponCode ();
171
+ $ serviceInfo = [
172
+ 'rest ' => [
173
+ 'resourcePath ' => self ::RESOURCE_PATH . 'mine/coupons ' ,
174
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_GET ,
175
+ 'token ' => $ token ,
176
+ ],
177
+ ];
178
+
179
+ $ requestData = [];
180
+ $ this ->assertEquals ($ couponCode , $ this ->_webApiCall ($ serviceInfo , $ requestData ));
181
+ }
182
+
183
+ /**
184
+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_coupon_saved.php
185
+ */
186
+ public function testDeleteMyCoupon ()
187
+ {
188
+ $ this ->_markTestAsRestOnly ();
189
+
190
+ // get customer ID token
191
+ /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */
192
+ $ customerTokenService = $ this ->objectManager ->create (
193
+ 'Magento\Integration\Service\V1\CustomerTokenServiceInterface '
194
+ );
195
+ $ token = $ customerTokenService ->createCustomerAccessToken ('customer@example.com ' , 'password ' );
196
+
197
+ /** @var \Magento\Quote\Model\Quote $quote */
198
+ $ quote = $ this ->objectManager ->create ('Magento\Quote\Model\Quote ' );
199
+ $ quote ->load ('test_order_1 ' , 'reserved_order_id ' );
200
+ $ cartId = $ quote ->getId ();
201
+ $ serviceInfo = [
202
+ 'rest ' => [
203
+ 'resourcePath ' => self ::RESOURCE_PATH . 'mine/coupons ' ,
204
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_DELETE ,
205
+ 'token ' => $ token ,
206
+ ],
207
+ ];
208
+ $ requestData = [];
209
+ $ this ->assertTrue ($ this ->_webApiCall ($ serviceInfo , $ requestData ));
210
+ $ quote ->load ('test_order_1 ' , 'reserved_order_id ' );
211
+ $ this ->assertEquals ('' , $ quote ->getCouponCode ());
212
+ }
213
+
214
+ /**
215
+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
216
+ * @expectedException \Exception
217
+ * @expectedExceptionMessage Coupon code is not valid
218
+ */
219
+ public function testSetMyCouponThrowsExceptionIfCouponDoesNotExist ()
220
+ {
221
+ $ this ->_markTestAsRestOnly ();
222
+
223
+ // get customer ID token
224
+ /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */
225
+ $ customerTokenService = $ this ->objectManager ->create (
226
+ 'Magento\Integration\Service\V1\CustomerTokenServiceInterface '
227
+ );
228
+ $ token = $ customerTokenService ->createCustomerAccessToken ('customer@example.com ' , 'password ' );
229
+
230
+ /** @var \Magento\Quote\Model\Quote $quote */
231
+ $ quote = $ this ->objectManager ->create ('Magento\Quote\Model\Quote ' );
232
+ $ quote ->load ('test_order_1 ' , 'reserved_order_id ' );
233
+ $ cartId = $ quote ->getId ();
234
+
235
+ $ couponCode = 'invalid_coupon_code ' ;
236
+
237
+ $ serviceInfo = [
238
+ 'rest ' => [
239
+ 'resourcePath ' => self ::RESOURCE_PATH . 'mine/coupons/ ' . $ couponCode ,
240
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_PUT ,
241
+ 'token ' => $ token ,
242
+ ],
243
+ ];
244
+
245
+ $ requestData = [
246
+ "couponCode " => $ couponCode ,
247
+ ];
248
+
249
+ $ this ->_webApiCall ($ serviceInfo , $ requestData );
250
+ }
251
+
252
+ /**
253
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
254
+ * @magentoApiDataFixture Magento/Sales/_files/quote.php
255
+ * @magentoApiDataFixture Magento/Checkout/_files/discount_10percent_generalusers.php
256
+ */
257
+ public function testSetMyCouponSuccess ()
258
+ {
259
+ $ this ->_markTestAsRestOnly ();
260
+
261
+ // get customer ID token
262
+ /** @var \Magento\Integration\Service\V1\CustomerTokenServiceInterface $customerTokenService */
263
+ $ customerTokenService = $ this ->objectManager ->create (
264
+ 'Magento\Integration\Service\V1\CustomerTokenServiceInterface '
265
+ );
266
+ $ token = $ customerTokenService ->createCustomerAccessToken ('customer@example.com ' , 'password ' );
267
+
268
+ /** @var \Magento\Quote\Model\Quote $quote */
269
+ $ quote = $ this ->objectManager ->create ('Magento\Quote\Model\Quote ' );
270
+ $ quote ->load ('test01 ' , 'reserved_order_id ' );
271
+ $ cartId = $ quote ->getId ();
272
+ $ salesRule = $ this ->objectManager ->create ('Magento\SalesRule\Model\Rule ' );
273
+ $ salesRule ->load ('Test Coupon for General ' , 'name ' );
274
+ $ couponCode = $ salesRule ->getCouponCode ();
275
+
276
+ /* Since this isn't a full quote fixture, need to assign it to the right customer */
277
+ $ cartManagementService = $ this ->objectManager ->create (
278
+ 'Magento\Quote\Api\CartManagementInterface '
279
+ );
280
+ $ cartManagementService ->assignCustomer ($ cartId , 1 , 1 );
281
+
282
+ $ serviceInfo = [
283
+ 'rest ' => [
284
+ 'resourcePath ' => self ::RESOURCE_PATH . 'mine/coupons/ ' . $ couponCode ,
285
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_PUT ,
286
+ 'token ' => $ token ,
287
+ ],
288
+ ];
289
+
290
+ $ requestData = [
291
+ "couponCode " => $ couponCode ,
292
+ ];
293
+
294
+ $ this ->assertTrue ($ this ->_webApiCall ($ serviceInfo , $ requestData ));
295
+
296
+ $ quoteWithCoupon = $ this ->objectManager ->create ('Magento\Quote\Model\Quote ' );
297
+ $ quoteWithCoupon ->load ('test01 ' , 'reserved_order_id ' );
298
+
299
+ $ this ->assertEquals ($ quoteWithCoupon ->getCouponCode (), $ couponCode );
300
+ }
151
301
}
0 commit comments