Skip to content

Commit

Permalink
refactor: clean up test files and update package dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-logan committed Jan 8, 2025
1 parent f341123 commit 12d3650
Show file tree
Hide file tree
Showing 11 changed files with 355 additions and 344 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@
"Breno A"
],
"devDependencies": {
"@types/jest": "^29.5.13",
"@types/node": "^22.7.7",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"@types/jest": "^29.5.14",
"@types/node": "^22.10.5",
"@typescript-eslint/eslint-plugin": "^8.19.1",
"@typescript-eslint/parser": "^8.19.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-prettier": "^5.2.1",
"jest": "^29.7.0",
"prettier": "^3.3.3",
"prettier": "^3.4.2",
"ts-jest": "^29.2.5",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"typescript": "^5.6.3",
"webpack": "^5.95.0",
"webpack-cli": "^5.1.4"
"typescript": "^5.7.2",
"webpack": "^5.97.1",
"webpack-cli": "^6.0.1"
},
"packageManager": "[email protected]"
}
19 changes: 11 additions & 8 deletions tests/generateFakeImage.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
const fs = require('fs');
const fs = require("fs");

// Assinatura PNG: [0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]
const pngSignature = [0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A];
const pngSignature = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
const fakePNG = new Uint8Array([...pngSignature, ...new Array(100).fill(0)]); // 100 bytes extras vazios
fs.writeFileSync('fake.png', fakePNG);
fs.writeFileSync("fake.png", fakePNG);

// Assinatura GIF: [0x47, 0x49, 0x46, 0x38, 0x37, 0x61] (GIF89a) ou [0x47, 0x49, 0x46, 0x38, 0x37, 0x61] (GIF87a)
const gifSignature = [0x47, 0x49, 0x46, 0x38, 0x37, 0x61];
const fakeGIF = new Uint8Array([...gifSignature, ...new Array(100).fill(0)]); // 100 bytes extras vazios
fs.writeFileSync('fake87a.gif', fakeGIF);
fs.writeFileSync("fake87a.gif", fakeGIF);

// Assinatura GIF89a: [0x47, 0x49, 0x46, 0x38, 0x39, 0x61]
const gif89aSignature = [0x47, 0x49, 0x46, 0x38, 0x39, 0x61];
const fakeGIF89a = new Uint8Array([...gif89aSignature, ...new Array(100).fill(0)]); // 100 bytes extras vazios
fs.writeFileSync('fake89a.gif', fakeGIF89a);
const fakeGIF89a = new Uint8Array([
...gif89aSignature,
...new Array(100).fill(0),
]); // 100 bytes extras vazios
fs.writeFileSync("fake89a.gif", fakeGIF89a);

// Assinatura JPEG: [0xFF, 0xD8, 0xFF]
const jpegSignature = [0xFF, 0xD8, 0xFF];
const jpegSignature = [0xff, 0xd8, 0xff];
const fakeJPEG = new Uint8Array([...jpegSignature, ...new Array(100).fill(0)]); // 100 bytes extras vazios
fs.writeFileSync('fake.jpeg', fakeJPEG);
fs.writeFileSync("fake.jpeg", fakeJPEG);
1 change: 0 additions & 1 deletion tests/src/cnpjValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,4 @@ describe("cnpjIsValid function", () => {
expect(result.isValid).toBe(true);
expect(result.errorMsg).toBeNull();
});

});
8 changes: 4 additions & 4 deletions tests/src/getOnlyEmail.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,23 @@ describe("getOnlyEmail", () => {
it("should return the first email when repeatEmail is true and multiple is false", () => {
const result = getOnlyEmail(
"Entre em contato com a equipe: [email protected], [email protected]",
{ multiple: false, cleanDomain: false, repeatEmail: true }
{ multiple: false, cleanDomain: false, repeatEmail: true },
);
expect(result).toBe("[email protected]");
});

it("should return the first cleaned email when repeatEmail is true and multiple is false", () => {
const result = getOnlyEmail(
"Entre em contato com a equipe: [email protected], [email protected]",
{ multiple: false, cleanDomain: true, repeatEmail: true }
{ multiple: false, cleanDomain: true, repeatEmail: true },
);
expect(result).toBe("[email protected]");
});
});

it("should return all cleaned emails when repeatEmail is true and multiple is true", () => {
const result = getOnlyEmail(
"Entre em contato com a equipe: [email protected], [email protected]",
{ multiple: true, cleanDomain: true, repeatEmail: true }
{ multiple: true, cleanDomain: true, repeatEmail: true },
);
expect(result).toEqual(["[email protected]", "[email protected]"]);
});
Expand Down
3 changes: 1 addition & 2 deletions tests/src/isDate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ describe("isDate", () => {
const result = isDate("2024-02-29");
expect(result).toBe(true);
});

it("should return true for February 29 in a leap year divisible by 400", () => {
const result = isDate("2000-02-29");
expect(result).toBe(true);
});

});
16 changes: 12 additions & 4 deletions tests/src/isValidImage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ describe("isValidImage", () => {
});

it("should return false for an invalid PNG image with headers corrects", () => {
const result = isValidImage(fileBuffer9, { exclude: ["gif", "ico", "jpeg"]});
const result = isValidImage(fileBuffer9, {
exclude: ["gif", "ico", "jpeg"],
});
expect(result).toBe(false);
});

Expand All @@ -258,17 +260,23 @@ describe("isValidImage", () => {
});

it("should return false for an invalid JPEG image with headers corrects", () => {
const result = isValidImage(fileBuffer10, { exclude: ["gif", "ico", "png"]});
const result = isValidImage(fileBuffer10, {
exclude: ["gif", "ico", "png"],
});
expect(result).toBe(false);
});

it("should return false for an invalid GIF image with headers corrects", () => {
const result = isValidImage(fileBuffer11, { exclude: ["jpeg", "ico", "png"]});
const result = isValidImage(fileBuffer11, {
exclude: ["jpeg", "ico", "png"],
});
expect(result).toBe(false);
});

it("should return false for an invalid GIF image with headers corrects", () => {
const result = isValidImage(fileBuffer12, { exclude: ["jpeg", "ico", "png"]});
const result = isValidImage(fileBuffer12, {
exclude: ["jpeg", "ico", "png"],
});
expect(result).toBe(false);
});
});
Expand Down
2 changes: 1 addition & 1 deletion tests/src/validateBRPhoneNumber.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("validateBRPhoneNumber", () => {
errorMsg: null,
});
});

it("should return default error messages when errorMsg['etc', null] is passed", () => {
const result = validateBRPhoneNumber("12345678", ["etc", null]);
expect(result).toEqual({
Expand Down
6 changes: 4 additions & 2 deletions tests/src/validatePassword.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ describe("validatePassword", () => {
maxLength: 20,
errorMsg: undefined,
});

expect(result.errorMsg).toBe("Password must be between 8 and 20 characters");

expect(result.errorMsg).toBe(
"Password must be between 8 and 20 characters",
);
});

it("should return default error messages when errorMsg['etc', null] is passed", () => {
Expand Down
4 changes: 3 additions & 1 deletion tests/src/validateUsername.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ describe("validateUsername", () => {
maxLength: 25,
errorMsg: null as any,
});
expect(result.errorMsg).toBe("Username must be between 3 and 25 characters");
expect(result.errorMsg).toBe(
"Username must be between 3 and 25 characters",
);
});

it("should throw an error if minLength is number but maxLength is not", () => {
Expand Down
Loading

0 comments on commit 12d3650

Please sign in to comment.