-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from matheuspiment/development
Melhorias nos testes e no CI
- Loading branch information
Showing
7 changed files
with
102 additions
and
97 deletions.
There are no files selected for viewing
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
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
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,57 @@ | ||
/** | ||
* Checks for an established connection. | ||
* @function | ||
* @throws {Error} Connection does not exists. | ||
*/ | ||
export const hasClient = (client) => { | ||
if (client === undefined || null) { | ||
throw new Error('Connection undefined'); | ||
} | ||
}; | ||
|
||
/** | ||
* The allowed keys on the message object. | ||
* @constant {array} | ||
*/ | ||
const MESSAGE_KEYS = ['id', 'title', 'type', 'description']; | ||
|
||
/** | ||
* Checks if the message is valid. | ||
* @function | ||
* @param {!object} message A javascript object | ||
* @throws {Error} The message must be an object. | ||
* @throws {Error} The message does not have all the expected keys. | ||
* @throws {Error} The message contains invalid keys. | ||
* @throws {Error} The value for the ${key} must be a number|string. | ||
*/ | ||
export const checkMessage = (message) => { | ||
if (typeof message !== 'object') { | ||
throw new Error('The message must be an object'); | ||
} | ||
|
||
const messageKeys = Object.keys(message); | ||
|
||
if (messageKeys.length < 4) { | ||
throw new Error('The message does not have all the expected keys'); | ||
} | ||
|
||
const unMatchedKeys = messageKeys.filter(key => !MESSAGE_KEYS.includes(key)); | ||
|
||
if (unMatchedKeys.length > 0) { | ||
throw new Error(`The message contains invalid keys:\n ${unMatchedKeys}`); | ||
} | ||
|
||
let value; | ||
|
||
MESSAGE_KEYS.forEach((key) => { | ||
value = message[key]; | ||
|
||
if (key !== 'id') { | ||
if (typeof value !== 'string') { | ||
throw new Error(`The value for the ${key} must be a string`); | ||
} | ||
} else if (typeof value !== 'number') { | ||
throw new Error('The value for the id must be a number'); | ||
} | ||
}); | ||
}; |
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 |
---|---|---|
|
@@ -497,6 +497,10 @@ argv-formatter@~1.0.0: | |
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/argv-formatter/-/argv-formatter-1.0.0.tgz#a0ca0cbc29a5b73e836eebe1cbf6c5e0e4eb82f9" | ||
|
||
[email protected]: | ||
version "0.0.2" | ||
resolved "https://registry.yarnpkg.com/argv/-/argv-0.0.2.tgz#ecbd16f8949b157183711b1bda334f37840185ab" | ||
|
||
aria-query@^0.7.0: | ||
version "0.7.1" | ||
resolved "https://registry.yarnpkg.com/aria-query/-/aria-query-0.7.1.tgz#26cbb5aff64144b0a825be1846e0b16cfa00b11e" | ||
|
@@ -1708,12 +1712,6 @@ chai@^4.1.2: | |
pathval "^1.0.0" | ||
type-detect "^4.0.0" | ||
|
||
"chainsaw@>=0.0.7 <0.1": | ||
version "0.0.9" | ||
resolved "https://registry.yarnpkg.com/chainsaw/-/chainsaw-0.0.9.tgz#11a05102d1c4c785b6d0415d336d5a3a1612913e" | ||
dependencies: | ||
traverse ">=0.3.0 <0.4" | ||
|
||
[email protected], chalk@^1.0.0, chalk@^1.1.1, chalk@^1.1.3: | ||
version "1.1.3" | ||
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98" | ||
|
@@ -1905,6 +1903,14 @@ code-point-at@^1.0.0: | |
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77" | ||
|
||
[email protected]: | ||
version "3.0.2" | ||
resolved "https://registry.yarnpkg.com/codecov/-/codecov-3.0.2.tgz#aea43843a5cd2fb6b7e488b2eff25d367ab70b12" | ||
dependencies: | ||
argv "0.0.2" | ||
request "^2.81.0" | ||
urlgrey "0.4.4" | ||
|
||
collapse-white-space@^1.0.0: | ||
version "1.0.4" | ||
resolved "https://registry.yarnpkg.com/collapse-white-space/-/collapse-white-space-1.0.4.tgz#ce05cf49e54c3277ae573036a26851ba430a0091" | ||
|
@@ -3822,12 +3828,6 @@ hash.js@^1.0.0, hash.js@^1.0.3: | |
inherits "^2.0.3" | ||
minimalistic-assert "^1.0.0" | ||
|
||
"hashish@>=0.0.2 <0.1": | ||
version "0.0.4" | ||
resolved "https://registry.yarnpkg.com/hashish/-/hashish-0.0.4.tgz#6d60bc6ffaf711b6afd60e426d077988014e6554" | ||
dependencies: | ||
traverse ">=0.2.4" | ||
|
||
[email protected]: | ||
version "1.1.1" | ||
resolved "https://registry.yarnpkg.com/he/-/he-1.1.1.tgz#93410fd21b009735151f8868c2f271f3427e23fd" | ||
|
@@ -7229,12 +7229,6 @@ remove-trailing-separator@^1.0.1: | |
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz#c24bce2a283adad5bc3f58e0d48249b92379d8ef" | ||
|
||
[email protected]: | ||
version "0.1.5" | ||
resolved "https://registry.yarnpkg.com/remove/-/remove-0.1.5.tgz#095ffd827d65c9f41ad97d33e416a75811079955" | ||
dependencies: | ||
seq ">= 0.3.5" | ||
|
||
repeat-element@^1.1.2: | ||
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/repeat-element/-/repeat-element-1.1.2.tgz#ef089a178d1483baae4d93eb98b4f9e4e11d990a" | ||
|
@@ -7263,7 +7257,7 @@ request-promise-native@^1.0.5: | |
stealthy-require "^1.1.0" | ||
tough-cookie ">=2.3.3" | ||
|
||
request@^2.72.0, request@^2.83.0: | ||
request@^2.72.0, request@^2.81.0, request@^2.83.0: | ||
version "2.87.0" | ||
resolved "https://registry.yarnpkg.com/request/-/request-2.87.0.tgz#32f00235cd08d482b4d0d68db93a829c0ed5756e" | ||
dependencies: | ||
|
@@ -7628,13 +7622,6 @@ semver@~2.3.1: | |
version "2.3.2" | ||
resolved "https://registry.yarnpkg.com/semver/-/semver-2.3.2.tgz#b9848f25d6cf36333073ec9ef8856d42f1233e52" | ||
|
||
"seq@>= 0.3.5": | ||
version "0.3.5" | ||
resolved "https://registry.yarnpkg.com/seq/-/seq-0.3.5.tgz#ae02af3a424793d8ccbf212d69174e0c54dffe38" | ||
dependencies: | ||
chainsaw ">=0.0.7 <0.1" | ||
hashish ">=0.0.2 <0.1" | ||
|
||
set-blocking@^2.0.0, set-blocking@~2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7" | ||
|
@@ -8262,14 +8249,10 @@ tr46@^1.0.1: | |
dependencies: | ||
punycode "^2.1.0" | ||
|
||
traverse@>=0.2.4, traverse@^0.6.6, traverse@~0.6.6: | ||
traverse@^0.6.6, traverse@~0.6.6: | ||
version "0.6.6" | ||
resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.6.6.tgz#cbdf560fd7b9af632502fed40f918c157ea97137" | ||
|
||
"traverse@>=0.3.0 <0.4": | ||
version "0.3.9" | ||
resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.3.9.tgz#717b8f220cc0bb7b44e40514c22b2e8bbc70d8b9" | ||
|
||
[email protected]: | ||
version "5.0.0" | ||
resolved "https://registry.yarnpkg.com/travis-deploy-once/-/travis-deploy-once-5.0.0.tgz#5fd23709db3104d18f48778df969409340b583d1" | ||
|
@@ -8518,6 +8501,10 @@ url@^0.11.0: | |
punycode "1.3.2" | ||
querystring "0.2.0" | ||
|
||
[email protected]: | ||
version "0.4.4" | ||
resolved "https://registry.yarnpkg.com/urlgrey/-/urlgrey-0.4.4.tgz#892fe95960805e85519f1cd4389f2cb4cbb7652f" | ||
|
||
use@^3.1.0: | ||
version "3.1.0" | ||
resolved "https://registry.yarnpkg.com/use/-/use-3.1.0.tgz#14716bf03fdfefd03040aef58d8b4b85f3a7c544" | ||
|