Skip to content

Commit

Permalink
fix: convert promises to async
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiin committed Oct 11, 2023
1 parent 62fb6fd commit c695f62
Show file tree
Hide file tree
Showing 22 changed files with 141 additions and 140 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
},
"scripts": {
"build": "nest build",
"lint": "eslint --cache",
"lint:fix": "eslint --cache --fix",
"lint": "ESLINT_USE_FLAT_CONFIG=true eslint '{src,test}/**/*.ts' --cache",
"lint:fix": "ESLINT_USE_FLAT_CONFIG=true eslint '{src,test}/**/*.ts' --cache --fix",
"orm": "npx mikro-orm",
"sample": "cd env; npx sample-env --env .env.dev",
"start": "nest start",
Expand Down Expand Up @@ -147,7 +147,7 @@
"@nestjs/cli": "10.1.18",
"@nestjs/schematics": "10.0.2",
"@nestjs/testing": "10.2.7",
"@rubiin/eslint-config": "^1.8.11",
"@rubiin/eslint-config": "^1.8.17",
"@rubiin/tsconfig": "^1.1.0",
"@sentry/types": "^7.73.0",
"@side/jest-runtime": "^1.1.0",
Expand Down
39 changes: 27 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ export class Cluster {
});
}
else {
main().catch((error: Error) => {
try {
main();
}
catch (error) {
this.loggerService.error(error);
});
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/@types/classes/offset.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class OffsetMeta {
pageOptionsDto,
itemCount,
}: {
pageOptionsDto: Omit<OffsetPaginationDto,"type">
pageOptionsDto: Omit<OffsetPaginationDto, "type">
itemCount: number
}) {
this.page = pageOptionsDto.page;
Expand Down
1 change: 0 additions & 1 deletion src/common/@types/enums/misc.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export enum TemplateEngine {
HBS = "HBS",
}


export const FileType: Record<keyof typeof FileSize, RegExp> = {
IMAGE: /(jpg|jpeg|png|gif|svg)$/i,
DOC: /(pdf|doc|txt|key|csv|docx|xls|xlsx|ppt|pptx)$/i,
Expand Down
29 changes: 13 additions & 16 deletions src/common/decorators/validation/is-after.validator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,39 @@ describe("isAfter", () => {
endDate!: Date;
}

it("if endDate is after than startDate then it should succeed", () => {
it("if endDate is after than startDate then it should succeed", async () => {
const model = new MyClass();

model.startDate = new Date("2022-02-21");
model.endDate = new Date("2022-05-01");

return validator.validate(model).then((errors) => {
expect(errors.length).toEqual(0);
});
const errors = await validator.validate(model);
expect(errors.length).toEqual(0);
});

it("if endDate is not after than startDate then it should fail", () => {
it("if endDate is not after than startDate then it should fail", async () => {
const model = new MyClass();

model.startDate = new Date("2022-02-21");
model.endDate = new Date("2022-01-01");

return validator.validate(model).then((errors) => {
expect(errors.length).toEqual(1);
expect(errors[0].constraints).toEqual({
IsAfterConstraint: "endDate should be after startDate",
});
const errors = await validator.validate(model);
expect(errors.length).toEqual(1);
expect(errors[0].constraints).toEqual({
IsAfterConstraint: "endDate should be after startDate",
});
});

it("if endDate is equal to startDate then it should fail", () => {
it("if endDate is equal to startDate then it should fail", async () => {
const model = new MyClass();

model.startDate = new Date("2022-02-21");
model.endDate = model.startDate;

return validator.validate(model).then((errors) => {
expect(errors.length).toEqual(1);
expect(errors[0].constraints).toEqual({
IsAfterConstraint: "endDate should be after startDate",
});
const errors = await validator.validate(model);
expect(errors.length).toEqual(1);
expect(errors[0].constraints).toEqual({
IsAfterConstraint: "endDate should be after startDate",
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,21 @@ describe("isDateInFormat", () => {
date: string;
}

it("if date satisfies the format then it should succeed", () => {
it("if date satisfies the format then it should succeed", async () => {
const model = new MyClass();

model.date = "2014-04-03";

return validator.validate(model).then((errors) => {
expect(errors.length).toEqual(0);
});
const errors = await validator.validate(model);
expect(errors.length).toEqual(0);
});

it("if date does not satisfies the format then it should fail", () => {
it("if date does not satisfies the format then it should fail", async () => {
const model = new MyClass();

model.date = "2014/04/03";

return validator.validate(model).then((errors) => {
expect(errors.length).toEqual(1);
});
const errors = await validator.validate(model);
expect(errors.length).toEqual(1);
});
});
18 changes: 8 additions & 10 deletions src/common/decorators/validation/is-equal-to.validator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,26 @@ describe("isEqualToField", () => {
confirmPassword!: string;
}

it("if password and confirm password are same then it should succeed", () => {
it("if password and confirm password are same then it should succeed", async () => {
const model = new MyClass();

model.password = "Test@1234";
model.confirmPassword = "Test@1234";

return validator.validate(model).then((errors) => {
expect(errors.length).toEqual(0);
});
const errors = await validator.validate(model);
expect(errors.length).toEqual(0);
});

it("if password and confirm password are not same then it should fail", () => {
it("if password and confirm password are not same then it should fail", async () => {
const model = new MyClass();

model.password = "UniquePassword@123";
model.confirmPassword = "DifferentPassword@1234";

return validator.validate(model).then((errors) => {
expect(errors.length).toEqual(1);
expect(errors[0].constraints).toEqual({
IsEqualToConstraint: "confirmPassword should be equal to password",
});
const errors = await validator.validate(model);
expect(errors.length).toEqual(1);
expect(errors[0].constraints).toEqual({
IsEqualToConstraint: "confirmPassword should be equal to password",
});
});
});
29 changes: 13 additions & 16 deletions src/common/decorators/validation/is-greater-than.validator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,39 @@ describe("isGreaterThan", () => {
totalMarks!: number;
}

it("if totalMarks is greater than passMarks then it should succeed", () => {
it("if totalMarks is greater than passMarks then it should succeed", async () => {
const model = new MyClass();

model.passMarks = 40;
model.totalMarks = 100;

return validator.validate(model).then((errors) => {
expect(errors.length).toEqual(0);
});
const errors = await validator.validate(model);
expect(errors.length).toEqual(0);
});

it("if totalMarks is less than passMarks then it should fail", () => {
it("if totalMarks is less than passMarks then it should fail", async () => {
const model = new MyClass();

model.passMarks = 100;
model.totalMarks = 40;

return validator.validate(model).then((errors) => {
expect(errors.length).toEqual(1);
expect(errors[0].constraints).toEqual({
IsGreaterThanConstraint: "totalMarks should be greater than passMarks",
});
const errors = await validator.validate(model);
expect(errors.length).toEqual(1);
expect(errors[0].constraints).toEqual({
IsGreaterThanConstraint: "totalMarks should be greater than passMarks",
});
});

it("if totalMarks is equal to passMarks then it should fail", () => {
it("if totalMarks is equal to passMarks then it should fail", async () => {
const model = new MyClass();

model.passMarks = 100;
model.totalMarks = 100;

return validator.validate(model).then((errors) => {
expect(errors.length).toEqual(1);
expect(errors[0].constraints).toEqual({
IsGreaterThanConstraint: "totalMarks should be greater than passMarks",
});
const errors = await validator.validate(model);
expect(errors.length).toEqual(1);
expect(errors[0].constraints).toEqual({
IsGreaterThanConstraint: "totalMarks should be greater than passMarks",
});
});
});
23 changes: 10 additions & 13 deletions src/common/decorators/validation/is-password.validator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,26 @@ describe("isPassword", () => {
password: string;
}

it("if password satisfies then it should succeed (one uppercase,one lowercase, one number and one symbol and more than 8 characters)", () => {
it("if password satisfies then it should succeed (one uppercase,one lowercase, one number and one symbol and more than 8 characters)", async () => {
const model = new MyClass();

model.password = "Test-1234";

return validator.validate(model).then((errors) => {
expect(errors.length).toEqual(0);
});
const errors = await validator.validate(model);
expect(errors.length).toEqual(0);
});

it("if password is not valid then it should fail", () => {
it("if password is not valid then it should fail", async () => {
const model = new MyClass();

model.password = "notStrongPassword";

return validator.validate(model).then((errors) => {
expect(errors.length).toEqual(1);
expect(errors[0].property).toEqual("password");
expect(errors[0].constraints).toEqual({
IsPasswordConstraint:
"password should contain at least one lowercase letter, one uppercase letter, one numeric digit, and one special character",
});
expect(errors[0].value).toEqual("notStrongPassword");
const errors = await validator.validate(model);
expect(errors.length).toEqual(1);
expect(errors[0].property).toEqual("password");
expect(errors[0].constraints).toEqual({
IsPasswordConstraint: "password should contain at least one lowercase letter, one uppercase letter, one numeric digit, and one special character",
});
expect(errors[0].value).toEqual("notStrongPassword");
});
});
18 changes: 8 additions & 10 deletions src/common/decorators/validation/is-profane.validator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,24 @@ describe("isProfane", () => {
text!: string;
}

it("it should pass if text doesn't profane words", () => {
it("it should pass if text doesn't profane words", async () => {
const model = new MyClass();

model.text = "clean text";

return validator.validate(model).then((errors) => {
expect(errors.length).toEqual(0);
});
const errors = await validator.validate(model);
expect(errors.length).toEqual(0);
});

it("it should fail if text has profane words", () => {
it("it should fail if text has profane words", async () => {
const model = new MyClass();

model.text = "Don't be an ash0le";

return validator.validate(model).then((errors) => {
expect(errors.length).toEqual(1);
expect(errors[0].constraints).toEqual({
IsProfaneConstraint: "text has profane words",
});
const errors = await validator.validate(model);
expect(errors.length).toEqual(1);
expect(errors[0].constraints).toEqual({
IsProfaneConstraint: "text has profane words",
});
});
});
Loading

0 comments on commit c695f62

Please sign in to comment.