diff --git a/packages/grid_client/tests/modules/zmount.test.ts b/packages/grid_client/tests/modules/zmount.test.ts index 81ee902ba9..dba0c769ae 100644 --- a/packages/grid_client/tests/modules/zmount.test.ts +++ b/packages/grid_client/tests/modules/zmount.test.ts @@ -1,58 +1,59 @@ +import { validate } from "class-validator"; + import { Zmount } from "../../src"; +import { getRandomNumber } from "../../src/helpers/utils"; -let zmount: Zmount; +describe("Zmount Class", () => { + let zmount: Zmount; + const minSize = getRandomNumber(0, 100 * 1024 ** 2 - 1); + const maxSize = getRandomNumber(10 * 1024 ** 4 + 1, 10 * 1024 ** 5); + const validSize = getRandomNumber(100 * 1024 ** 2, 10 * 1024 ** 4); -beforeEach(() => { - zmount = new Zmount(); -}); -describe("Zmount module", () => { - test("Zmount instance is of type Zmount.", () => { - expect(zmount).toBeInstanceOf(Zmount); + beforeEach(() => { + zmount = new Zmount(); }); - test("Min value for size.", () => { - const size = 100 * 1025 ** 2; - - zmount.size = size; - - const result = () => zmount.challenge(); - - expect(result).toThrow(); + describe("Initialization", () => { + it("should be initialized with default values", () => { + expect(zmount).toBeDefined(); + expect(zmount.size).toBeUndefined(); + }); }); - test("Max value for size.", () => { - const size = 100 * 1025 ** 4; - - zmount.size = size; + describe("size property validation", () => { + it("should fail validation if size is set to a non-numeric value", async () => { + expect(() => (zmount.size = "not a number" as any)).toThrow(); + }); - const result = () => zmount.challenge(); + it("should fail validation if size is null", async () => { + expect(() => (zmount.size = null as any)).toThrow(); + }); - expect(result).toThrow(); - }); + it("should fail validation if size is undefined", async () => { + expect(() => (zmount.size = undefined as any)).toThrow(); + }); - test("Size doesn't accept decimal value.", () => { - const size = 1.5; + it("should fail validation if size is less than the minimum", async () => { + expect(() => (zmount.size = minSize)).toThrow(); + }); - zmount.size = size; + it("should fail validation if size is greater than the maximum", async () => { + expect(() => (zmount.size = maxSize)).toThrow(); + }); - const result = () => zmount.challenge(); - - expect(result).toThrow(); - }); - - test("Size empty value.", () => { - const result = () => zmount.challenge(); - - expect(result).toThrow(); + it("should pass validation if size is a valid number within the range", async () => { + zmount.size = validSize; + const errors = await validate(zmount); + expect(errors.length).toBe(0); + }); }); - test("Size negative value.", () => { - const negative_size = -1; - - zmount.size = negative_size; - - const result = () => zmount.challenge(); + describe("challenge method", () => { + it("should return the size as a string", () => { + zmount.size = validSize; - expect(result).toThrow(); + const result = zmount.challenge(); + expect(result).toBe(validSize.toString()); + }); }); });