Skip to content

Commit

Permalink
Paper cuts
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelMwangiW committed Aug 5, 2023
1 parent e980fe3 commit 7a9f351
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/Enum/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
enum Status: string
{
case INSUFFICIENT_BALANCE = 'InsufficientBalance';
case INVALID_REQUEST = 'InvalidRequest';
case NOT_SUPPORTED = 'NotSupported';
case INCOMPLETE = 'Incomplete';
case SUBMITTED = 'Submitted';
case BUFFERED = 'Buffered';
Expand Down
2 changes: 1 addition & 1 deletion src/Saloon/Requests/Payment/WalletBalanceRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class WalletBalanceRequest extends BaseRequest
{
use HasJsonBody;

public Service $service = Service::PAYMENT;
public Service $service = Service::DATA;
protected Method $method = Method::GET;

public function resolveEndpoint(): string
Expand Down
7 changes: 4 additions & 3 deletions src/ValueObjects/DataBundlesResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ public static function fromResponse(Response $response): DataBundlesResponse
->map(function (array $entry) {
return new DataBundlesResponseEntry(
number: PhoneNumber::make(data_get($entry, 'phoneNumber')),
provider: data_get($entry, 'provider'),
provider: data_get($entry, 'provider','Athena'),
status: Status::from(data_get($entry, 'status')),
transactionId: data_get($entry, 'transactionId'),
value: Money::make(data_get($entry, 'value'))
transactionId: data_get($entry, 'transactionId','InvalidRequest'),
value: Money::make(data_get($entry, 'value','USD 0.0')),
errorMessage: data_get($entry, 'errorMessage'),
);
});

Expand Down
3 changes: 2 additions & 1 deletion src/ValueObjects/DataBundlesResponseEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public function __construct(
public readonly string $provider,
public readonly Status $status,
public readonly string $transactionId,
public readonly Money $value
public readonly Money $value,
public readonly string|null $errorMessage = null
) {
}

Expand Down
31 changes: 27 additions & 4 deletions tests/MobileDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
use SamuelMwangiW\Africastalking\ValueObjects\MobileDataTransaction;

it('can be resolved')
->expect(fn () => africastalking()->mobileData())
->expect(fn() => africastalking()->mobileData())
->toBeInstanceOf(MobileData::class);

it('can be resolved via the Facade')
->expect(fn () => Africastalking::mobileData())
->expect(fn() => Africastalking::mobileData())
->toBeInstanceOf(MobileData::class);

it('can be resolved via bundles alias')
->expect(fn () => africastalking()->bundles())
->expect(fn() => africastalking()->bundles())
->toBeInstanceOf(MobileData::class);

it('sends idempotency requests')
->expect(
fn () => app(MobileData::class)->idempotent('key_123')
fn() => app(MobileData::class)->idempotent('key_123')
)->toBeInstanceOf(MobileData::class)
->idempotencyKey()->toBe('key_123');

Expand Down Expand Up @@ -158,3 +158,26 @@
->entries->toHaveCount(3)
->each->toBeInstanceOf(DataBundlesResponseEntry::class);
})->with('phone-numbers');

it('defaults values for an invalid request', function (): void {
Saloon::fake([
SendRequest::class => MockResponse::fixture('mobile-data/invalid'),
]);

$object = app(MobileData::class);
$result = $object
->to(
phoneNumber: fake()->e164PhoneNumber(),
quantity: 7,
validity: BundlesValidity::DAILY
)->idempotent(key: fake()->uuid())
->send();

expect($result)
->toBeInstanceOf(DataBundlesResponse::class)
->entries->toHaveCount(1)
->each->toBeInstanceOf(DataBundlesResponseEntry::class)
->and($result->entries->first())
->provider->toBe('Athena')
->transactionId->toBe('InvalidRequest');
});

0 comments on commit 7a9f351

Please sign in to comment.