From 9edc07375c6af166f61c391e77ad9127192b2a29 Mon Sep 17 00:00:00 2001 From: dlstechteaching Date: Tue, 13 Dec 2022 16:38:39 +0100 Subject: [PATCH 1/7] test(services): exclude names with x function definition and first test --- src/services/__tests__/excludeNamesWithX.test.js | 8 ++++++++ src/services/excludeNamesWithX.js | 3 +++ 2 files changed, 11 insertions(+) create mode 100644 src/services/__tests__/excludeNamesWithX.test.js create mode 100644 src/services/excludeNamesWithX.js diff --git a/src/services/__tests__/excludeNamesWithX.test.js b/src/services/__tests__/excludeNamesWithX.test.js new file mode 100644 index 0000000..f4a474a --- /dev/null +++ b/src/services/__tests__/excludeNamesWithX.test.js @@ -0,0 +1,8 @@ +const excludeNamesWithX = require('../excludeNamesWithX'); + +describe('excludeNamesWithX tests suites', () => { + it('should return array', () => { + const result = excludeNamesWithX([]); + expect(result).toEqual([]); + }); +}); \ No newline at end of file diff --git a/src/services/excludeNamesWithX.js b/src/services/excludeNamesWithX.js new file mode 100644 index 0000000..f955a67 --- /dev/null +++ b/src/services/excludeNamesWithX.js @@ -0,0 +1,3 @@ +module.exports = function (name) { + return []; +}; \ No newline at end of file From 5453ec903ebf847267fcaeb4caca4692d45a2853 Mon Sep 17 00:00:00 2001 From: dlstechteaching Date: Tue, 13 Dec 2022 16:46:16 +0100 Subject: [PATCH 2/7] test(services): test scenario when all names do not have the letter x --- src/services/__tests__/excludeNamesWithX.test.js | 5 +++++ src/services/excludeNamesWithX.js | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/services/__tests__/excludeNamesWithX.test.js b/src/services/__tests__/excludeNamesWithX.test.js index f4a474a..697d7ac 100644 --- a/src/services/__tests__/excludeNamesWithX.test.js +++ b/src/services/__tests__/excludeNamesWithX.test.js @@ -5,4 +5,9 @@ describe('excludeNamesWithX tests suites', () => { const result = excludeNamesWithX([]); expect(result).toEqual([]); }); + + it('should return an array with all names as no names have an "x" letter', () => { + const result = excludeNamesWithX(['Momo','Hadji','Leo']); + expect(result).toEqual(['Momo','Hadji','Leo']); + }); }); \ No newline at end of file diff --git a/src/services/excludeNamesWithX.js b/src/services/excludeNamesWithX.js index f955a67..bc77137 100644 --- a/src/services/excludeNamesWithX.js +++ b/src/services/excludeNamesWithX.js @@ -1,3 +1,3 @@ -module.exports = function (name) { - return []; +module.exports = function (names) { + return names; }; \ No newline at end of file From 794380c2e853836fbf9a03e58579b6f1a4928663 Mon Sep 17 00:00:00 2001 From: dlstechteaching Date: Tue, 13 Dec 2022 16:51:49 +0100 Subject: [PATCH 3/7] test(services): test scenario when only one name is remaining --- src/services/__tests__/excludeNamesWithX.test.js | 5 +++++ src/services/excludeNamesWithX.js | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/services/__tests__/excludeNamesWithX.test.js b/src/services/__tests__/excludeNamesWithX.test.js index 697d7ac..18e89ed 100644 --- a/src/services/__tests__/excludeNamesWithX.test.js +++ b/src/services/__tests__/excludeNamesWithX.test.js @@ -10,4 +10,9 @@ describe('excludeNamesWithX tests suites', () => { const result = excludeNamesWithX(['Momo','Hadji','Leo']); expect(result).toEqual(['Momo','Hadji','Leo']); }); + + it('should return an array with JeanKevin only as it is the only name without the letter "x" ', () => { + const result = excludeNamesWithX(['DMX','Xzibit','JeanKevin']); + expect(result).toEqual(['JeanKevin']); + }); }); \ No newline at end of file diff --git a/src/services/excludeNamesWithX.js b/src/services/excludeNamesWithX.js index bc77137..8451b05 100644 --- a/src/services/excludeNamesWithX.js +++ b/src/services/excludeNamesWithX.js @@ -1,3 +1,9 @@ module.exports = function (names) { - return names; + const updateNames = []; + names.forEach(name => { + if (name.indexOf('X') === -1) { + updateNames.push(name); + } + }); + return updateNames; }; \ No newline at end of file From ed0c851a8dddf83c8883e4e7f25699e0b383257f Mon Sep 17 00:00:00 2001 From: dlstechteaching Date: Tue, 13 Dec 2022 16:55:36 +0100 Subject: [PATCH 4/7] test(services): test scenario handling case sensitivity --- src/services/__tests__/excludeNamesWithX.test.js | 5 +++++ src/services/excludeNamesWithX.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/services/__tests__/excludeNamesWithX.test.js b/src/services/__tests__/excludeNamesWithX.test.js index 18e89ed..4e1ab66 100644 --- a/src/services/__tests__/excludeNamesWithX.test.js +++ b/src/services/__tests__/excludeNamesWithX.test.js @@ -15,4 +15,9 @@ describe('excludeNamesWithX tests suites', () => { const result = excludeNamesWithX(['DMX','Xzibit','JeanKevin']); expect(result).toEqual(['JeanKevin']); }); + + it('should return an array with JC and Leo only as only xena contains the letter "x" ', () => { + const result = excludeNamesWithX(['JC','Leo','xena']); + expect(result).toEqual(['JC','Leo']); + }); }); \ No newline at end of file diff --git a/src/services/excludeNamesWithX.js b/src/services/excludeNamesWithX.js index 8451b05..10c28ac 100644 --- a/src/services/excludeNamesWithX.js +++ b/src/services/excludeNamesWithX.js @@ -1,7 +1,7 @@ module.exports = function (names) { const updateNames = []; names.forEach(name => { - if (name.indexOf('X') === -1) { + if (name.toLowerCase().indexOf('x') === -1) { updateNames.push(name); } }); From 32eea8e89f1cb2087501e08c3d0a2c3d11c6ecdf Mon Sep 17 00:00:00 2001 From: dlstechteaching Date: Tue, 13 Dec 2022 17:00:27 +0100 Subject: [PATCH 5/7] refactor(services): simplifying the excludeNameWithX function --- src/services/excludeNamesWithX.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/services/excludeNamesWithX.js b/src/services/excludeNamesWithX.js index 10c28ac..6f4eaf4 100644 --- a/src/services/excludeNamesWithX.js +++ b/src/services/excludeNamesWithX.js @@ -1,9 +1 @@ -module.exports = function (names) { - const updateNames = []; - names.forEach(name => { - if (name.toLowerCase().indexOf('x') === -1) { - updateNames.push(name); - } - }); - return updateNames; -}; \ No newline at end of file +module.exports = (names) => names.filter(name => name.toLowerCase().indexOf('x') === -1); \ No newline at end of file From 5b4c9fdcca91c0efc6dfa1164fd9a18d5f6edcee Mon Sep 17 00:00:00 2001 From: dlstechteaching Date: Tue, 13 Dec 2022 17:23:59 +0100 Subject: [PATCH 6/7] test(coverage): increasing coverage to 90 --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index b3ce81f..201cb41 100644 --- a/package.json +++ b/package.json @@ -53,10 +53,10 @@ ], "coverageThreshold": { "global": { - "lines": 80, - "branches": 80, - "functions": 80, - "statements": 80 + "lines": 90, + "branches": 90, + "functions": 90, + "statements": 90 } } } From 5efaed9368c22d07701b6ad082489876ff065f14 Mon Sep 17 00:00:00 2001 From: dlstechteaching Date: Tue, 13 Dec 2022 17:27:42 +0100 Subject: [PATCH 7/7] fix(format): fixing code prettier --- src/__tests__/app.test.js | 4 +- .../__tests__/excludeNamesWithX.test.js | 38 +++++++++---------- src/services/excludeNamesWithX.js | 3 +- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/__tests__/app.test.js b/src/__tests__/app.test.js index 1a1ad1c..13d1782 100644 --- a/src/__tests__/app.test.js +++ b/src/__tests__/app.test.js @@ -1,9 +1,7 @@ const { getCurrentMonth } = require("../app"); const { isAdmin } = require("../app"); -jest - .useFakeTimers() - .setSystemTime(new Date('2020-01-01')); +jest.useFakeTimers().setSystemTime(new Date("2020-01-01")); describe("app tests suites - getCurrentMonth", () => { test("should return the current month", () => { diff --git a/src/services/__tests__/excludeNamesWithX.test.js b/src/services/__tests__/excludeNamesWithX.test.js index 4e1ab66..19f8f88 100644 --- a/src/services/__tests__/excludeNamesWithX.test.js +++ b/src/services/__tests__/excludeNamesWithX.test.js @@ -1,23 +1,23 @@ -const excludeNamesWithX = require('../excludeNamesWithX'); +const excludeNamesWithX = require("../excludeNamesWithX"); -describe('excludeNamesWithX tests suites', () => { - it('should return array', () => { - const result = excludeNamesWithX([]); - expect(result).toEqual([]); - }); +describe("excludeNamesWithX tests suites", () => { + it("should return array", () => { + const result = excludeNamesWithX([]); + expect(result).toEqual([]); + }); - it('should return an array with all names as no names have an "x" letter', () => { - const result = excludeNamesWithX(['Momo','Hadji','Leo']); - expect(result).toEqual(['Momo','Hadji','Leo']); - }); + it('should return an array with all names as no names have an "x" letter', () => { + const result = excludeNamesWithX(["Momo", "Hadji", "Leo"]); + expect(result).toEqual(["Momo", "Hadji", "Leo"]); + }); - it('should return an array with JeanKevin only as it is the only name without the letter "x" ', () => { - const result = excludeNamesWithX(['DMX','Xzibit','JeanKevin']); - expect(result).toEqual(['JeanKevin']); - }); + it('should return an array with JeanKevin only as it is the only name without the letter "x" ', () => { + const result = excludeNamesWithX(["DMX", "Xzibit", "JeanKevin"]); + expect(result).toEqual(["JeanKevin"]); + }); - it('should return an array with JC and Leo only as only xena contains the letter "x" ', () => { - const result = excludeNamesWithX(['JC','Leo','xena']); - expect(result).toEqual(['JC','Leo']); - }); -}); \ No newline at end of file + it('should return an array with JC and Leo only as only xena contains the letter "x" ', () => { + const result = excludeNamesWithX(["JC", "Leo", "xena"]); + expect(result).toEqual(["JC", "Leo"]); + }); +}); diff --git a/src/services/excludeNamesWithX.js b/src/services/excludeNamesWithX.js index 6f4eaf4..5642f69 100644 --- a/src/services/excludeNamesWithX.js +++ b/src/services/excludeNamesWithX.js @@ -1 +1,2 @@ -module.exports = (names) => names.filter(name => name.toLowerCase().indexOf('x') === -1); \ No newline at end of file +module.exports = (names) => + names.filter((name) => name.toLowerCase().indexOf("x") === -1);