Skip to content

Commit

Permalink
moving in the tests I had from the other app
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Feb 3, 2023
1 parent 4bec472 commit 65d2d8a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ImageClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public function images($phrase): ImagesResponseDto|\Exception
throw new \Exception('Error with response');
}

$dto = new ImagesResponseDto($response->json());
$data = $response->json();
$dto = new ImagesResponseDto($data);

return $dto;
}
Expand Down
36 changes: 36 additions & 0 deletions tests/ImageClientMockTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Alnutile\LaravelChatgpt\Tests;

use Alnutile\LaravelChatgpt\DTOs\ImageResponseDto;
use Alnutile\LaravelChatgpt\DTOs\ImagesResponseDto;
use Alnutile\LaravelChatgpt\ImageClientMock;
use Illuminate\Support\Facades\File;

class ImageClientMockTest extends TestCase
{
public function test_mock()
{
$data = <<<'EOD'
{
"created": 1674065330,
"data": [
{
"url": "https://oaidalleapiprodscus.blob.core.windows.net/private/org-ClL1biAi0m1pC2J2IV5C22TQ/user-i08oJb4T3Lhnsh2yJsoErWJ4/img-5CGVUOpH2HsRdB7zVWeJSufj.png?st=2023-01-18T17%3A08%3A50Z&se=2023-01-18T19%3A08%3A50Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-01-18T15%3A37%3A27Z&ske=2023-01-19T15%3A37%3A27Z&sks=b&skv=2021-08-06&sig=1guBf9z2zX%2BUNiBGs7IT61YmKcmv7%2BHKL1zHxzNKcQc%3D"
},
{
"url": "https://oaidalleapiprodscus.blob.core.windows.net/private/org-ClL1biAi0m1pC2J2IV5C22TQ/user-i08oJb4T3Lhnsh2yJsoErWJ4/img-GkcQxoVIH1BWlml3uMJjxlNt.png?st=2023-01-18T17%3A08%3A50Z&se=2023-01-18T19%3A08%3A50Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-01-18T15%3A37%3A27Z&ske=2023-01-19T15%3A37%3A27Z&sks=b&skv=2021-08-06&sig=o9wlRNNJZW4GPBJo74gKn%2BXX8WSq47DL9QSf/agD9Ws%3D"
}
]
}
EOD;

File::shouldReceive('get')->andReturn($data);

$results = (new ImageClientMock())->images('foo');

$this->assertInstanceOf(ImagesResponseDto::class, $results);
$this->assertInstanceOf(ImageResponseDto::class,
$results->images[0]);
}
}
28 changes: 28 additions & 0 deletions tests/ImageClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Alnutile\LaravelChatgpt\Tests;

use Alnutile\LaravelChatgpt\DTOs\ImagesResponseDto;
use Alnutile\LaravelChatgpt\ImageClient;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Http;

class ImageClientTest extends TestCase
{
public function test_client()
{
$data = File::get(__DIR__.'/fixtures/image_response.json');
$data = json_decode($data, true);

Http::fake(
[
'api.openai.com/*' => Http::response($data, 200),
]
);

$results = (new ImageClient())->images('Bob Belcher');
$this->assertNotEmpty($results);
$this->assertInstanceOf(ImagesResponseDto::class, $results);
Http::assertSentCount(1);
}
}

0 comments on commit 65d2d8a

Please sign in to comment.