Skip to content

Commit

Permalink
copy updates in test
Browse files Browse the repository at this point in the history
  • Loading branch information
ibalosh committed Feb 15, 2022
1 parent 48ee020 commit 0550e6a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 3.0.1

* Separated error handling responsibility between postmark client and http client
* Separated error handling responsibility between postmark client and http client

## 3.0.0

Expand Down
32 changes: 12 additions & 20 deletions test/unit/ErrorHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ import "mocha";
describe("ErrorHandler", () => {
it("buildError", () => {
const errorHandler = new ErrorHandler();

const error = new Error();
const postmarkError = errorHandler.buildError("Test message");
error.name = "Test name";
error.message = "Test message";

const postmarkError = errorHandler.buildError("Test message");
expect(postmarkError.message).to.equal(error.message);
expect(postmarkError.name).to.equal("PostmarkError");
});

it("no response", () => {
const errorHandler = new ErrorHandler();
const error: any = { message: 'Hello Error' };

const postmarkError = errorHandler.buildError(error.message);

expect(postmarkError).to.be.an.instanceof(Errors.PostmarkError);
expect(postmarkError.name).to.equal("PostmarkError");
expect(postmarkError.message).to.equal(error.message);
Expand All @@ -42,6 +41,7 @@ describe("ErrorHandler", () => {
it("422", () => {
const errorHandler = new ErrorHandler();
const postmarkError = errorHandler.buildError("Test message", 423, 422);

expect(postmarkError).to.be.an.instanceof(Errors.ApiInputError);
expect(postmarkError.name).to.equal("ApiInputError");
expect(postmarkError.message).to.equal("Test message");
Expand All @@ -52,6 +52,7 @@ describe("ErrorHandler", () => {
it("429", () => {
const errorHandler = new ErrorHandler();
const postmarkError = errorHandler.buildError("Test message", 429, 429);

expect(postmarkError).to.be.an.instanceof(Errors.RateLimitExceededError);
expect(postmarkError.name).to.equal("RateLimitExceededError");
expect(postmarkError.message).to.equal("Test message");
Expand All @@ -60,25 +61,16 @@ describe("ErrorHandler", () => {
it("500", () => {
const errorHandler = new ErrorHandler();
const postmarkError = errorHandler.buildError("Test message", 500, 500);

expect(postmarkError).to.be.an.instanceof(Errors.InternalServerError);
expect(postmarkError.name).to.equal("InternalServerError");
expect(postmarkError.message).to.equal("Test message");
});

it("unknown", () => {
const errorHandler = new ErrorHandler();

const error: any = {
response: {
data: {
Message: "Test message",
ErrorCode: 600,
},
status: 600,
}
};

const postmarkError = errorHandler.buildError("Test message", 600, 600);

expect(postmarkError).to.be.an.instanceof(Errors.PostmarkError);
expect(postmarkError.name).to.equal("UnknownError");
expect(postmarkError.message).to.equal("Test message");
Expand All @@ -87,6 +79,7 @@ describe("ErrorHandler", () => {
it("no http status", () => {
const errorHandler = new ErrorHandler();
const postmarkError = errorHandler.buildError("Test message");

expect(postmarkError).to.be.an.instanceof(Errors.PostmarkError);
expect(postmarkError.name).to.equal("PostmarkError");
expect(postmarkError.message).to.equal("Test message");
Expand All @@ -95,15 +88,16 @@ describe("ErrorHandler", () => {
it("unknown http status", () => {
const errorHandler = new ErrorHandler();
const postmarkError = errorHandler.buildError("Test message", 500, 15);

expect(postmarkError).to.be.an.instanceof(Errors.PostmarkError);
expect(postmarkError.name).to.equal("UnknownError");
expect(postmarkError.message).to.equal("Test message");
});

it("postmark default error", () => {
const errorHandler = new ErrorHandler();

const postmarkError = errorHandler.buildError("Test message");

expect(postmarkError).to.be.an.instanceof(Errors.PostmarkError);
expect(postmarkError.name).to.equal("PostmarkError");
expect(postmarkError.message).to.equal("Test message");
Expand All @@ -123,19 +117,17 @@ describe("ErrorHandler", () => {
};

const postmarkError:any = errorHandler.buildError(error.message, error.errorCode, error.status);

expect(postmarkError).to.be.an.instanceof(Errors.InactiveRecipientsError);
expect(postmarkError.name).to.equal("InactiveRecipientsError");
expect(postmarkError.recipients).to.eql([ '[email protected]', '[email protected]' ])
});

it("email error", () => {
const errorHandler = new ErrorHandler();

const error: any = {
message: "Error message", errorCode: 300, status: 422
};

const error: any = { message: "Error message", errorCode: 300, status: 422 };
const postmarkError:any = errorHandler.buildError(error.message, error.errorCode, error.status);

expect(postmarkError).to.be.an.instanceof(Errors.InvalidEmailRequestError);
expect(postmarkError.name).to.equal("InvalidEmailRequestError");
});
Expand Down

0 comments on commit 0550e6a

Please sign in to comment.