Skip to content

Commit

Permalink
Fix zmount test cases (#3608)
Browse files Browse the repository at this point in the history
* Fix zmount test cases

* refactor zmount test suite

* Provide test cases for checking min and max values for size

* Update zmount test suites

* Add test cases for null, undefined and non numerics values

* Refactor test cases

* Add function to get random number to validate zmount size

* Add random ragnes to check the min, max and valid size

* Fix initialized values

* modify the expected result for the valid size

* rm files push by mistake
  • Loading branch information
samaradel authored Dec 18, 2024
1 parent c3bfded commit bc6633b
Showing 1 changed file with 42 additions and 41 deletions.
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 () => {
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());
});
});
});

0 comments on commit bc6633b

Please sign in to comment.