Skip to content

Commit 1f8302f

Browse files
committed
test(OpenAI): add assertion for invalid_request_error
1 parent eab26e6 commit 1f8302f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/Transporters/HttpTransporter.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,34 @@
112112
});
113113
})->with('request methods');
114114

115+
test('request object mismatched project error', function (string $requestMethod) {
116+
$payload = Payload::list('models');
117+
118+
$response = new Response(401, ['Content-Type' => 'application/json; charset=utf-8'], json_encode([
119+
'error' => [
120+
'message' => 'OpenAI-Project header should match project for API key',
121+
'type' => 'invalid_request_error',
122+
'code' => 'mismatched_project',
123+
'param' => null,
124+
],
125+
'status' => 401
126+
]));
127+
128+
$this->client
129+
->shouldReceive('sendRequest')
130+
->once()
131+
->andReturn($response);
132+
133+
expect(fn () => $this->http->$requestMethod($payload))
134+
->toThrow(function (ErrorException $e) {
135+
expect($e->getMessage())->toBe('OpenAI-Project header should match project for API key')
136+
->and($e->getErrorMessage())->toBe('OpenAI-Project header should match project for API key')
137+
->and($e->getErrorCode())->toBe('mismatched_project')
138+
->and($e->getErrorType())->toBe('invalid_request_error')
139+
->and($e->getStatusCode())->toBe(401);
140+
});
141+
})->with('request methods');
142+
115143
test('request object server errors', function () {
116144
$payload = Payload::create('completions', ['model' => 'gpt-4']);
117145

0 commit comments

Comments
 (0)