Commit fa73adc5 authored by Lucas Fernandes de Oliveira's avatar Lucas Fernandes de Oliveira

Merge branch '4-criar-enumhandler' into 'develop'

Issue #4: Create EnumHandler and InputType

See merge request !4
parents 4eb25ff0 d92d3039
Pipeline #19237 passed with stages
in 28 seconds
......@@ -7,3 +7,4 @@ Dockerfile
package-lock.json
node_modules
*.bak
.editorconfig
......@@ -15,3 +15,5 @@
/dist
*.bak
.env
docker-compose.yaml
.editorconfig
......@@ -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.
......
{
"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": {
......
/*
* 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);
});
});
/*
* 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;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment