Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v3] Make Digital Reward and Digital Reward Code nullable #25

Merged
merged 4 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/Mappers/Loyalty/Receptions/DigitalRewardReceptionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ public function map(stdClass $data): DigitalRewardReception

$contact = $contactMapper->map($data->contact);
$shop = $shopMapper->map($data->shop);
$digitalReward = $digitalRewardMapper->map($data->digital_reward);
$digitalRewardCode = $digitalRewardCodeMapper->map($data->digital_reward_code);

if (isset($data->digital_reward)) {
$digitalReward = $digitalRewardMapper->map($data->digital_reward);
}

if (isset($data->digital_reward_code)) {
$digitalRewardCode = $digitalRewardCodeMapper->map($data->digital_reward_code);
}

if (isset($data->contact_identifier)) {
$contactIdentifier = $contactIdentifierMapper->map($data->contact_identifier);
Expand All @@ -41,8 +47,8 @@ public function map(stdClass $data): DigitalRewardReception
$contactIdentifier,
$this->parseDate($data->created_at),
$data->title,
$digitalReward,
$digitalRewardCode
$digitalReward ?? null,
$digitalRewardCode ?? null
);
}
}
4 changes: 1 addition & 3 deletions src/Mappers/Loyalty/Rewards/DigitalRewardCodeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class DigitalRewardCodeMapper
{
public function map(stdClass $data): DigitalRewardCode
{
return new DigitalRewardCode(
$data->code
);
return new DigitalRewardCode($data->code);
}
}
10 changes: 5 additions & 5 deletions src/Models/Loyalty/Receptions/DigitalRewardReception.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ class DigitalRewardReception extends BaseReception
protected $title;

/**
* @var DigitalReward
* @var DigitalReward|null
*/
protected $digitalReward;

/**
* @var DigitalRewardCode
* @var DigitalRewardCode|null
*/
protected $digitalRewardCode;

public function __construct(string $type, int $credits, string $uuid, Contact $contact, Shop $shop, ?ContactIdentifier $contactIdentifier, DateTime $createdAt, string $title, DigitalReward $digitalReward, DigitalRewardCode $digitalRewardCode)
public function __construct(string $type, int $credits, string $uuid, Contact $contact, Shop $shop, ?ContactIdentifier $contactIdentifier, DateTime $createdAt, string $title, ?DigitalReward $digitalReward, ?DigitalRewardCode $digitalRewardCode)
{
$this->type = $type;
$this->credits = $credits;
Expand Down Expand Up @@ -115,12 +115,12 @@ public function getTitle(): string
return $this->title;
}

public function getDigitalReward(): DigitalReward
public function getDigitalReward(): ?DigitalReward
{
return $this->digitalReward;
}

public function getDigitalRewardCode(): DigitalRewardCode
public function getDigitalRewardCode(): ?DigitalRewardCode
{
return $this->digitalRewardCode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ public static function map(stdClass $data): DigitalRewardReception
{
$contact = ContactMapper::map($data->contact);
$shop = ShopMapper::map($data->shop);
$digitalReward = DigitalRewardMapper::map($data->digital_reward);
$digitalRewardCode = DigitalRewardCodeMapper::map($data->digital_reward_code);

$contactIdentifier = null;
$digitalReward = null;
Thibaux marked this conversation as resolved.
Show resolved Hide resolved
if (isset($data->digital_reward)) {
$digitalReward = DigitalRewardMapper::map($data->digital_reward);
}

if (isset($data->digital_reward_code)) {
$digitalRewardCode = DigitalRewardCodeMapper::map($data->digital_reward_code);
}

if (isset($data->contact_identifier)) {
$contactIdentifier = ContactIdentifierMapper::map($data->contact_identifier);
}
Expand All @@ -34,8 +40,8 @@ public static function map(stdClass $data): DigitalRewardReception
$contactIdentifier,
self::parseDate($data->created_at),
$data->title,
$digitalReward,
$digitalRewardCode
$digitalReward ?? null,
$digitalRewardCode ?? null
);
}
}
39 changes: 38 additions & 1 deletion tests/OAuth/Loyalty/Receptions/RewardReceptionsResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,44 @@ public function it_returns_a_physical_reward_reception()
$this->assertEquals('PHYSICAL', $rewardReception->getReward()->getRewardType());
$this->assertEquals('332-3232', $rewardReception->getReward()->getUuid());
$this->assertEquals('2022-06-30T15:11:57+00:00', $rewardReception->getExpiresAt()->format('c'));
$this->assertEquals(false, $rewardReception->getHasBeenCollected());
$this->assertFalse($rewardReception->getHasBeenCollected());
}

/**
* @test
*
* @throws PiggyRequestException
* @throws Exception
*/
public function it_returns_a_digital_reward_reception_without_a_reward_linked()
{
$this->addExpectedResponse([
'type' => 'digital_reward_reception',
'credits' => -40,
'uuid' => '123-lol',
'contact' => [
'uuid' => '123-123',
],
'shop' => [
'name' => 'shopName',
'uuid' => '123-312',
],
'created_at' => '2022-06-30T13:42:04+00:00',
'title' => 'digital reward title',
]);

$rewardReception = $this->mockedClient->rewardReceptions->create('123-123', '123-312', '123-lol');

$this->assertEquals('digital_reward_reception', $rewardReception->getType());
$this->assertEquals(-40, $rewardReception->getCredits());
$this->assertEquals('123-lol', $rewardReception->getUuid());
$this->assertEquals('123-123', $rewardReception->getContact()->getUuid());
$this->assertEquals('123-312', $rewardReception->getShop()->getUuid());
$this->assertEquals('shopName', $rewardReception->getShop()->getName());
$this->assertEquals('2022-06-30T13:42:04+00:00', $rewardReception->getCreatedAt()->format('c'));
$this->assertEquals('digital reward title', $rewardReception->getTitle());

$this->assertNull($rewardReception->getDigitalReward());
}

/**
Expand Down
Loading