|
2 | 2 |
|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
4 | 4 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertNull; |
5 | 6 | import static org.junit.jupiter.api.Assertions.assertThrows; |
6 | 7 | import static org.junit.jupiter.api.Assertions.assertTrue; |
7 | 8 |
|
@@ -71,12 +72,30 @@ void throwsFacturapiExceptionWithApiMessage() { |
71 | 72 | assertEquals(400, ex.getStatusCode()); |
72 | 73 | assertTrue(ex.getMessage().contains("Invalid customer")); |
73 | 74 | assertEquals(ApiErrorCodes.RequestErrorCode.INVALID_REQUEST, ex.getErrorCode()); |
74 | | - assertEquals(ApiErrorCodes.RequestErrorCode.INVALID_REQUEST, ex.getApiErrorCode()); |
75 | 75 | assertEquals("customer.tax_id", ex.getErrorPath()); |
76 | 76 | assertEquals("body", ex.getErrorLocation()); |
77 | 77 | assertEquals("log_123", ex.getLogId()); |
78 | 78 | assertEquals("required", ex.getErrors().get(0).get("code").asText()); |
79 | 79 | assertEquals("3", ex.getHeaders().get("Retry-After").get(0)); |
80 | 80 | assertEquals("log_123", ex.getHeaders().get("x-facturapi-log-id").get(0)); |
81 | 81 | } |
| 82 | + |
| 83 | + @Test |
| 84 | + void ignoresNonStringApiErrorCodes() { |
| 85 | + StubHttpClient httpClient = new StubHttpClient(); |
| 86 | + httpClient.enqueueJson(400, "{\"message\":\"Invalid customer\",\"code\":400}"); |
| 87 | + |
| 88 | + FacturapiHttpClient client = new FacturapiHttpClient( |
| 89 | + FacturapiConfig.builder("sk_test_123") |
| 90 | + .httpClient(httpClient.client()) |
| 91 | + .build() |
| 92 | + ); |
| 93 | + |
| 94 | + FacturapiException ex = assertThrows( |
| 95 | + FacturapiException.class, |
| 96 | + () -> client.get("/customers/cus_1", null, GenericResponse.class) |
| 97 | + ); |
| 98 | + |
| 99 | + assertNull(ex.getErrorCode()); |
| 100 | + } |
82 | 101 | } |
0 commit comments