Skip to content

Commit

Permalink
♻️ [refactor]: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brunotot committed Jan 5, 2024
1 parent 354cd84 commit 757ee00
Show file tree
Hide file tree
Showing 46 changed files with 62 additions and 80 deletions.
11 changes: 4 additions & 7 deletions packages/core/tests/common/TestFactory.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import Types from "../../src/utilities/impl/Types";
import ValidationEngine from "../../src/validation";
import ValidationHandlerMock, {
IMock,
buildIOName,
} from "./ValidationHandlerMock";
import { Types } from "../../src/utilities";
import { Form } from "../../src/validation";
import ValidationHandlerMock, { IMock, buildIOName } from "./ValidationHandlerMock";

export type StandardTestProps<T> = {
Model: Types.Class<IMock<T>>;
Expand All @@ -20,7 +17,7 @@ export function standardTest<T>({
errorData,
type,
}: StandardTestProps<T>) {
const handler = new ValidationEngine.ValidationEngine<T>(Model as any);
const handler = new Form<T>(Model as any);
const expectService = new ValidationHandlerMock(handler as any);

describe(buildIOName(identifier, true, type), () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/tests/common/ValidationHandlerMock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ValidationEngine from "../../src/validation";
import { Form } from "../../src/validation";

export interface IMock<T> {
value: T;
Expand All @@ -13,10 +13,10 @@ function buildItMessage(valid: boolean, value: any) {
}

export default class ValidationHandlerMock<T> {
constructor(private handler: ValidationEngine.ValidationEngine<IMock<T>>) {}
constructor(private handler: Form<IMock<T>>) {}

expect(data: T[], valid: boolean) {
data.forEach((value) => {
data.forEach(value => {
it(buildItMessage(valid, value), () => {
const state: any = { value };
const res = this.handler.validate(state);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/tests/impl/any/Required.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Required } from "../../../collection/any/Required";
import Objects from "../../../src/utilities/impl/Objects";
import * as Objects from "../../../src/utilities/impl/Objects";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";
import { Required } from "./../../../src/decorators";

/*** Data ***/
type Type = Objects.Optional<any>;
Expand Down
8 changes: 3 additions & 5 deletions packages/core/tests/impl/any/attribute.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import collection from "../../../collection";
import { attribute } from "../../../collection/class/attribute";
import $ from "../../../index";
import $, { attribute, Decorators } from "../../../index";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";

Expand Down Expand Up @@ -32,10 +30,10 @@ const errorData: Type[] = [
];

class NestedModel {
@collection.string.Required()
@Decorators.Required()
stringValue!: string;

@collection.number.Integer()
@Decorators.Integer()
numberValue!: number;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/array/ArrayContains.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";
import { ArrayContains } from "./../../../collection/array/ArrayContains";
import { ArrayContains } from "./../../../src/decorators";

const SEARCH_ITEM = 7;
const NON_SEARCH_ITEM_STRING = "X";
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/array/ArrayEmpty.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArrayEmpty } from "../../../collection/array/ArrayEmpty";
import { ArrayEmpty } from "../../../src/decorators";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/array/ArrayEvery.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ArrayEvery } from "../../../collection/array/ArrayEvery";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";
import { ArrayEvery } from "./../../../src/decorators";

/*** Data ***/
type Type = string[];
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/array/ArrayNone.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ArrayNone } from "../../../collection/array/ArrayNone";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";
import { ArrayNone } from "./../../../src/decorators";

/*** Data ***/
type Type = string[];
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/array/ArrayOne.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ArrayOne } from "../../../collection/array/ArrayOne";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";
import { ArrayOne } from "./../../../src/decorators";

/*** Data ***/
type Type = string[];
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/array/ArraySizeExact.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ArraySizeExact } from "../../../collection/array/ArraySizeExact";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";
import { ArraySizeExact } from "./../../../src/decorators";

/*** Data ***/
type Type = string[];
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/array/ArraySizeMax.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ArraySizeMax } from "../../../collection/array/ArraySizeMax";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";
import { ArraySizeMax } from "./../../../src/decorators";

/*** Data ***/
type Type = string[];
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/array/ArraySizeMin.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ArraySizeMin } from "../../../collection/array/ArraySizeMin";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";
import { ArraySizeMin } from "./../../../src/decorators";

/*** Data ***/
type Type = string[];
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/array/ArraySizeRange.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ArraySizeRange } from "../../../collection/array/ArraySizeRange";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";
import { ArraySizeRange } from "./../../../src/decorators";

/*** Data ***/
type Type = string[];
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/array/ArraySome.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ArraySome } from "../../../collection/array/ArraySome";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";
import { ArraySome } from "./../../../src/decorators";

/*** Data ***/
type Type = string[];
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/array/ArrayUnique.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ArrayUnique } from "../../../collection/array/ArrayUnique";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";
import { ArrayUnique } from "./../../../src/decorators";

/*** Data ***/
type Type = string[];
Expand Down
4 changes: 2 additions & 2 deletions packages/core/tests/impl/array/foreach.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Required } from "../../../collection/any/Required";
import { foreach } from "../../../collection/array/foreach";
import { Required } from "../../../src/decorators";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";
import { foreach } from "./../../../src/decorators";

/*** Data ***/
type Type = string[];
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/boolean/AssertFalse.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AssertFalse } from "../../../collection/boolean/AssertFalse";
import { AssertFalse } from "../../../src/decorators";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/boolean/AssertTrue.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AssertTrue } from "../../../collection/boolean/AssertTrue";
import { AssertTrue } from "../../../src/decorators";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/date/FutureDate.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FutureDate } from "../../../collection/date/FutureDate";
import $ from "../../../index";
import { FutureDate } from "../../../src/decorators";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/date/PastDate.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PastDate } from "../../../collection/date/PastDate";
import $ from "../../../index";
import { PastDate } from "../../../src/decorators";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/date/TodayDate.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TodayDate } from "../../../collection/date/TodayDate";
import $ from "../../../index";
import { TodayDate } from "../../../src/decorators";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/number/Decimal.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Decimal } from "../../../collection/number/Decimal";
import $ from "../../../index";
import { Decimal } from "../../../src/decorators";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/number/Digits.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Digits } from "../../../collection/number/Digits";
import $ from "../../../index";
import { Digits } from "../../../src/decorators";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/number/Integer.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Integer } from "../../../collection/number/Integer";
import $ from "../../../index";
import { Integer } from "../../../src/decorators";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/number/Negative.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Negative } from "../../../collection/number/Negative";
import $ from "../../../index";
import { Negative } from "../../../src/decorators";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/number/NonNegative.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NonNegative } from "../../../collection/number/NonNegative";
import $ from "../../../index";
import { NonNegative } from "../../../src/decorators";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/number/NonPositive.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NonPositive } from "../../../collection/number/NonPositive";
import $ from "../../../index";
import { NonPositive } from "../../../src/decorators";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/number/Positive.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Positive } from "../../../collection/number/Positive";
import $ from "../../../index";
import { Positive } from "../../../src/decorators";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/number/ValueMax.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ValueMax } from "../../../collection/number/ValueMax";
import $ from "../../../index";
import { ValueMax } from "../../../src/decorators";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/number/ValueMin.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ValueMin } from "../../../collection/number/ValueMin";
import $ from "../../../index";
import { ValueMin } from "../../../src/decorators";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/number/ValueRange.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ValueRange } from "../../../collection/number/ValueRange";
import $ from "../../../index";
import { ValueRange } from "../../../src/decorators";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/string/ExactLength.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExactLength } from "../../../collection/string/ExactLength";
import $ from "../../../index";
import { ExactLength } from "../../../src/decorators";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/string/MaxLength.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MaxLength } from "../../../collection/string/MaxLength";
import $ from "../../../index";
import { MaxLength } from "../../../src/decorators";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/string/MinLength.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MinLength } from "../../../collection/string/MinLength";
import $ from "../../../index";
import { MinLength } from "../../../src/decorators";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/string/Password.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Password } from "../../../collection/string/Password";
import $ from "../../../index";
import { Password } from "../../../src/decorators";
import { standardTest } from "../../common/TestFactory";
import { IMock } from "../../common/ValidationHandlerMock";

Expand Down
4 changes: 2 additions & 2 deletions packages/core/tests/impl/string/regex/Pattern.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Pattern } from "../../../../collection/string/regex/Pattern";
import RegexConst from "../../../../collection/string/regex/shared/regex.constants";
import $ from "../../../../index";
import RegexConst from "../../../../src/decorators/data/validators/string/regex/shared/regex.constants";
import { standardTest } from "../../../common/TestFactory";
import { IMock } from "../../../common/ValidationHandlerMock";
import { Pattern } from "./../../../../src/decorators";

/*** Data ***/
type Type = $.Utilities.Objects.Optional<string>;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/string/regex/impl/Alpha.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Alpha } from "../../../../../collection/string/regex/impl/Alpha";
import $ from "../../../../../index";
import { Alpha } from "../../../../../src/decorators";
import { standardTest } from "../../../../common/TestFactory";
import { IMock } from "../../../../common/ValidationHandlerMock";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Alphanumeric } from "../../../../../collection/string/regex/impl/Alphanumeric";
import Objects from "../../../../../src/utilities/impl/Objects";
import { Alphanumeric } from "../../../../../src/decorators";
import { Objects } from "../../../../../src/utilities";
import { standardTest } from "../../../../common/TestFactory";
import { IMock } from "../../../../common/ValidationHandlerMock";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/string/regex/impl/Email.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Email } from "../../../../../collection/string/regex/impl/Email";
import $ from "../../../../../index";
import { Email } from "../../../../../src/decorators";
import { standardTest } from "../../../../common/TestFactory";
import { IMock } from "../../../../common/ValidationHandlerMock";

