Skip to content

Commit

Permalink
WIP: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gehrisandro committed Nov 10, 2023
1 parent 211c668 commit 32fb237
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace OpenAI\Testing\Responses\Fixtures\Threads;

final class ThreadDeleteResponseFixture
{
public const ATTRIBUTES = [
'id' => 'thread_agvtHUGezjTCt4SKgQg0NJ2Y',
'object' => 'thread.deleted',
'deleted' => true,
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace OpenAI\Testing\Responses\Fixtures\Threads;

final class ThreadListResponseFixture
{
public const ATTRIBUTES = [
'object' => 'list',
'data' => [
[
'id' => 'thread_agvtHUGezjTCt4SKgQg0NJ2Y',
'object' => 'thread',
'created_at' => 1_699_621_778,
'metadata' => [],
],
],
'first_id' => 'thread_agvtHUGezjTCt4SKgQg0NJ2Y',
'last_id' => 'thread_agvtHUGezjTCt4SKgQg0NJ2Y',
'has_more' => false,
];
}
13 changes: 13 additions & 0 deletions src/Testing/Responses/Fixtures/Threads/ThreadResponseFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace OpenAI\Testing\Responses\Fixtures\Threads;

final class ThreadResponseFixture
{
public const ATTRIBUTES = [
'id' => 'thread_agvtHUGezjTCt4SKgQg0NJ2Y',
'object' => 'thread',
'created_at' => 1_699_621_778,
'metadata' => [],
];
}
47 changes: 47 additions & 0 deletions tests/Responses/Threads/ThreadDeleteResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

use OpenAI\Responses\Meta\MetaInformation;
use OpenAI\Responses\Threads\ThreadDeleteResponse;

test('from', function () {
$result = ThreadDeleteResponse::from(threadDeleteResource(), meta());

expect($result)
->id->toBe('thread_agvtHUGezjTCt4SKgQg0NJ2Y')
->object->toBe('thread.deleted')
->deleted->toBe(true)
->meta()->toBeInstanceOf(MetaInformation::class);
});

test('as array accessible', function () {
$result = ThreadDeleteResponse::from(threadDeleteResource(), meta());

expect($result['id'])
->toBe('thread_agvtHUGezjTCt4SKgQg0NJ2Y');
});

test('to array', function () {
$result = ThreadDeleteResponse::from(threadDeleteResource(), meta());

expect($result->toArray())
->toBe(threadDeleteResource());
});

test('fake', function () {
$response = ThreadDeleteResponse::fake();

expect($response)
->id->toBe('thread_agvtHUGezjTCt4SKgQg0NJ2Y')
->deleted->toBe(true);
});

test('fake with override', function () {
$response = ThreadDeleteResponse::fake([
'id' => 'thread_1234',
'deleted' => false,
]);

expect($response)
->id->toBe('thread_1234')
->deleted->toBe(false);
});
50 changes: 50 additions & 0 deletions tests/Responses/Threads/ThreadListResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

use OpenAI\Responses\Meta\MetaInformation;
use OpenAI\Responses\Threads\ThreadListResponse;
use OpenAI\Responses\Threads\ThreadResponse;

test('from', function () {
$response = ThreadListResponse::from(threadListResource(), meta());

expect($response)
->toBeInstanceOf(ThreadListResponse::class)
->object->toBe('list')
->data->toBeArray()->toHaveCount(2)
->data->each->toBeInstanceOf(ThreadResponse::class)
->meta()->toBeInstanceOf(MetaInformation::class);
});

test('as array accessible', function () {
$response = ThreadListResponse::from(threadListResource(), meta());

expect($response['object'])->toBe('list');
});

test('to array', function () {
$response = ThreadListResponse::from(threadListResource(), meta());

expect($response->toArray())
->toBeArray()
->toBe(threadListResource());
});

test('fake', function () {
$response = ThreadListResponse::fake();

expect($response['data'][0])
->id->toBe('thread_agvtHUGezjTCt4SKgQg0NJ2Y');
});

test('fake with override', function () {
$response = ThreadListResponse::fake([
'data' => [
[
'id' => 'thread_1234',
],
],
]);

expect($response['data'][0])
->id->toBe('thread_1234');
});
45 changes: 45 additions & 0 deletions tests/Responses/Threads/ThreadResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

use OpenAI\Responses\Meta\MetaInformation;
use OpenAI\Responses\Threads\ThreadResponse;

test('from', function () {
$result = ThreadResponse::from(threadResource(), meta());

expect($result)
->id->toBe('thread_agvtHUGezjTCt4SKgQg0NJ2Y')
->object->toBe('thread')
->createdAt->toBe(1699621778)
->metadata->toBe([])
->meta()->toBeInstanceOf(MetaInformation::class);
});

test('as array accessible', function () {
$result = ThreadResponse::from(threadResource(), meta());

expect($result['id'])
->toBe('thread_agvtHUGezjTCt4SKgQg0NJ2Y');
});

test('to array', function () {
$result = ThreadResponse::from(threadResource(), meta());

expect($result->toArray())
->toBe(threadResource());
});

test('fake', function () {
$response = ThreadResponse::fake();

expect($response)
->id->toBe('thread_agvtHUGezjTCt4SKgQg0NJ2Y');
});

test('fake with override', function () {
$response = ThreadResponse::fake([
'id' => 'thread_1234',
]);

expect($response)
->id->toBe('thread_1234');
});

0 comments on commit 32fb237

Please sign in to comment.