From 064fe0ba8b72f6ae04c3cfe0adee9d6337847d73 Mon Sep 17 00:00:00 2001 From: Faruk Nasir Date: Fri, 5 Nov 2021 00:22:15 +0100 Subject: [PATCH] test: passing --- .phpunit.result.cache | 2 +- build/report.junit.xml | 36 +++++++++------- src/API/Transaction.php | 4 +- src/Options/TransactionFeeOptions.php | 30 ++++++++------ tests/ChargeTest.php | 8 ++-- tests/SubscriptionTest.php | 12 +++--- tests/TransactionTest.php | 60 ++++++++++++++++++++++++++- 7 files changed, 108 insertions(+), 44 deletions(-) diff --git a/.phpunit.result.cache b/.phpunit.result.cache index 90030fc..6189177 100644 --- a/.phpunit.result.cache +++ b/.phpunit.result.cache @@ -1 +1 @@ -{"version":1,"defects":{"StarfolkSoftware\\Flutterwave\\Tests\\PlanTest::testPlanCanBeCreated":4,"StarfolkSoftware\\Flutterwave\\Tests\\PlanTest::testPlanCanBeUpdated":4,"StarfolkSoftware\\Flutterwave\\Tests\\SubscriptionTest::testSubscriptionsCanBeRetrieved":4,"StarfolkSoftware\\Flutterwave\\Tests\\ChargeTest::testCanPerformTokenizedCharges":4,"StarfolkSoftware\\Flutterwave\\Tests\\TransactionTest::testTransactionsCanBeRetrieved":4},"times":{"StarfolkSoftware\\Flutterwave\\Tests\\PlanTest::testPlanCanBeCreated":0.001,"StarfolkSoftware\\Flutterwave\\Tests\\PlanTest::testPlansCanBeRetrieved":0,"StarfolkSoftware\\Flutterwave\\Tests\\PlanTest::testPlanCanBeFound":0.001,"StarfolkSoftware\\Flutterwave\\Tests\\PlanTest::testPlanCanBeCancelled":0.001,"StarfolkSoftware\\Flutterwave\\Tests\\PlanTest::testPlanCanBeUpdated":0.001,"StarfolkSoftware\\Flutterwave\\Tests\\SubscriptionTest::testSubscriptionsCanBeRetrieved":0.001,"StarfolkSoftware\\Flutterwave\\Tests\\SubscriptionTest::testSubscriptionCanBeCancelled":0,"StarfolkSoftware\\Flutterwave\\Tests\\SubscriptionTest::testSubscriptionCanBeActivated":0.001,"StarfolkSoftware\\Flutterwave\\Tests\\ChargeTest::testCanPerformTokenizedCharges":0.001,"StarfolkSoftware\\Flutterwave\\Tests\\ChargeTest::testCanUpdateCustomerToken":0.003,"StarfolkSoftware\\Flutterwave\\Tests\\TransactionTest::testTransactionsCanBeRetrieved":0.077}} \ No newline at end of file +{"version":1,"defects":{"StarfolkSoftware\\Flutterwave\\Tests\\PlanTest::testPlanCanBeCreated":4,"StarfolkSoftware\\Flutterwave\\Tests\\PlanTest::testPlanCanBeUpdated":4,"StarfolkSoftware\\Flutterwave\\Tests\\SubscriptionTest::testSubscriptionsCanBeRetrieved":4,"StarfolkSoftware\\Flutterwave\\Tests\\ChargeTest::testCanPerformTokenizedCharges":4,"StarfolkSoftware\\Flutterwave\\Tests\\TransactionTest::testTransactionsCanBeRetrieved":4,"StarfolkSoftware\\Flutterwave\\Tests\\TransactionTest::testTransactionFeeCanBeRetrieved":4},"times":{"StarfolkSoftware\\Flutterwave\\Tests\\PlanTest::testPlanCanBeCreated":0,"StarfolkSoftware\\Flutterwave\\Tests\\PlanTest::testPlansCanBeRetrieved":0,"StarfolkSoftware\\Flutterwave\\Tests\\PlanTest::testPlanCanBeFound":0,"StarfolkSoftware\\Flutterwave\\Tests\\PlanTest::testPlanCanBeCancelled":0,"StarfolkSoftware\\Flutterwave\\Tests\\PlanTest::testPlanCanBeUpdated":0.009,"StarfolkSoftware\\Flutterwave\\Tests\\SubscriptionTest::testSubscriptionsCanBeRetrieved":0,"StarfolkSoftware\\Flutterwave\\Tests\\SubscriptionTest::testSubscriptionCanBeCancelled":0,"StarfolkSoftware\\Flutterwave\\Tests\\SubscriptionTest::testSubscriptionCanBeActivated":0,"StarfolkSoftware\\Flutterwave\\Tests\\ChargeTest::testCanPerformTokenizedCharges":0,"StarfolkSoftware\\Flutterwave\\Tests\\ChargeTest::testCanUpdateCustomerToken":0,"StarfolkSoftware\\Flutterwave\\Tests\\TransactionTest::testTransactionsCanBeRetrieved":0,"StarfolkSoftware\\Flutterwave\\Tests\\TransactionTest::testTransactionFeeCanBeRetrieved":0,"StarfolkSoftware\\Flutterwave\\Tests\\TransactionTest::testWebhookCanBeResent":0,"StarfolkSoftware\\Flutterwave\\Tests\\TransactionTest::testTransactionCanBeVerified":0,"StarfolkSoftware\\Flutterwave\\Tests\\TransactionTest::testTransactionTimelineCanBeRetrieved":0}} \ No newline at end of file diff --git a/build/report.junit.xml b/build/report.junit.xml index e6a24cf..5e1bce5 100644 --- a/build/report.junit.xml +++ b/build/report.junit.xml @@ -1,24 +1,28 @@ - - - + + + + + + + - - - + + + + - - - - + + + + + + - - - - - - + + + diff --git a/src/API/Transaction.php b/src/API/Transaction.php index 33804c9..76a2c5b 100644 --- a/src/API/Transaction.php +++ b/src/API/Transaction.php @@ -35,7 +35,7 @@ public function all(TransactionQueryParams $params): array public function fee(TransactionFeeOptions $options): array { $response = $this->httpClient->get('/transactions/fee', [ - 'query' => $options + 'query' => $options->all() ]); return ResponseMediator::getContent($response); @@ -48,7 +48,7 @@ public function fee(TransactionFeeOptions $options): array * * @return array */ - public function resendWebhook(int $id, int $wait = 1): array + public function webhook(int $id, int $wait = 1): array { $response = $this->httpClient->post("/transactions/{$id}/resend-webhook", [ 'query' => [ diff --git a/src/Options/TransactionFeeOptions.php b/src/Options/TransactionFeeOptions.php index 34e4c10..55dfc40 100644 --- a/src/Options/TransactionFeeOptions.php +++ b/src/Options/TransactionFeeOptions.php @@ -16,20 +16,24 @@ final class TransactionFeeOptions extends OptionsAbstract */ public function configureOptions(OptionsResolver $resolver): void { - $resolver->setDefaults([]); + $resolver->define('amount') + ->required() + ->allowedTypes('int') + ->info('The amount of the transaction fee in kobo'); - $resolver->setRequired(['amount', 'currency']); + $resolver->define('currency') + ->required() + ->allowedTypes('string') + ->info('The currency of the transaction fee'); - $resolver->setAllowedTypes('amount', 'int'); - $resolver->setAllowedTypes('currency', 'string'); - $resolver->setAllowedTypes('payment_type', 'string'); - $resolver->setAllowedValues('payment_type', [ - 'card', - 'debit_ng_account', - 'mobilemoney', - 'bank_transfer', - 'ach_payment' - ]); - $resolver->setAllowedTypes('card_first6digits', 'int'); + $resolver->define('payment_type') + ->default('card') + ->allowedTypes('string') + ->allowedValues('card', 'debit_ng_account', 'mobilemoney', 'bank_transfer', 'ach_payment') + ->info('The payment type of the transaction fee'); + + $resolver->define('card_first6digits') + ->allowedTypes('string') + ->info('The first 6 digits of the card used to pay the transaction fee'); } } diff --git a/tests/ChargeTest.php b/tests/ChargeTest.php index 4045c01..9bc8bc1 100644 --- a/tests/ChargeTest.php +++ b/tests/ChargeTest.php @@ -14,7 +14,7 @@ public function testCanPerformTokenizedCharges(): void "status" => "success", ]))->withStatus(200)); - $plan = $this->client()->charge()->withToken( + $charge = $this->client()->charge()->withToken( new ChargeWithTokenOptions([ 'token' => 'abc', 'email' => 'contact@starfolksoftware.com', @@ -25,7 +25,7 @@ public function testCanPerformTokenizedCharges(): void ]) ); - $this->assertEquals('success', $plan['status']); + $this->assertEquals('success', $charge['status']); } public function testCanUpdateCustomerToken(): void @@ -34,7 +34,7 @@ public function testCanUpdateCustomerToken(): void "status" => "success", ]))->withStatus(200)); - $plan = $this->client()->charge()->updateCustomerToken( + $charge = $this->client()->charge()->updateCustomerToken( token: 124343, options: new UpdateCustomerTokenOptions([ 'email' => 'contact@starfolksoftware.com', @@ -44,6 +44,6 @@ public function testCanUpdateCustomerToken(): void ]) ); - $this->assertEquals('success', $plan['status']); + $this->assertEquals('success', $charge['status']); } } \ No newline at end of file diff --git a/tests/SubscriptionTest.php b/tests/SubscriptionTest.php index bca6826..15c766e 100644 --- a/tests/SubscriptionTest.php +++ b/tests/SubscriptionTest.php @@ -13,11 +13,11 @@ public function testSubscriptionsCanBeRetrieved(): void "status" => "success", ]))->withStatus(200)); - $plan = $this->client()->subscription()->all( + $subscription = $this->client()->subscription()->all( new SubscriptionQueryParams([]) ); - $this->assertEquals('success', $plan['status']); + $this->assertEquals('success', $subscription['status']); } public function testSubscriptionCanBeCancelled(): void @@ -26,9 +26,9 @@ public function testSubscriptionCanBeCancelled(): void "status" => "success", ]))->withStatus(200)); - $plan = $this->client()->subscription()->cancel(1); + $subscription = $this->client()->subscription()->cancel(1); - $this->assertEquals('success', $plan['status']); + $this->assertEquals('success', $subscription['status']); } public function testSubscriptionCanBeActivated(): void @@ -37,8 +37,8 @@ public function testSubscriptionCanBeActivated(): void "status" => "success", ]))->withStatus(200)); - $plan = $this->client()->subscription()->activate(1); + $subscription = $this->client()->subscription()->activate(1); - $this->assertEquals('success', $plan['status']); + $this->assertEquals('success', $subscription['status']); } } \ No newline at end of file diff --git a/tests/TransactionTest.php b/tests/TransactionTest.php index 369241b..676a45c 100644 --- a/tests/TransactionTest.php +++ b/tests/TransactionTest.php @@ -3,6 +3,7 @@ namespace StarfolkSoftware\Flutterwave\Tests; use Laminas\Diactoros\Response\JsonResponse; +use StarfolkSoftware\Flutterwave\Options\TransactionFeeOptions; use StarfolkSoftware\Flutterwave\Options\TransactionQueryParams; final class TransactionTest extends TestCase @@ -13,10 +14,65 @@ public function testTransactionsCanBeRetrieved(): void "status" => "success", ]))->withStatus(200)); - $plan = $this->client()->transaction()->all( + $transaction = $this->client()->transaction()->all( params: new TransactionQueryParams([]) ); - $this->assertEquals('success', $plan['status']); + $this->assertEquals('success', $transaction['status']); + } + + public function testTransactionFeeCanBeRetrieved(): void + { + $this->mockClient->addResponse((new JsonResponse([ + "status" => "success", + ]))->withStatus(200)); + + $transaction = $this->client()->transaction()->fee( + options: new TransactionFeeOptions([ + 'amount' => 10000, + 'currency' => 'NGN', + ]) + ); + + $this->assertEquals('success', $transaction['status']); + } + + public function testWebhookCanBeResent(): void + { + $this->mockClient->addResponse((new JsonResponse([ + "status" => "success", + ]))->withStatus(200)); + + $transaction = $this->client()->transaction()->webhook( + id: 12345 + ); + + $this->assertEquals('success', $transaction['status']); + } + + public function testTransactionCanBeVerified(): void + { + $this->mockClient->addResponse((new JsonResponse([ + "status" => "success", + ]))->withStatus(200)); + + $transaction = $this->client()->transaction()->verify( + id: 12345 + ); + + $this->assertEquals('success', $transaction['status']); + } + + public function testTransactionTimelineCanBeRetrieved(): void + { + $this->mockClient->addResponse((new JsonResponse([ + "status" => "success", + ]))->withStatus(200)); + + $transaction = $this->client()->transaction()->timeline( + id: 12345 + ); + + $this->assertEquals('success', $transaction['status']); } }