-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: jahabeebs <47253537+jahabeebs@users.noreply.github.com>
- Loading branch information
Showing
3 changed files
with
155 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/automated-dispute/tests/exceptions/errorFactory.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { describe, expect, it } from "vitest"; | ||
|
||
import { CustomContractError } from "../../src/exceptions/customContractError"; | ||
import { ErrorFactory } from "../../src/exceptions/errorFactory"; | ||
|
||
describe("ErrorFactory", () => { | ||
it("creates a CustomContractError with the correct name and strategy for known errors", () => { | ||
const errorName = "ValidatorLib_InvalidResponseBody"; | ||
const error = ErrorFactory.createError(errorName); | ||
|
||
expect(error).toBeInstanceOf(CustomContractError); | ||
expect(error.name).toBe(errorName); | ||
expect(error.strategy).toEqual({ | ||
shouldNotify: false, | ||
shouldTerminate: false, | ||
shouldReenqueue: true, | ||
}); | ||
}); | ||
|
||
it("creates a CustomContractError with default strategy for unknown errors", () => { | ||
const errorName = "UnknownError"; | ||
const error = ErrorFactory.createError(errorName); | ||
|
||
expect(error).toBeInstanceOf(CustomContractError); | ||
expect(error.name).toBe(errorName); | ||
expect(error.strategy).toEqual({ | ||
shouldNotify: true, | ||
shouldTerminate: false, | ||
shouldReenqueue: true, | ||
}); | ||
}); | ||
|
||
it("creates a CustomContractError with custom action for specific errors", () => { | ||
const errorName = "BondEscalationModule_InvalidDispute"; | ||
const error = ErrorFactory.createError(errorName); | ||
|
||
expect(error).toBeInstanceOf(CustomContractError); | ||
expect(error.name).toBe(errorName); | ||
expect(error.strategy).toHaveProperty("customAction"); | ||
expect(typeof error.strategy.customAction).toBe("function"); | ||
}); | ||
|
||
it("creates different CustomContractErrors for different error names", () => { | ||
const error1 = ErrorFactory.createError("ValidatorLib_InvalidResponseBody"); | ||
const error2 = ErrorFactory.createError("BondEscalationAccounting_InsufficientFunds"); | ||
|
||
expect(error1.name).not.toBe(error2.name); | ||
expect(error1.strategy).not.toEqual(error2.strategy); | ||
}); | ||
|
||
it("creates CustomContractErrors with consistent strategies for the same error name", () => { | ||
const errorName = "ValidatorLib_InvalidResponseBody"; | ||
const error1 = ErrorFactory.createError(errorName); | ||
const error2 = ErrorFactory.createError(errorName); | ||
|
||
expect(error1.strategy).toEqual(error2.strategy); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters