Skip to content

Commit

Permalink
feat: adds tests for Lib/Api
Browse files Browse the repository at this point in the history
  • Loading branch information
kajetan-nobel committed Sep 21, 2023
1 parent f365085 commit 7d44a0f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
],
"require": {
"php": "^8.1",
"guzzlehttp/guzzle": "^7.8",
"illuminate/support": "^10.0",
"justinrainbow/json-schema": "^5.2"
},
Expand Down
34 changes: 33 additions & 1 deletion tests/Lib/ApiTest.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
<?php

todo('write tests for @api');
use Illuminate\Http\Client\Request;
use Illuminate\Support\Facades\Http;
use Routegroup\Imoje\Payment\DTO\Request\RefundRequestDto;
use Routegroup\Imoje\Payment\Lib\Api;
use Routegroup\Imoje\Payment\Lib\Utils;

beforeEach(function (): void {
Http::fake();
$this->api = app(Api::class);
$this->utils = app(Utils::class);
});

it('makes refund request', function (): void {
$dto = RefundRequestDto::make(['amount' => 100]);
$this->api->createRefund($dto, '$transaction_id$');

Http::assertSent(function (Request $request) {
return $request->url() === $this->utils->createRefundUrl('$transaction_id$')
&& $request->isJson()
&& $request->method() === 'POST'
&& array_keys($request->data()) === ['type', 'serviceId', 'amount'];
});
});

it('makes deactivate profile request', function (): void {
$this->api->deactivateProfile('$profile_id$');

Http::assertSent(function (Request $request) {
return $request->url() === $this->utils->createDeactivateProfileUrl('$profile_id$')
&& $request->isJson()
&& $request->method() === 'DELETE';
});
});

0 comments on commit 7d44a0f

Please sign in to comment.