Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Commit

Permalink
GraphQL-571: [Checkout Coverage] Place order for guest
Browse files Browse the repository at this point in the history
  • Loading branch information
naydav committed Apr 16, 2019
1 parent 58fa5d4 commit 44b99de
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,24 @@ class SetGuestEmailOnCart implements ResolverInterface
*/
private $getCartForUser;

/**
* @var EmailAddressValidator
*/
private $emailValidator;

/**
* @param GetCartForUser $getCartForUser
* @param CartRepositoryInterface $cartRepository
* @param EmailAddressValidator $emailValidator
*/
public function __construct(
GetCartForUser $getCartForUser,
CartRepositoryInterface $cartRepository
CartRepositoryInterface $cartRepository,
EmailAddressValidator $emailValidator
) {
$this->getCartForUser = $getCartForUser;
$this->cartRepository = $cartRepository;
$this->emailValidator = $emailValidator;
}

/**
Expand All @@ -58,11 +66,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
throw new GraphQlInputException(__('Required parameter "email" is missing'));
}

$guestEmail = $args['input']['email'];

if (!\Zend_Validate::is($guestEmail, EmailAddressValidator::class)) {
if (false === $this->emailValidator->isValid($args['input']['email'])) {
throw new GraphQlInputException(__('Invalid email format'));
}
$email = $args['input']['email'];

$currentUserId = $context->getUserId();

Expand All @@ -71,7 +78,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
}

$cart = $this->getCartForUser->execute($maskedCartId, $currentUserId);
$cart->setCustomerEmail($guestEmail);
$cart->setCustomerEmail($email);

try {
$this->cartRepository->save($cart);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private function getQuery(string $maskedQuoteId, string $email): string
email: "$email"
}) {
cart {
guest_email
email
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testSetGuestEmailOnCart()

$this->assertArrayHasKey('setGuestEmailOnCart', $response);
$this->assertArrayHasKey('cart', $response['setGuestEmailOnCart']);
$this->assertEquals($email, $response['setGuestEmailOnCart']['cart']['guest_email']);
$this->assertEquals($email, $response['setGuestEmailOnCart']['cart']['email']);
}

/**
Expand All @@ -65,16 +65,14 @@ public function testSetGuestEmailOnCustomerCart()
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
*
* @dataProvider incorrectEmailDataProvider
* @param string $maskedQuoteId
* @param string $email
* @param string $exceptionMessage
*/
public function testSetGuestEmailOnCartWithIncorrectEmail(
string $maskedQuoteId,
string $email,
string $exceptionMessage
) {
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute($maskedQuoteId);
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');

$query = $this->getQuery($maskedQuoteId, $email);
$this->expectExceptionMessage($exceptionMessage);
Expand All @@ -87,8 +85,8 @@ public function testSetGuestEmailOnCartWithIncorrectEmail(
public function incorrectEmailDataProvider(): array
{
return [
'wrong_email' => ['test_quote', 'some', 'Invalid email format'],
'no_email' => ['test_quote', '', 'Required parameter "email" is missing'],
'wrong_email' => ['some', 'Invalid email format'],
'no_email' => ['', 'Required parameter "email" is missing'],
];
}

Expand Down Expand Up @@ -134,7 +132,7 @@ private function getQuery(string $maskedQuoteId, string $email): string
email: "$email"
}) {
cart {
guest_email
email
}
}
}
Expand Down

0 comments on commit 44b99de

Please sign in to comment.