@@ -37,7 +37,7 @@ func testContract(t *testing.T, when spec.G, it spec.S) {
37
37
})
38
38
39
39
when ("accessing the completion endpoint" , func () {
40
- it ("should have the expected keys in the response " , func () {
40
+ it ("should return a successful response with expected keys " , func () {
41
41
body := types.CompletionsRequest {
42
42
Messages : []types.Message {{
43
43
Role : client .SystemRole ,
@@ -64,6 +64,34 @@ func testContract(t *testing.T, when spec.G, it spec.S) {
64
64
Expect (data .Usage ).ShouldNot (BeNil (), "Expected Usage to be present in the response" )
65
65
Expect (data .Choices ).ShouldNot (BeNil (), "Expected Choices to be present in the response" )
66
66
})
67
+
68
+ it ("should return an error response with appropriate error details" , func () {
69
+ // Set the wrong API key
70
+ restCaller .SetAPIKey ("wrong-key" )
71
+
72
+ body := types.CompletionsRequest {
73
+ Messages : []types.Message {{
74
+ Role : client .SystemRole ,
75
+ Content : defaults .Role ,
76
+ }},
77
+ Model : defaults .Model ,
78
+ Stream : false ,
79
+ }
80
+
81
+ bytes , err := json .Marshal (body )
82
+ Expect (err ).NotTo (HaveOccurred ())
83
+
84
+ resp , err := restCaller .Post (defaults .URL + defaults .CompletionsPath , bytes , false )
85
+ Expect (err ).To (HaveOccurred ())
86
+
87
+ var errorData types.ErrorResponse
88
+ err = json .Unmarshal (resp , & errorData )
89
+ Expect (err ).NotTo (HaveOccurred ())
90
+
91
+ Expect (errorData .Error .Message ).ShouldNot (BeEmpty (), "Expected error message to be present in the response" )
92
+ Expect (errorData .Error .Type ).ShouldNot (BeEmpty (), "Expected error type to be present in the response" )
93
+ Expect (errorData .Error .Code ).ShouldNot (BeEmpty (), "Expected error code to be present in the response" )
94
+ })
67
95
})
68
96
69
97
when ("accessing the models endpoint" , func () {
0 commit comments