@@ -5,7 +5,7 @@ import org.scalatest.flatspec.AnyFlatSpec
5
5
import org .scalatest .matchers .should .Matchers
6
6
import sttp .openai .fixtures .BatchFixture
7
7
import sttp .openai .json .{SnakePickle , SttpUpickleApiExtension }
8
- import sttp .openai .requests .batch .{BatchRequestBody , BatchResponse , RequestCounts }
8
+ import sttp .openai .requests .batch .{BatchRequestBody , BatchResponse , ListBatchResponse }
9
9
10
10
class BatchDataSpec extends AnyFlatSpec with Matchers with EitherValues {
11
11
@@ -27,32 +27,29 @@ class BatchDataSpec extends AnyFlatSpec with Matchers with EitherValues {
27
27
" Given create batch response as Json" should " be properly deserialized to case class" in {
28
28
// given
29
29
val jsonResponse = BatchFixture .jsonCreateBatchResponse
30
- val expectedResponse : BatchResponse = BatchResponse (
31
- id = " batch_abc123" ,
32
- endpoint = " /v1/completions" ,
33
- errors = None ,
34
- inputFileId = " file-abc123" ,
35
- completionWindow = " 24h" ,
36
- status = " completed" ,
37
- outputFileId = Some (" file-cvaTdG" ),
38
- errorFileId = Some (" file-HOWS94" ),
39
- createdAt = 1711471533 ,
40
- inProgressAt = Some (1711471538 ),
41
- expiresAt = Some (1711557933 ),
42
- finalizingAt = Some (1711493133 ),
43
- completedAt = Some (1711493163 ),
44
- failedAt = None ,
45
- expiredAt = None ,
46
- cancellingAt = None ,
47
- cancelledAt = None ,
48
- requestCounts = Some (RequestCounts (total = 100 , completed = 95 , failed = 5 )),
49
- metadata = Some (Map (" customer_id" -> " user_123456789" , " batch_description" -> " Nightly eval job" ))
50
- )
30
+ val expectedResponse : BatchResponse = BatchFixture .batchResponse
51
31
// when
52
32
val deserializedJsonResponse : Either [Exception , BatchResponse ] =
53
33
SttpUpickleApiExtension .deserializeJsonSnake[BatchResponse ].apply(jsonResponse)
54
34
// then
55
35
deserializedJsonResponse.value shouldBe expectedResponse
56
36
}
57
37
38
+ " Given list batch response as Json" should " be properly deserialized to case class" in {
39
+ // given
40
+ val jsonResponse = BatchFixture .jsonListBatchResponse
41
+ val expectedResponse : ListBatchResponse = ListBatchResponse (
42
+ data = Seq (BatchFixture .batchResponse),
43
+ hasMore = true ,
44
+ firstId = " ftckpt_zc4Q7MP6XxulcVzj4MZdwsAB" ,
45
+ lastId = " ftckpt_enQCFmOTGj3syEpYVhBRLTSy"
46
+ )
47
+ // when
48
+ val deserializedJsonResponse : Either [Exception , ListBatchResponse ] =
49
+ SttpUpickleApiExtension .deserializeJsonSnake[ListBatchResponse ].apply(jsonResponse)
50
+
51
+ // then
52
+ deserializedJsonResponse.value shouldBe expectedResponse
53
+ }
54
+
58
55
}
0 commit comments