-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb6bfad
commit 79f6bd5
Showing
6 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters