-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
1 changed file
with
42 additions
and
41 deletions.
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
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()); | ||
}); | ||
}); | ||
}); |