Skip to content

Commit

Permalink
test: add more test to isCreditCardValid function
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-logan committed Aug 17, 2024
1 parent 5553f36 commit 38d78a9
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions tests/src/isCreditCardValid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,88 @@ describe("isCreditCardValid", () => {
expect(result).toBe(false);
});

it("should return false when the length of the input is less than 13", () => {
const result = isCreditCardValid("123456781234");
expect(result).toBe(false);
});

it("should return false when the length of the input is greater than 19", () => {
const result = isCreditCardValid("12345678123456781234");
expect(result).toBe(false);
});

it("should throw an error when the input is not a string", () => {
expect(() => isCreditCardValid(1234567812345678 as any)).toThrow(
"The input should be a string.",
);
});

it("should return false when the input is an empty string", () => {
const result = isCreditCardValid("");
expect(result).toBe(false);
});

it("should return false when the input is a string with only spaces", () => {
const result = isCreditCardValid(" ");
expect(result).toBe(false);
});

it("should return false when the input is a string with only letters", () => {
const result = isCreditCardValid("abcdefgh");
const result2 = isCreditCardValid("asdfghjklcmvnshdg==");
const result3 = isCreditCardValid("asdfghjklcmvnshdg");
expect(result).toBe(false);
expect(result2).toBe(false);
expect(result3).toBe(false);
});

it("should return false when having a letter in the middle of the string", () => {
const result = isCreditCardValid("1234a5678");
expect(result).toBe(false);
});

it("should return false when the input is a string with only special characters", () => {
const result = isCreditCardValid("++++");
expect(result).toBe(false);
});

it("should return false when the input is a string with only special characters and numbers", () => {
const result = isCreditCardValid("1234++++");
expect(result).toBe(false);
});

it("should return false when the input is a string with only special characters and letters", () => {
const result = isCreditCardValid("abcd++++");
expect(result).toBe(false);
});

it("should return false when the input is a string with only special characters, letters and numbers", () => {
const result = isCreditCardValid("abcd1234++++");
expect(result).toBe(false);
});

it("should return false when the input is a string with only special characters and spaces", () => {
const result = isCreditCardValid(" ++++");
expect(result).toBe(false);
});

it("should return false when the input is a string with only special characters, spaces and numbers", () => {
const result = isCreditCardValid("1234 ++++");
expect(result).toBe(false);
});

it("should return false when the input is a string with only special characters, spaces and letters", () => {
const result = isCreditCardValid("abcd ++++");
expect(result).toBe(false);
});

it("should return false when the input is a string with only special characters, spaces, letters and numbers", () => {
const result = isCreditCardValid("abcd1234 ++++");
expect(result).toBe(false);
});

it("should return false when the input is a string with only spaces and letters", () => {
const result = isCreditCardValid(" abcd");
expect(result).toBe(false);
});
});

0 comments on commit 38d78a9

Please sign in to comment.