Skip to content

Commit

Permalink
Merge pull request #18 from daoodaba975/fix-errors-and-tu
Browse files Browse the repository at this point in the history
Fix: correction of errors and unit tests
  • Loading branch information
daoodaba975 authored Jul 21, 2023
2 parents aa5b70d + 3e18204 commit fb7a5de
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 27 deletions.
12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = {
departments: (regionName) => {
regionName = lowerCase(regionName);

if (regionName.length == 0) {
if (regionName?.length == 0) {
throw new RegionReferenceError();
}

Expand All @@ -73,7 +73,7 @@ module.exports = {
population: (regionName) => {
regionName = lowerCase(regionName);

if (regionName.length == 0) {
if (regionName?.length == 0) {
throw new RegionReferenceError();
}

Expand All @@ -93,7 +93,7 @@ module.exports = {
superficie: (regionName) => {
regionName = lowerCase(regionName);

if (regionName.length == 0) {
if (regionName?.length == 0) {
throw new RegionReferenceError();
}

Expand Down Expand Up @@ -125,7 +125,7 @@ module.exports = {
arrondissements: (departmentName) => {
departmentName = lowerCase(departmentName);

if (departmentName.length == 0) {
if (departmentName?.length == 0) {
throw new DepartmentReferenceError();
}

Expand All @@ -145,7 +145,7 @@ module.exports = {
populationDepartment: (departmentName) => {
departmentName = lowerCase(departmentName);

if (departmentName.length == 0) {
if (departmentName?.length == 0) {
throw new DepartmentReferenceError();
}

Expand All @@ -165,7 +165,7 @@ module.exports = {
superficieDepartment: (departmentName) => {
departmentName = lowerCase(departmentName);

if (departmentName.length == 0) {
if (departmentName?.length == 0) {
throw new DepartmentReferenceError();
}

Expand Down
4 changes: 2 additions & 2 deletions libs/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const rg = require("../dataset/regions.json");
const dp = require("../dataset/departments.json");
// const { DepartmentReferenceError } = require("./exceptions");
const { DepartmentReferenceError, RegionReferenceError} = require("./exceptions");

const lowerCase = (value) => value.toLowerCase().trim();
const lowerCase = (value) => value?.toLowerCase().trim();

const findItem = (value) => {
const region = rg.find(
Expand Down
111 changes: 111 additions & 0 deletions mock/galsenify.test.mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
const regionNamesMock = [
"Dakar",
"Diourbel",
"Fatick",
"Kaffrine",
"Kaolack",
"Kédougou",
"Kolda",
"Louga",
"Matam",
"Saint-Louis",
"Sédhiou",
"Tambacounda",
"Thies",
"Ziguinchor",
];

const departmentsMock = [
"Dakar",
"Pikine",
"Guédiawaye",
"Rufisque",
"Keur Massar",
];

const codeMock = [
"DK",
"DB",
"FK",
"KA",
"KL",
"KE",
"KD",
"LG",
"MT",
"SL",
"SE",
"TC",
"TH",
"ZG",
];

const languesNationalesMock = [
"Wolof",
"Pular",
"Sérère",
"Diola",
"Mandingue",
"Soninké",
"Bambara",
];

const allDepartmentMock = [
"Dakar",
"Guédiawaye",
"Keur Massar",
"Pikine",
"Rufisque",
"Bambey",
"Diourbel",
"Mbacké",
"Fatick",
"Foundiougne",
"Gossas",
"Birkelane",
"Kaffrine",
"Koungheul",
"Malème-Hodar",
"Guinguinéo",
"Kaolack",
"Nioro du Rip",
"Kédougou",
"Salemata",
"Saraya",
"Kolda",
"Vélingara",
"Médina Yoro Foulah",
"Kébémer",
"Linguère",
"Louga",
"Kanel",
"Matam",
"Ranérou-Ferlo",
"Dagana",
"Podor",
"Saint-Louis",
"Bounkiling",
"Goudomp",
"Sédhiou",
"Bakel",
"Goudiry",
"Koumpentoum",
"Tambacounda",
"Mbour",
"Thies",
"Tivaouane",
"Bignona",
"Oussouye",
"Ziguinchor",
];

const arrondissementsMock = ["Dagoudane", "Thiaroye"];

module.exports = {
regionNamesMock,
departmentsMock,
codeMock,
languesNationalesMock,
allDepartmentMock,
arrondissementsMock,
};
16 changes: 9 additions & 7 deletions test/departments.test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
const department = require("../index")
const department = require("../index");
const { allDepartmentMock, arrondissementsMock } = require("../mock/galsenify.test.mock");


describe("Department testing", () => {
test("receive the department", () => {
const departmentName = department.allDepartments();
expect(departmentName.length).toEqual(departmentName.length);
expect(departmentName).toContain("Dakar");
expect(departmentName.length).toEqual(allDepartmentMock.length);
expect(departmentName).toEqual(allDepartmentMock);
});

test("receive the arrondissements of passing department", () => {
const arrondissements = department.arrondissements("Pikine");
expect(arrondissements.length).toBeGreaterThan(0);
expect(arrondissements).toContain("Thiaroye");
expect(arrondissements.length).toEqual(arrondissementsMock.length);
expect(arrondissements).toEqual(arrondissementsMock);
});

test("receive the arrrondissements of passing department should fail", () => {
expect(() => department.arrondissements("Yeumbeul")).toThrow();
expect(() => department.arrondissements("")).toThrow();
expect(() => department.arrondissements("Yeumbeul")).toThrow("Oups! Ce n'est pas un Département valide !");
expect(() => department.arrondissements("")).toThrow("Oups! Ce n'est pas un Département valide !");
});

});
26 changes: 14 additions & 12 deletions test/galsenify.test.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
const galsenify = require('../index');
const {regionNamesMock, departmentsMock, codeMock, languesNationalesMock} = require('../mock/galsenify.test.mock');

describe("galsenify testing", () => {
test("receive the regions", () => {
const regionNames = galsenify.regions();
expect(regionNames.length).toEqual(regionNames.length);
expect(regionNames).toContain("Dakar");
expect(regionNames.length).toEqual(14);
expect(regionNames).toEqual(regionNamesMock);
});

test("receive the departments of passing region", () => {
const departments = galsenify.departments("Dakar");
expect(departments.length).toBeGreaterThan(0);
expect(departments).toContain("Pikine");
expect(departments.length).toEqual(departmentsMock.length);
expect(departments).toEqual(departmentsMock);
});

test("receive the departments of passing region should fail", () => {
expect(() => galsenify.departments("Adidjan")).toThrow();
expect(() => galsenify.departments("")).toThrow();
expect(() => galsenify.departments("Adidjan")).toThrow("Oups! Ce n'est pas une région valide !");
expect(() => galsenify.departments("")).toThrow("Oups! Ce n'est pas une région valide !");
});

test("receive the codes", () => {
const codes = galsenify.codes();
expect(codes.length).toBeGreaterThan(0);
expect(codes).toEqual(codeMock);
expect(codes.length).toEqual(codeMock.length);
});

test("receive the population of passing region", () => {
Expand All @@ -29,8 +31,8 @@ describe("galsenify testing", () => {
});

test("receive the population of passing region should be fail", () => {
expect(() => galsenify.population("Abidjan")).toThrow();
expect(() => galsenify.population("")).toThrow();
expect(() => galsenify.population("Abidjan")).toThrow("Oups! Ce n'est pas une région valide !");
expect(() => galsenify.population("")).toThrow("Oups! Ce n'est pas une région valide !");
});

test("receive the superficie of passing region", () => {
Expand All @@ -39,14 +41,14 @@ describe("galsenify testing", () => {
});

test("receive the superficie of passing region should be fail", () => {
expect(() => galsenify.superficie("Abidjan")).toThrow();
expect(() => galsenify.superficie("")).toThrow();
expect(() => galsenify.superficie("Abidjan")).toThrow("Oups! Ce n'est pas une région valide !");
expect(() => galsenify.superficie("")).toThrow("Oups! Ce n'est pas une région valide !");
});

test("receive the sn information", () => {
const sn = galsenify.sn();
expect(sn.pays).toBe("Sénégal");
expect(sn.capital).toBe("Dakar");
expect(galsenify.languesNationales()).toContain("Wolof");
expect(galsenify.languesNationales()).toEqual(languesNationalesMock);
});
});

0 comments on commit fb7a5de

Please sign in to comment.