Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverearl committed Nov 30, 2024
1 parent bf51699 commit 45f8200
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
5 changes: 0 additions & 5 deletions tests/ExampleTest.php

This file was deleted.

19 changes: 19 additions & 0 deletions tests/NomiAiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

use Illuminate\Support\Facades\Config;
use Nomiai\PhpSdk\Laravel\Exceptions\NomiaiException;
use Nomiai\PhpSdk\Laravel\Facades\NomiAI;

it('can get a new nomi instance', function (): void {
Config::set('nomiai.api_key', 'token');
$token = NomiAI::token();

expect($token)->toEqual('token');
});

it('will throw an exception if an empty api key is provided', function (): void {
Config::set('nomiai.api_key', '');
$token = NomiAI::endpoint();
})->throws(NomiaiException::class);
28 changes: 28 additions & 0 deletions tests/RequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

use Illuminate\Support\Facades\Http;
use Nomiai\PhpSdk\Enums\Gender;
use Nomiai\PhpSdk\Enums\RelationshipType;
use Nomiai\PhpSdk\Laravel\Facades\NomiAI;
use Nomiai\PhpSdk\Resources\Nomi;

it('can fire a http request and be successfully mocked by laravel', function (): void {
$nomi = Nomi::make([
'uuid' => fake()->uuid(),
'name' => fake()->name(),
'created' => new DateTimeImmutable(),
'gender' => fake()->randomElement(Gender::cases()),
'relationshipType' => fake()->randomElement(RelationshipType::cases()),
]);

Http::preventingStrayRequests();
Http::fake(['*' => Http::response($nomi->toArray())]);

$response = NomiAI::getNomi($nomi->uuid);

expect($response)
->toBeInstanceOf(Nomi::class)
->and($response->toArray())->toEqual($nomi->toArray());
});

0 comments on commit 45f8200

Please sign in to comment.