|
| 1 | +import { OpenRouterErrorResponseSchema } from "./error-response"; |
| 2 | + |
| 3 | +describe("OpenRouterErrorResponseSchema", () => { |
| 4 | + it("should be valid without a type, code, and param", () => { |
| 5 | + const errorWithoutTypeCodeAndParam = { |
| 6 | + error: { |
| 7 | + message: "Example error message", |
| 8 | + metadata: { provider_name: "Morph" }, |
| 9 | + }, |
| 10 | + user_id: "example_1", |
| 11 | + }; |
| 12 | + |
| 13 | + const result = OpenRouterErrorResponseSchema.parse( |
| 14 | + errorWithoutTypeCodeAndParam |
| 15 | + ); |
| 16 | + |
| 17 | + expect(result).toEqual({ |
| 18 | + error: { |
| 19 | + message: "Example error message", |
| 20 | + code: null, |
| 21 | + type: null, |
| 22 | + param: null, |
| 23 | + }, |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + it("should be invalid with a type", () => { |
| 28 | + const errorWithType = { |
| 29 | + error: { |
| 30 | + message: "Example error message with type", |
| 31 | + type: "invalid_request_error", |
| 32 | + code: 400, |
| 33 | + param: "canBeAnything", |
| 34 | + metadata: { provider_name: "Morph" }, |
| 35 | + }, |
| 36 | + }; |
| 37 | + |
| 38 | + const result = OpenRouterErrorResponseSchema.parse(errorWithType); |
| 39 | + |
| 40 | + expect(result).toEqual({ |
| 41 | + error: { |
| 42 | + code: 400, |
| 43 | + message: "Example error message with type", |
| 44 | + type: "invalid_request_error", |
| 45 | + param: "canBeAnything", |
| 46 | + }, |
| 47 | + }); |
| 48 | + }); |
| 49 | +}); |
0 commit comments