Skip to content

Commit

Permalink
fixup! FE API addProductToListMutation: ensure new product list is cr…
Browse files Browse the repository at this point in the history
…eated with non-conflicting uuid
  • Loading branch information
vitek-rostislav committed Apr 24, 2024
1 parent c81bd03 commit 3267f66
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ public function testAddProductCreatesNewListWhenNewUuidIsProvided(string $produc
public function testAddProductCreatesNewListWithNewUuidWhenUuidOfAnonymousListIsProvided(
string $productListType,
): void {
$anonymousProductListUuid = $productListType === ProductListTypeEnum::COMPARISON
? ProductListDataFixture::PRODUCT_LIST_COMPARISON_NOT_LOGGED_CUSTOMER_UUID
: ProductListDataFixture::PRODUCT_LIST_WISHLIST_NOT_LOGGED_CUSTOMER_UUID;
$anonymousProductListUuid = $this->getAnonymousProductListUuid($productListType);
$productToAddId = 69;
$productToAdd = $this->getReference(ProductDataFixture::PRODUCT_PREFIX . $productToAddId);
$response = $this->getResponseContentForGql(__DIR__ . '/graphql/AddProductToListMutation.graphql', [
Expand Down Expand Up @@ -266,4 +264,17 @@ public function productListDataProvider(): Iterator
'expectedProductIds' => [1],
];
}

/**
* @param string $productListType
* @return string
*/
private function getAnonymousProductListUuid(string $productListType): string
{
return match ($productListType) {
ProductListTypeEnum::COMPARISON => ProductListDataFixture::PRODUCT_LIST_COMPARISON_NOT_LOGGED_CUSTOMER_UUID,
ProductListTypeEnum::WISHLIST => ProductListDataFixture::PRODUCT_LIST_WISHLIST_NOT_LOGGED_CUSTOMER_UUID,
default => throw new UnknownProductListTypeException($productListType),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ public function testAddProductCreatesNewListWhenNewUuidIsProvided(string $produc
public function testAddProductCreatesNewListWithNewUuidWhenUuidOfCustomerUserListIsProvided(
string $productListType,
): void {
$customerUserProductListUuid = $productListType === ProductListTypeEnum::COMPARISON
? ProductListDataFixture::PRODUCT_LIST_COMPARISON_LOGGED_CUSTOMER_UUID
: ProductListDataFixture::PRODUCT_LIST_WISHLIST_LOGGED_CUSTOMER_UUID;
$customerUserProductListUuid = $this->getCustomerUserProductListUuid($productListType);
$productToAddId = 69;
$productToAdd = $this->getReference(ProductDataFixture::PRODUCT_PREFIX . $productToAddId);
$response = $this->getResponseContentForGql(__DIR__ . '/graphql/AddProductToListMutation.graphql', [
Expand Down Expand Up @@ -495,4 +493,17 @@ private function assertOriginalAnonymousListsDoNotExist(): void
$this->assertTrue($originalAnonymousWishlist === null, 'Original anonymous wishlist should not exist anymore');
$this->assertTrue($originalAnonymousComparison === null, 'Original anonymous comparison should not exist anymore');
}

/**
* @param string $productListType
* @return string
*/
private function getCustomerUserProductListUuid(string $productListType): string
{
return match ($productListType) {
ProductListTypeEnum::COMPARISON => ProductListDataFixture::PRODUCT_LIST_COMPARISON_LOGGED_CUSTOMER_UUID,
ProductListTypeEnum::WISHLIST => ProductListDataFixture::PRODUCT_LIST_WISHLIST_LOGGED_CUSTOMER_UUID,
default => throw new UnknownProductListTypeException($productListType),
};
}
}

0 comments on commit 3267f66

Please sign in to comment.