Skip to content

Commit

Permalink
Add more tests and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
galeaspablo committed Sep 25, 2024
1 parent bbd2eb5 commit 148ab8c
Show file tree
Hide file tree
Showing 13 changed files with 216 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public function handle(DefineProductCommand $command): void
return;
}

if (!in_array($command->paymentCycle, ['monthly', 'quarterly'])) {
if (!\in_array($command->paymentCycle, ['monthly', 'quarterly'], true)) {
throw new InvalidPaymentCycle();
}

if (!in_array($command->reward, ['points', 'cashback', 'no_reward'])) {
if (!\in_array($command->reward, ['points', 'cashback', 'no_reward'], true)) {
throw new InvalidReward();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

use Galeas\Api\CommonException\BadRequestException;

class
InvalidReward extends BadRequestException
class InvalidReward extends BadRequestException
{
public static function getErrorIdentifier(): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function project(Event $event): void
->getSingleResult()
;

if ($userDetails instanceof UserDetails && $event instanceof SignedUp) {
if (null === $userDetails && $event instanceof SignedUp) {
$userDetails = UserDetails::fromProperties($userId, UnverifiedEmail::fromProperties(
$event->primaryEmail()
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,53 +22,53 @@ public function testHandle(): void
$command = new DefineProductCommand();
$command->productIdentifierForAggregateIdHash = 'some-hash';
$command->name = 'Test Product';
$command->interestInBasisPoints = 1500;
$command->annualFeeInCents = 5000;
$command->interestInBasisPoints = 1_500;
$command->annualFeeInCents = 5_000;
$command->paymentCycle = 'monthly';
$command->creditLimitInCents = 100000;
$command->maxBalanceTransferAllowedInCents = 50000;
$command->creditLimitInCents = 100_000;
$command->maxBalanceTransferAllowedInCents = 50_000;
$command->reward = 'cashback';
$command->cardBackgroundHex = '#FFFFFF';

$handler->handle($command);

/** @var ProductDefined[] $events */
$events = $eventStore->storedEvents();
$this->assertCount(1, $events);
$this->assertInstanceOf(ProductDefined::class, $events[0]);
$this->assertEquals('Test Product', $events[0]->name());
$this->assertEquals(1500, $events[0]->interestInBasisPoints());
$this->assertEquals(5000, $events[0]->annualFeeInCents());
$this->assertEquals('monthly', $events[0]->paymentCycle());
$this->assertEquals(100000, $events[0]->creditLimitInCents());
$this->assertEquals(50000, $events[0]->maxBalanceTransferAllowedInCents());
$this->assertEquals('cashback', $events[0]->reward());
$this->assertEquals('#FFFFFF', $events[0]->cardBackgroundHex());
self::assertCount(1, $events);
self::assertInstanceOf(ProductDefined::class, $events[0]);
self::assertEquals('Test Product', $events[0]->name());
self::assertEquals(1_500, $events[0]->interestInBasisPoints());
self::assertEquals(5_000, $events[0]->annualFeeInCents());
self::assertEquals('monthly', $events[0]->paymentCycle());
self::assertEquals(100_000, $events[0]->creditLimitInCents());
self::assertEquals(50_000, $events[0]->maxBalanceTransferAllowedInCents());
self::assertEquals('cashback', $events[0]->reward());
self::assertEquals('#FFFFFF', $events[0]->cardBackgroundHex());

$handler->handle($command);
$this->assertCount(1, $events);
self::assertCount(1, $events);
}

public function testValidPaymentCycles()
public function testValidPaymentCycles(): void
{
$this->handlePaymentCycleAndRewardWithDefaultValues('monthly', 'cashback');
$this->handlePaymentCycleAndRewardWithDefaultValues('quarterly', 'cashback');
}

public function testValidRewards()
public function testValidRewards(): void
{
$this->handlePaymentCycleAndRewardWithDefaultValues('monthly', 'cashback');
$this->handlePaymentCycleAndRewardWithDefaultValues('monthly', 'points');
$this->handlePaymentCycleAndRewardWithDefaultValues('monthly', 'no_reward');
}

public function testInvalidPaymentCycle()
public function testInvalidPaymentCycle(): void
{
$this->expectException(InvalidPaymentCycle::class);
$this->handlePaymentCycleAndRewardWithDefaultValues('what', 'cashback');
}

public function testInvalidReward()
public function testInvalidReward(): void
{
$this->expectException(InvalidReward::class);
$this->handlePaymentCycleAndRewardWithDefaultValues('monthly', 'what');
Expand All @@ -82,15 +82,15 @@ public function handlePaymentCycleAndRewardWithDefaultValues(string $paymentCycl
$command = new DefineProductCommand();
$command->productIdentifierForAggregateIdHash = 'some-hash';
$command->name = 'Test Product';
$command->interestInBasisPoints = 1500;
$command->annualFeeInCents = 5000;
$command->interestInBasisPoints = 1_500;
$command->annualFeeInCents = 5_000;
$command->paymentCycle = $paymentCycle;
$command->creditLimitInCents = 100000;
$command->maxBalanceTransferAllowedInCents = 50000;
$command->creditLimitInCents = 100_000;
$command->maxBalanceTransferAllowedInCents = 50_000;
$command->reward = $reward;
$command->cardBackgroundHex = '#FFFFFF';

$handler->handle($command);
Assert::assertCount(1, $eventStore->storedEvents());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Tests\Galeas\Api\UnitAndIntegration\BoundedContext\CreditCardProduct\Product\Event;

use Galeas\Api\BoundedContext\CreditCardProduct\Product\Aggregate\Product;
Expand All @@ -14,7 +16,7 @@

class ProductActivatedTest extends TestCase
{
public function testNewProductActivatedEvent()
public function testNewProductActivatedEvent(): void
{
$eventId = Id::createNew();
$aggregateId = Id::createNew();
Expand Down Expand Up @@ -42,7 +44,7 @@ public function testNewProductActivatedEvent()
$causationId,
$correlationId,
$recordedOn,
$metadata
$metadata,
],
[
$event->eventId(),
Expand All @@ -51,12 +53,12 @@ public function testNewProductActivatedEvent()
$event->causationId(),
$event->correlationId(),
$event->recordedOn(),
$event->metadata()
$event->metadata(),
]
);
}

public function testTransformProduct()
public function testTransformProduct(): void
{
$eventId = Id::createNew();
$aggregateId = Id::createNew();
Expand All @@ -80,11 +82,11 @@ public function testTransformProduct()
$aggregateId,
1,
'Test Product',
1500,
5000,
1_500,
5_000,
PaymentCycle::fromProperties(Monthly::fromProperties()),
100000,
50000,
100_000,
50_000,
Reward::fromProperties(Points::fromProperties()),
'#FFFFFF',
false
Expand All @@ -104,7 +106,7 @@ public function testTransformProduct()
$product->maxBalanceTransferAllowedInCents(),
$product->reward(),
$product->cardBackgroundHex(),
true
true,
],
[
$transformedProduct->aggregateId(),
Expand All @@ -117,8 +119,8 @@ public function testTransformProduct()
$transformedProduct->maxBalanceTransferAllowedInCents(),
$transformedProduct->reward(),
$transformedProduct->cardBackgroundHex(),
$transformedProduct->isActive()
$transformedProduct->isActive(),
]
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

declare(strict_types=1);

namespace Tests\Galeas\Api\UnitAndIntegration\BoundedContext\CreditCardProduct\Product\Event;

use Galeas\Api\BoundedContext\CreditCardProduct\Product\Aggregate\Product;
use Galeas\Api\BoundedContext\CreditCardProduct\Product\Event\ProductActivated;
use Galeas\Api\BoundedContext\CreditCardProduct\Product\Event\ProductDeactivated;
use Galeas\Api\BoundedContext\CreditCardProduct\Product\ValueObject\Monthly;
use Galeas\Api\BoundedContext\CreditCardProduct\Product\ValueObject\PaymentCycle;
Expand All @@ -15,7 +16,7 @@

class ProductDeactivatedTest extends TestCase
{
public function testNewProductActivatedEvent()
public function testNewProductActivatedEvent(): void
{
$eventId = Id::createNew();
$aggregateId = Id::createNew();
Expand Down Expand Up @@ -43,7 +44,7 @@ public function testNewProductActivatedEvent()
$causationId,
$correlationId,
$recordedOn,
$metadata
$metadata,
],
[
$event->eventId(),
Expand All @@ -52,12 +53,12 @@ public function testNewProductActivatedEvent()
$event->causationId(),
$event->correlationId(),
$event->recordedOn(),
$event->metadata()
$event->metadata(),
]
);
}

public function testTransformProduct()
public function testTransformProduct(): void
{
$eventId = Id::createNew();
$aggregateId = Id::createNew();
Expand All @@ -81,11 +82,11 @@ public function testTransformProduct()
$aggregateId,
1,
'Test Product',
1500,
5000,
1_500,
5_000,
PaymentCycle::fromProperties(Monthly::fromProperties()),
100000,
50000,
100_000,
50_000,
Reward::fromProperties(Points::fromProperties()),
'#FFFFFF',
true
Expand All @@ -105,7 +106,7 @@ public function testTransformProduct()
$product->maxBalanceTransferAllowedInCents(),
$product->reward(),
$product->cardBackgroundHex(),
false
false,
],
[
$transformedProduct->aggregateId(),
Expand All @@ -118,8 +119,8 @@ public function testTransformProduct()
$transformedProduct->maxBalanceTransferAllowedInCents(),
$transformedProduct->reward(),
$transformedProduct->cardBackgroundHex(),
$transformedProduct->isActive()
$transformedProduct->isActive(),
]
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Tests\Galeas\Api\UnitAndIntegration\BoundedContext\CreditCardProduct\Product\Event;

use Galeas\Api\BoundedContext\CreditCardProduct\Product\Event\ProductDefined;
Expand All @@ -13,21 +15,21 @@

class ProductDefinedTest extends TestCase
{
public function testNewProductDefinedEvent()
public function testNewProductDefinedEvent(): void
{
$eventId = Id::createNew();
$aggregateId = Id::createNew();
$aggregateVersion = 1;
$causationId = Id::createNew();
$correlationId = Id::createNew();
$recordedOn = new \DateTimeImmutable();
$metadata = ['bla'=>'ble'];
$metadata = ['bla' => 'ble'];
$name = 'Test Product';
$interestInBasisPoints = 1500;
$annualFeeInCents = 5000;
$interestInBasisPoints = 1_500;
$annualFeeInCents = 5_000;
$paymentCycle = 'monthly';
$creditLimitInCents = 100000;
$maxBalanceTransferAllowedInCents = 50000;
$creditLimitInCents = 100_000;
$maxBalanceTransferAllowedInCents = 50_000;
$reward = 'points';
$cardBackgroundHex = '#FFFFFF';

Expand Down Expand Up @@ -64,7 +66,7 @@ public function testNewProductDefinedEvent()
$creditLimitInCents,
$maxBalanceTransferAllowedInCents,
$reward,
$cardBackgroundHex
$cardBackgroundHex,
],
[
$event->eventId(),
Expand All @@ -81,12 +83,12 @@ public function testNewProductDefinedEvent()
$event->creditLimitInCents(),
$event->maxBalanceTransferAllowedInCents(),
$event->reward(),
$event->cardBackgroundHex()
$event->cardBackgroundHex(),
]
);
}

public function testCreateProduct()
public function testCreateProduct(): void
{
$eventId = Id::createNew();
$aggregateId = Id::createNew();
Expand All @@ -96,11 +98,11 @@ public function testCreateProduct()
$recordedOn = new \DateTimeImmutable();
$metadata = [];
$name = 'Test Product';
$interestInBasisPoints = 1500;
$annualFeeInCents = 5000;
$interestInBasisPoints = 1_500;
$annualFeeInCents = 5_000;
$paymentCycle = 'monthly';
$creditLimitInCents = 100000;
$maxBalanceTransferAllowedInCents = 50000;
$creditLimitInCents = 100_000;
$maxBalanceTransferAllowedInCents = 50_000;
$reward = 'points';
$cardBackgroundHex = '#FFFFFF';

Expand Down Expand Up @@ -136,7 +138,7 @@ public function testCreateProduct()
$maxBalanceTransferAllowedInCents,
Reward::fromProperties(Points::fromProperties()),
$cardBackgroundHex,
false
false,
],
[
$product->aggregateId(),
Expand All @@ -149,8 +151,8 @@ public function testCreateProduct()
$product->maxBalanceTransferAllowedInCents(),
$product->reward(),
$product->cardBackgroundHex(),
$product->isActive()
$product->isActive(),
]
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ public function testListProducts(): void
$listProductsService->list()
);
}
}
}
Loading

0 comments on commit 148ab8c

Please sign in to comment.