2019-10-21 10:57:56 +02:00
|
|
|
import { BackendError, UnauthorizedError, createBackendError, NotFoundError } from "./errors";
|
2019-10-19 16:38:07 +02:00
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
describe("test createBackendError", () => {
|
2019-10-19 16:38:07 +02:00
|
|
|
const earthNotFoundError = {
|
2019-10-20 16:59:02 +02:00
|
|
|
transactionId: "42t",
|
|
|
|
|
errorCode: "42e",
|
|
|
|
|
message: "earth not found",
|
2019-10-19 16:38:07 +02:00
|
|
|
context: [
|
|
|
|
|
{
|
2019-10-20 16:59:02 +02:00
|
|
|
type: "planet",
|
|
|
|
|
id: "earth"
|
|
|
|
|
}
|
2019-10-19 16:38:07 +02:00
|
|
|
],
|
2019-10-20 16:59:02 +02:00
|
|
|
violations: []
|
2019-10-19 16:38:07 +02:00
|
|
|
};
|
|
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
it("should return a default backend error", () => {
|
2019-10-19 16:38:07 +02:00
|
|
|
const err = createBackendError(earthNotFoundError, 500);
|
|
|
|
|
expect(err).toBeInstanceOf(BackendError);
|
2019-10-20 16:59:02 +02:00
|
|
|
expect(err.name).toBe("BackendError");
|
2019-10-19 16:38:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 403 is no backend error
|
2019-10-20 16:59:02 +02:00
|
|
|
xit("should return an unauthorized error for status code 403", () => {
|
2019-10-19 16:38:07 +02:00
|
|
|
const err = createBackendError(earthNotFoundError, 403);
|
|
|
|
|
expect(err).toBeInstanceOf(UnauthorizedError);
|
2019-10-20 16:59:02 +02:00
|
|
|
expect(err.name).toBe("UnauthorizedError");
|
2019-10-19 16:38:07 +02:00
|
|
|
});
|
|
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
it("should return an not found error for status code 404", () => {
|
2019-10-19 16:38:07 +02:00
|
|
|
const err = createBackendError(earthNotFoundError, 404);
|
|
|
|
|
expect(err).toBeInstanceOf(NotFoundError);
|
2019-10-20 16:59:02 +02:00
|
|
|
expect(err.name).toBe("NotFoundError");
|
2019-10-19 16:38:07 +02:00
|
|
|
});
|
|
|
|
|
});
|