Expand Down
10 changes: 2 additions & 8 deletions packages/core/tests/impl/string/regex/impl/IPAddress.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IPAddress } from "../../../../../collection/string/regex/impl/IPAddress";
import $ from "../../../../../index";
import { IPAddress } from "../../../../../src/decorators";
import { standardTest } from "../../../../common/TestFactory";
import { IMock } from "../../../../common/ValidationHandlerMock";

Expand All @@ -8,13 +8,7 @@ type Type = $.Utilities.Objects.Optional<string>;
const type = "String";
const identifier = "IPAddress";
const successData: Type[] = ["192.168.1.0", "", null, undefined];
const errorData: Type[] = [
"test123",
"192.168",
"@@@",
"gmail.com",
"www.google.hr",
];
const errorData: Type[] = ["test123", "192.168", "@@@", "gmail.com", "www.google.hr"];

/*** Model ***/
class Model implements IMock<Type> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Lowercase } from "../../../../../collection/string/regex/impl/Lowercase";
import $ from "../../../../../index";
import { Lowercase } from "../../../../../src/decorators";
import { standardTest } from "../../../../common/TestFactory";
import { IMock } from "../../../../common/ValidationHandlerMock";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/impl/string/regex/impl/Numeric.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Numeric } from "../../../../../collection/string/regex/impl/Numeric";
import $ from "../../../../../index";
import { Numeric } from "../../../../../src/decorators";
import { standardTest } from "../../../../common/TestFactory";
import { IMock } from "../../../../common/ValidationHandlerMock";

Expand Down
9 changes: 2 additions & 7 deletions packages/core/tests/impl/string/regex/impl/URL.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import { URL } from "../../../../../collection/string/regex/impl/URL";
import $ from "../../../../../index";
import { URL } from "../../../../../src/decorators";
import { standardTest } from "../../../../common/TestFactory";
import { IMock } from "../../../../common/ValidationHandlerMock";

/*** Data ***/
type Type = $.Utilities.Objects.Optional<string>;
const type = "String";
const identifier = "URL";
const successData: Type[] = [
"www.google.hr",
"https://www.facebook.com/?query=",
null,
undefined,
];
const successData: Type[] = ["www.google.hr", "https://www.facebook.com/?query=", null, undefined];
const errorData: Type[] = ["/google.com", "test@test"];

/*** Model ***/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Uppercase } from "../../../../../collection/string/regex/impl/Uppercase";
import $ from "../../../../../index";
import { Uppercase } from "../../../../../src/decorators";
import { standardTest } from "../../../../common/TestFactory";
import { IMock } from "../../../../common/ValidationHandlerMock";

Expand Down
Loading

0 comments on commit 757ee00

Please sign in to comment.