diff --git a/.dockerignore b/.dockerignore index c6256632b5a0b1101af6e4df2c337f4bee52c8f7..1d8309a56b34f50343a9534ec68217e30754cb64 100644 --- a/.dockerignore +++ b/.dockerignore @@ -7,3 +7,4 @@ Dockerfile package-lock.json node_modules *.bak +.editorconfig diff --git a/.gitignore b/.gitignore index 6e5cd7f08c0c8ac4153ac494b7101428d7fa352d..73ebd01968826de5bb4291d1bcd9d54c64e1d6e8 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ /dist *.bak .env +docker-compose.yaml +.editorconfig diff --git a/CHANGELOG.md b/CHANGELOG.md index bc0fd63cfd605259638bf29e088aef23b4c340be..0bc14ae747a9f066d3bcb7942fd77efb7c8084e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.0.2 - 05-02-2019 +### Added +- EnunHandler to handle types of inputs #4 (Horstmann) + + ## 0.0.1 - 04-02-2019 ### Added - This CHANGELOG file to hopefully serve as an evolving example of a standardized open source project CHANGELOG. diff --git a/package.json b/package.json index f20ba8a39c7616b04300a63fe1c7df3d11fa00e0..e2ae36209674529b434e1e7a34a55dba7d227cca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "form-creator-api", - "version": "0.0.1", + "version": "0.0.2", "description": "RESTful API used to manage and answer forms.", "main": "index.js", "scripts": { diff --git a/src/utils/enumHandler.spec.ts b/src/utils/enumHandler.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..d861f6b96732601a420a67981ad0e4bc6811ee89 --- /dev/null +++ b/src/utils/enumHandler.spec.ts @@ -0,0 +1,46 @@ +/* + * form-creator-api. RESTful API to manage and answer forms. + * Copyright (C) 2019 Centro de Computacao Cientifica e Software Livre + * Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + * + * This file is part of form-creator-api. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +import { expect } from "chai"; +import { EnumHandler, InputType } from "./enumHandler"; + +describe("Enum Handler", () => { + + it("should stringfy input ", () => { + + const inputNone = EnumHandler.stringfyInputType(InputType.NONE); + const inputText = EnumHandler.stringfyInputType(InputType.TEXT); + expect(inputNone).to.be.equal(""); + expect(inputText).to.be.equal("text"); + }); + + it("should parse string to InputType", () => { + const inputText = EnumHandler.parseInputType("text"); + const inputTextCapitalLetters = EnumHandler.parseInputType("TEXT"); + const inputNone = EnumHandler.parseInputType(""); + const inputFOOL = EnumHandler.parseInputType("fool"); + expect(inputText).to.be.equal(InputType.TEXT); + expect(inputTextCapitalLetters).to.be.equal(InputType.TEXT); + expect(inputNone).to.be.equal(InputType.NONE); + expect(inputFOOL).to.be.equal(InputType.NONE); + }); + +}); diff --git a/src/utils/enumHandler.ts b/src/utils/enumHandler.ts new file mode 100644 index 0000000000000000000000000000000000000000..3e359416de4e2a51f3a1899ffe68d0682e5aca68 --- /dev/null +++ b/src/utils/enumHandler.ts @@ -0,0 +1,63 @@ +/* + * form-creator-api. RESTful API to manage and answer forms. + * Copyright (C) 2019 Centro de Computacao Cientifica e Software Livre + * Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + * + * This file is part of form-creator-api. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ + +/** + * Available Input types + */ +export enum InputType { + /** Used as error code. No suitable input found. */ + NONE, + /** Text type, when input is a text */ + TEXT +} + +/** + * Enum's handler. Manage parse through the project. + */ + +export class EnumHandler { + /** + * Parse an enum(Input type) to string. + * @param a - Input type to be stringified. + */ + public static stringfyInputType(a: InputType): string { + switch (a) { + case InputType.TEXT: + return "text"; + default: + return ""; + } + } + /** + * Parse a string to enum(InputType). + * @param str - InputType in string format. + */ + public static parseInputType(str: string): InputType { + str = str.toLocaleLowerCase(); + switch (str) { + case "text": + return InputType.TEXT; + default: + return InputType.NONE; + } + } + + }