-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestionDocumentTest.php
More file actions
87 lines (63 loc) · 2.54 KB
/
QuestionDocumentTest.php
File metadata and controls
87 lines (63 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace OneOffTech\LibrarianClient\Tests\Documents;
use OneOffTech\LibrarianClient\Dto\Question;
use OneOffTech\LibrarianClient\Requests\Document\QuestionDocumentRequest;
use OneOffTech\LibrarianClient\Tests\Base;
use Saloon\Http\Faking\MockClient;
use Saloon\Http\Faking\MockResponse;
use Saloon\Http\Request;
class QuestionDocumentTest extends Base
{
public function test_question_asked_to_document(): void
{
$mockClient = MockClient::global([
QuestionDocumentRequest::class => MockResponse::fixture('document-question'),
]);
$connector = $this->connector($mockClient);
$question = new Question(
id: 'question-id',
language: 'en',
text: 'This is a question',
);
$answer = $connector->documents('localhost')->ask('d-1', $question);
$this->assertEquals('question-id', $answer->id);
$this->assertEquals('en', $answer->lang);
$this->assertEquals('The answer.', $answer->text);
$this->assertEquals([
[
'id' => 'd1',
'page_number' => 20,
'score' => 0.5881791,
'bounding_box' => null,
'text' => 'The chunk that lead to this reference',
],
], $answer->refs);
$mockClient->assertSent(QuestionDocumentRequest::class);
$mockClient->assertSentCount(1);
$mockClient->assertSent(function (Request $request) {
return $request->resolveEndpoint() === '/library/localhost/documents/d-1/questions';
});
}
public function test_answer_with_no_references(): void
{
$mockClient = MockClient::global([
QuestionDocumentRequest::class => MockResponse::fixture('document-question-no-refs'),
]);
$connector = $this->connector($mockClient);
$question = new Question(
id: 'question-id',
language: 'en',
text: 'This is a question',
);
$answer = $connector->documents('localhost')->ask('d-1', $question);
$this->assertEquals('question-id', $answer->id);
$this->assertEquals('en', $answer->lang);
$this->assertEquals('The answer.', $answer->text);
$this->assertEmpty($answer->refs);
$mockClient->assertSent(QuestionDocumentRequest::class);
$mockClient->assertSentCount(1);
$mockClient->assertSent(function (Request $request) {
return $request->resolveEndpoint() === '/library/localhost/documents/d-1/questions';
});
}
}