Skip to content

Commit

Permalink
feat: getSpecialName
Browse files Browse the repository at this point in the history
  • Loading branch information
singuerinc committed Feb 20, 2019
1 parent e245096 commit 80a21c8
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 1 deletion.
16 changes: 16 additions & 0 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions src/getSpecialName.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { SPECIALS } from "./specials";
import { getSpecialCode } from "./getSpecialCode";

/**
* Returns the special name for a valid car plate
* @param {string} value
* @returns {string}
* @since 0.0.7
* @example
* getSpecialCode("CME1234"); // => "Corps of the Mossos d'Esquadra"
*/
function getSpecialName(value) {
const str = !value ? "" : value;
const code = getSpecialCode(str);

return SPECIALS[code] || null;
}

export { getSpecialName };
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export { isSpecial } from "./isSpecial";
export { getCounter } from "./getCounter";
export { getNumber } from "./getNumber";
export { getSpecialCode } from "./getSpecialCode";
export { getSpecialName } from "./getSpecialName";
export { getProvinceName } from "./getProvinceName";
export { getProvinceCode } from "./getProvinceCode";
export { parse } from "./parse";
Expand Down
102 changes: 102 additions & 0 deletions test/getSpecialName.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
const assert = require("assert");
const { getSpecialName } = require("../dist/index");

describe("#getSpecialName", () => {
describe("invalid", () => {
describe("special plates only", () => {
it("should work only with special plates 1", () => {
assert.equal(getSpecialName("1234BCD"), null);
});

it("should work only with special plates 2", () => {
assert.equal(getSpecialName("A 1234 BL"), null);
});
});

describe("unknown special", () => {
it("should not work with unknown code", () => {
assert.equal(getSpecialName("AAA1234"), null);
});
});

describe("wrong input", () => {
it("should return null with null", () => {
assert.equal(getSpecialName(null), null);
});

it("should return null with undefined", () => {
assert.equal(getSpecialName(undefined), null);
});

it("should return null with empty", () => {
assert.equal(getSpecialName(""), null);
});
});
});

describe("valid", () => {
it("should get CME", () => {
assert.equal(getSpecialName("CME1234"), "Corps of the Mossos d'Esquadra");
});

it("should get DGP", () => {
assert.equal(getSpecialName("DGP1234"), "Spanish Police");
});

it("should get CNP", () => {
assert.equal(getSpecialName("CNP1234"), "Spanish Police");
});

it("should get E", () => {
assert.equal(getSpecialName("E1234"), "Autonomous police force of the Basque Country");
});

it("should get EA", () => {
assert.equal(getSpecialName("EA1234"), "Air Force");
});

it("should get ET", () => {
assert.equal(getSpecialName("ET1234"), "Spanish Army");
});

it("should get FAE", () => {
assert.equal(getSpecialName("FAE1234"), "Allied Forces in Spain");
});

it("should get FN", () => {
assert.equal(getSpecialName("FN1234"), "Spanish Navy");
});

it("should get GSH", () => {
assert.equal(getSpecialName("GSH1234"), "Colonial police on Sahara");
});

it("should get PGC", () => {
assert.equal(getSpecialName("PGC1234"), "Spanish civil guard");
});

it("should get MF", () => {
assert.equal(getSpecialName("MF1234"), "Public Works Ministry");
});

it("should get MMA", () => {
assert.equal(getSpecialName("MMA1234"), "Environment Ministry");
});

it("should get MOP", () => {
assert.equal(getSpecialName("MOP1234"), "Public Works Ministry");
});

it("should get PME", () => {
assert.equal(getSpecialName("PME1234"), "State owned vehicles");
});

it("should get PMM", () => {
assert.equal(getSpecialName("PMM1234"), "State owned vehicles, on a Ministry");
});

it("should get Crown", () => {
assert.equal(getSpecialName("Crown1234"), "King's Car");
});
});
});
5 changes: 5 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
getProvinceName,
getProvinceCode,
getSpecialCode,
getSpecialName,
PROVINCES
} = require("../dist/index");

Expand Down Expand Up @@ -40,6 +41,10 @@ describe("api", () => {
assert.ok(getSpecialCode);
});

it("should export getSpecialName", () => {
assert.ok(getSpecialName);
});

it("should export getCounter", () => {
assert.ok(getCounter);
});
Expand Down

0 comments on commit 80a21c8

Please sign in to comment.