[API][AddressBook] Setting default address#11961
Conversation
AdamKasp
commented
Oct 26, 2020
| Q | A |
|---|---|
| Branch? | master |
| Bug fix? | no |
| New feature? | yes |
| BC breaks? | no |
| License | MIT |
| { | ||
| $userShowResponse = $this->customerClient->show((string) $this->sharedStorage->get('user')->getCustomer()->getId()); | ||
| Assert::null($this->responseChecker->getValue($userShowResponse, 'defaultAddress'), 'Default address should be null' | ||
| ); |
There was a problem hiding this comment.
Can we move this ); to one line 😄 As we can see it even cries because of it
| $this->addressClient->index(); | ||
|
|
||
| Assert::same(count($this->responseChecker->getCollection($this->client->getLastResponse())), $count); | ||
| Assert::same(count($this->responseChecker->getCollection($this->addressClient->getLastResponse())), $count); |
There was a problem hiding this comment.
| Assert::same(count($this->responseChecker->getCollection($this->addressClient->getLastResponse())), $count); | |
| Assert::same(count($this->responseChecker->getCollection($this->addressClient->index())), $count); |
| public function iShouldHaveAddresses(int $count = 1): void | ||
| { | ||
| $this->client->index(); | ||
| $this->addressClient->index(); |
There was a problem hiding this comment.
| $this->addressClient->index(); |
| $addressIri = $this->getAddressIriFromAddressBookByFullName($fullName); | ||
| $addressBook = $this->responseChecker->getCollection($this->addressClient->getLastResponse()); | ||
|
|
||
| Assert::notEmpty( | ||
| array_filter($addressBook, function($address) use ($addressIri) { | ||
| return $address['@id'] === $addressIri; | ||
| }), | ||
| sprintf('There is no Address assigned to %s', $fullName) | ||
| ); |
There was a problem hiding this comment.
I wonder if this method makes sense, because in getAddressIriFromAddressBookByFullName method you are getting an address from the address book and then you are checking if this address is in the same address book 😃
Maybe you could use an address transformer to get an address by full name and then check if this address is in address book? Or even simple, just check if the value returned from getAddressIriFromAddressBookByFullName method is not null.
| public function thereShouldBeNoAddresses(): void | ||
| { | ||
| $this->client->index(); | ||
| $this->addressClient->index(); |
There was a problem hiding this comment.
| $this->addressClient->index(); |
| $this->addressClient->index(); | ||
|
|
||
| Assert::same(count($this->responseChecker->getCollection($this->client->getLastResponse())), 0); | ||
| Assert::same(count($this->responseChecker->getCollection($this->addressClient->getLastResponse())), 0); |
There was a problem hiding this comment.
| Assert::same(count($this->responseChecker->getCollection($this->addressClient->getLastResponse())), 0); | |
| Assert::same(count($this->responseChecker->getCollection($this->addressClient->index())), 0); |
| { | ||
| Assert::notNull($fullName); | ||
| $fullNameArray = explode(' ',$fullName); | ||
| [$firstName, $lastName] = explode(' ',$fullName); |
There was a problem hiding this comment.
| [$firstName, $lastName] = explode(' ',$fullName); | |
| [$firstName, $lastName] = explode(' ', $fullName); |
| private function getAddressIriFromAddressBookByFullName(string $fullName): ?string | ||
| { | ||
| Assert::notNull($fullName); | ||
| [$firstName, $lastName] = explode(' ',$fullName); |
There was a problem hiding this comment.
| [$firstName, $lastName] = explode(' ',$fullName); | |
| [$firstName, $lastName] = explode(' ', $fullName); |
|
Thank you, Adam! 🥇 |