Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix zmount test cases #3608

Merged
merged 11 commits into from
Dec 18, 2024
83 changes: 42 additions & 41 deletions packages/grid_client/tests/modules/zmount.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
amiraabouhadid marked this conversation as resolved.
Show resolved Hide resolved
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());
});
});
});
Loading