Skip to content

Commit

Permalink
Update Cards service method signature
Browse files Browse the repository at this point in the history
The signature for the method `getById` in the `Cards` service has been changed from `CardItemResult` to `CardResult`. The required changes have been made in the `Cards` class and the associated test. A new class `CardResult` has also been added.

Signed-off-by: B24io <[email protected]>
  • Loading branch information
b24io-sdk committed Jul 9, 2024
1 parent 1741a77 commit 6f68aba
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

* change signature for method `Loyalty\SDK\Services\Admin\Contacts::add`, argument `$mobilePhone` can be nullable.
* change signature for method `Loyalty\SDK\Services\Admin\Contacts::getById` from `ContactItemResult` to `ContactResult`
* WIP change signature for method `Loyalty\SDK\Services\Admin\Cards::getById` from `` to ``
* change signature for method `Loyalty\SDK\Services\Admin\Cards::getById` from `CardItemResult` to `CardResult`

## 3.2.0 (2024.05.23)

Expand Down
15 changes: 15 additions & 0 deletions src/Common/Result/Cards/CardResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace B24io\Loyalty\SDK\Common\Result\Cards;

use B24io\Loyalty\SDK\Core\Result\AbstractResult;

class CardResult extends AbstractResult
{
public function getCard(): CardItemResult
{
return new CardItemResult($this->getCoreResponse()->getResponseData()->result);
}
}
8 changes: 4 additions & 4 deletions src/Services/Admin/Cards/Cards.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use B24io\Loyalty\SDK\Common\Requests\ItemsOrder;
use B24io\Loyalty\SDK\Common\Result\Cards\AddedCardResult;
use B24io\Loyalty\SDK\Common\Result\Cards\CardItemResult;
use B24io\Loyalty\SDK\Common\Result\Cards\CardResult;
use B24io\Loyalty\SDK\Common\Result\Cards\CardsResult;
use B24io\Loyalty\SDK\Common\Result\Cards\CardStatus;
use B24io\Loyalty\SDK\Core\Command;
Expand Down Expand Up @@ -58,16 +58,16 @@ public function add(
));
}

public function getById(Uuid $id): CardItemResult
public function getById(Uuid $id): CardResult
{
return new CardItemResult(
return new CardResult(
$this->core->call(
new Command(
Context::admin(),
RequestMethodInterface::METHOD_GET,
sprintf('cards/%s', $id->toRfc4122()),
)
)->getResponseData()->result
)
);
}

Expand Down
76 changes: 76 additions & 0 deletions tests/Integration/Services/Admin/Cards/CardsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use B24io\Loyalty\SDK\Common\Result\Cards\CardStatus;
use B24io\Loyalty\SDK\Core\Exceptions\BadRequestException;
use B24io\Loyalty\SDK\Core\Exceptions\BaseException;
use B24io\Loyalty\SDK\Core\Exceptions\MethodNotFoundException;
use B24io\Loyalty\SDK\Services\Admin\AdminServiceBuilder;
use B24io\Loyalty\SDK\Tests\Integration\IntegrationTestsContextBuilder;
use DateTimeZone;
Expand All @@ -26,6 +27,7 @@
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Faker;
use Throwable;
use Symfony\Component\Uid\Uuid;

class CardsTest extends TestCase
{
Expand Down Expand Up @@ -113,6 +115,80 @@ public function testAddCard(): void
}
}

/**
* @throws BaseException
* @throws NumberParseException
* @testdox Test add card and contact with mobile phone
* @covers \B24io\Loyalty\SDK\Services\Admin\Contacts\Contacts::add
* @covers \B24io\Loyalty\SDK\Services\Admin\Cards\Cards::add
* @covers \B24io\Loyalty\SDK\Services\Admin\Cards\Cards::getById
*/
public function testGetCardByIdHappyPath(): void
{
$phone = $this->phoneNumberUtil->parse(
$this->faker->phoneNumber,
'RU'
);
$addedContact = $this->sb->contactsScope()->contacts()->add(
new FullName(
$this->faker->firstName(),
$this->faker->lastName(),
),
new DateTimeZone('Europe/Moscow'),
Gender::male(),
$phone
);

$contactId = $addedContact->getContact()->id;
$cardNumber = (string)time();
$cardBalance = new Money(random_int(1000, 1000000), new Currency('RUB'));
$cardPercentage = new Percentage('5.5');
$cardStatus = CardStatus::active();

$addedCard = $this->sb->cardsScope()->cards()->add(
$contactId,
$cardNumber,
$cardBalance,
$cardPercentage,
$cardStatus
);

$card = $this->sb->cardsScope()->cards()->getById($addedCard->getCard()->id)->getCard();

$this->assertEquals($cardNumber, $card->number,
sprintf('expected «%s» card number, but «%s» number returned',
$cardNumber,
$card->number));
$this->assertEquals(
$cardBalance->getAmount(),
$card->balance->getAmount(),
sprintf('for card with id %s and number %s expected balance «%s», but «%s» balance returned',
$card->id->toRfc4122(),
$cardNumber,
$cardBalance->getAmount(),
$card->balance->getAmount()
)
);
$this->assertEquals(
$cardPercentage->format(),
$card->percentage->format()
);
$this->assertEquals(
$cardStatus,
$card->status
);
if ($card->mobilePhone !== null) {
$this->assertTrue($card->mobilePhone->verificationStatus->isUnverified());
$this->assertTrue($phone->equals($card->mobilePhone->phoneNumber));
}
}

public function testGetByIdNonExistingCard():void
{
$this->expectException(MethodNotFoundException::class);
$this->sb->cardsScope()->cards()->getById(Uuid::v4());
}

/**
* @return void
* @throws TransportExceptionInterface
Expand Down

0 comments on commit 6f68aba

Please sign in to comment.