This repository has been archived by the owner on May 3, 2022. It is now read-only.
-
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
Showing
11 changed files
with
1,384 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module.exports = { | ||
extends: [ | ||
'@macpaw/eslint-config-webservices/rules/base', | ||
'@macpaw/eslint-config-webservices/rules/filenames', | ||
'@macpaw/eslint-config-webservices/rules/promise', | ||
], | ||
parser: 'espree', | ||
parserOptions: { | ||
ecmaVersion: 8, | ||
sourceType: 'script', | ||
}, | ||
plugins: ['async-await'], | ||
rules: { | ||
strict: ['warn', 'global'], | ||
'no-unused-expressions': ['off'], | ||
'newline-after-var': ['off'], | ||
'filenames/match-regex': ['off'], | ||
}, | ||
}; |
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,2 @@ | ||
.idea/ | ||
node_modules |
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 |
---|---|---|
@@ -1 +1,17 @@ | ||
# qa-api-services | ||
# qa-api-services | ||
|
||
## Contributing guide | ||
1. Create feature branch and perform changes. | ||
2. Push changes to the origin and create pull-request. | ||
3. After pull-request merging update local master. | ||
4. Bump version and add a tag (for example using `npm version`). | ||
5. Push changes to the origin. | ||
6. Publish new version to NPM. | ||
|
||
**TIP**: you can use [np](https://github.com/sindresorhus/np) to perform steps 4-6 automatically | ||
|
||
## Versioning rules | ||
Given a version number MAJOR.MINOR.PATCH, increment the: | ||
* **patch** - when you make backwards-compatible bug fixes | ||
* **minor** - when you add functionality in a backwards-compatible manner | ||
* **major** - when you make incompatible API changes |
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,8 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
logger: require('./libs/logger'), | ||
request: require('./libs/request'), | ||
requestHelper: require('./libs/request-helper'), | ||
waiters: require('./libs/waiters') | ||
}; |
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,17 @@ | ||
'use strict'; | ||
|
||
const chalk = require('chalk'); | ||
|
||
module.exports = { | ||
info(message) { | ||
console.log(chalk.yellow(message)); | ||
}, | ||
|
||
error(message) { | ||
console.log(chalk.red(message)); | ||
}, | ||
|
||
success(message) { | ||
console.log(chalk.green(message)); | ||
}, | ||
}; |
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,31 @@ | ||
'use strict'; | ||
|
||
const request = require('then-request'); | ||
|
||
module.exports = { | ||
isSuccess(statusCode) { | ||
const regExp = new RegExp('^20[0-9]$'); | ||
|
||
return regExp.test(statusCode); | ||
}, | ||
|
||
isServerError(statusCode) { | ||
const regExp = new RegExp('^5[0-1][0-9]$'); | ||
|
||
return regExp.test(statusCode); | ||
}, | ||
|
||
async getResponseBody(method, url, options) { | ||
return request(method, url, options); | ||
}, | ||
|
||
catchError(response) { | ||
const body = response.body.toString(); | ||
|
||
if (!this.isSuccess(response.statusCode)) { | ||
throw new Error(`Server responded with code ${response.statusCode}: ${body}`); | ||
} | ||
|
||
return body ? JSON.parse(body) : {}; | ||
}, | ||
}; |
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,35 @@ | ||
'use strict'; | ||
|
||
const requestHelper = require('./request-helper'); | ||
|
||
module.exports = { | ||
get(url, options) { | ||
const response = browser.call(() => requestHelper.getResponseBody('GET', url, options)); | ||
|
||
return requestHelper.catchError(response); | ||
}, | ||
|
||
post(url, options) { | ||
const response = browser.call(() => requestHelper.getResponseBody('POST', url, options)); | ||
|
||
return requestHelper.catchError(response); | ||
}, | ||
|
||
patch(url, options) { | ||
const response = browser.call(() => requestHelper.getResponseBody('PATCH', url, options)); | ||
|
||
return requestHelper.catchError(response); | ||
}, | ||
|
||
put(url, options) { | ||
const response = browser.call(() => requestHelper.getResponseBody('PUT', url, options)); | ||
|
||
return requestHelper.catchError(response); | ||
}, | ||
|
||
del(url, options) { | ||
const response = browser.call(() => requestHelper.getResponseBody('DELETE', url, options)); | ||
|
||
return requestHelper.catchError(response); | ||
}, | ||
}; |
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,25 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
*waitFor(func, strategy, {timeout = 90000, interval = 2500, message, time}) { | ||
const timeStart = Date.now(); | ||
|
||
const getData = () => new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve(func()); | ||
}, interval); | ||
}); | ||
|
||
let result = yield getData(); | ||
|
||
while (true) { | ||
if (strategy(result, time)) { | ||
return result; | ||
} else if (Date.now() - timeStart < timeout) { | ||
result = yield getData(); | ||
} else { | ||
throw new Error(message || 'Timeout reached'); | ||
} | ||
} | ||
}, | ||
}; |
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,5 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
apiServices: require('./api-services/'), | ||
}; |
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,32 @@ | ||
{ | ||
"name": "qa-api-services", | ||
"version": "0.0.0", | ||
"description": "QA API libraries for Macpaw projects", | ||
"main": "index.js", | ||
"author": "Volodymyr Dobrygin", | ||
"contributors": [ | ||
"Maksym Shykov", | ||
"Vladyslav Filimonov", | ||
"Andrii Pocherpailo" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "[email protected]:MacPaw/qa-api-services.git" | ||
}, | ||
"license": "UNLICENSED", | ||
"scripts": { | ||
"lint": "$(npm bin)/eslint --max-warnings 0 ." | ||
}, | ||
"dependencies": { | ||
"chalk": "^2.4.1", | ||
"then-request": "^6.0.2" | ||
}, | ||
"devDependencies": { | ||
"@macpaw/eslint-config-webservices": "^1.1.0", | ||
"babel-eslint": "^8.2.3", | ||
"eslint": "^4.19.1", | ||
"eslint-plugin-async-await": "0.0.0", | ||
"eslint-plugin-filenames": "^1.2.0", | ||
"eslint-plugin-promise": "^3.7.0" | ||
} | ||
} |
Oops, something went wrong.