Skip to content

Commit 95473fc

Browse files
committed
Revert "AC-15054: Product Add to Cart issue in Rest API"
This reverts commit f4f04df.
1 parent 357fbb1 commit 95473fc

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

app/code/Magento/Quote/Test/Unit/Plugin/Webapi/ValidateProductWebsiteAssignmentTest.php

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function testBeforeSaveSuccessful()
160160
->with($productId, false, $storeId)
161161
->willReturn($this->productMock);
162162

163-
$this->productMock->expects($this->exactly(2))
163+
$this->productMock->expects($this->once())
164164
->method('getWebsiteIds')
165165
->willReturn($productWebsiteIds);
166166

@@ -226,7 +226,7 @@ public function testBeforeSaveProductNotAssignedToWebsite()
226226
->with($productId, false, $storeId)
227227
->willReturn($this->productMock);
228228

229-
$this->productMock->expects($this->exactly(2))
229+
$this->productMock->expects($this->once())
230230
->method('getWebsiteIds')
231231
->willReturn($productWebsiteIds);
232232

@@ -277,6 +277,15 @@ public function testBeforeSaveProductWebsiteIdsNotArray()
277277
->method('getProductId')
278278
->willReturn($productId);
279279

280+
$this->storeManagerMock->expects($this->once())
281+
->method('getStore')
282+
->with($storeId)
283+
->willReturn($this->storeMock);
284+
285+
$this->storeMock->expects($this->once())
286+
->method('getWebsiteId')
287+
->willReturn($websiteId);
288+
280289
$this->productRepositoryMock->expects($this->once())
281290
->method('getById')
282291
->with($productId, false, $storeId)
@@ -286,8 +295,10 @@ public function testBeforeSaveProductWebsiteIdsNotArray()
286295
->method('getWebsiteIds')
287296
->willReturn($productWebsiteIds);
288297

298+
$this->expectException(LocalizedException::class);
299+
$this->expectExceptionMessage('Product that you are trying to add is not available.');
300+
289301
$this->plugin->beforeSave($this->cartItemRepositoryMock, $this->cartItemMock);
290-
$this->assertTrue(true);
291302
}
292303

293304
/**
@@ -379,7 +390,7 @@ public function testBeforeSaveMultipleWebsitesIncludingCurrent()
379390
->with($productId, false, $storeId)
380391
->willReturn($this->productMock);
381392

382-
$this->productMock->expects($this->exactly(2))
393+
$this->productMock->expects($this->once())
383394
->method('getWebsiteIds')
384395
->willReturn($productWebsiteIds);
385396

@@ -431,13 +442,28 @@ public function testBeforeSaveEmptyWebsiteIds()
431442
->method('getProductId')
432443
->willReturn($productId);
433444

445+
$this->storeManagerMock->expects($this->once())
446+
->method('getStore')
447+
->with($storeId)
448+
->willReturn($this->storeMock);
449+
450+
$this->storeMock->expects($this->once())
451+
->method('getWebsiteId')
452+
->willReturn($websiteId);
453+
434454
$this->productRepositoryMock->expects($this->once())
435455
->method('getById')
436456
->with($productId, false, $storeId)
437457
->willReturn($this->productMock);
438458

459+
$this->productMock->expects($this->once())
460+
->method('getWebsiteIds')
461+
->willReturn($productWebsiteIds);
462+
463+
$this->expectException(LocalizedException::class);
464+
$this->expectExceptionMessage('Product that you are trying to add is not available.');
465+
439466
$this->plugin->beforeSave($this->cartItemRepositoryMock, $this->cartItemMock);
440-
$this->assertTrue(true);
441467
}
442468

443469
/**
@@ -495,7 +521,7 @@ public function testBeforeSaveWebsiteIdZero()
495521
->with($productId, false, $storeId)
496522
->willReturn($this->productMock);
497523

498-
$this->productMock->expects($this->exactly(2))
524+
$this->productMock->expects($this->once())
499525
->method('getWebsiteIds')
500526
->willReturn($productWebsiteIds);
501527

0 commit comments

Comments
 (0)