Compare commits

..

No commits in common. "master" and "v0.11.1" have entirely different histories.

11 changed files with 849 additions and 625 deletions

42
LICENSE
View File

@ -1,41 +1,7 @@
“Commons Clause” License Condition v1.0 Copyright 2018 David Sergio Díaz
The Software is provided to you by the Licensor under the License, as defined Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
below, subject to the following condition.
Without limiting other conditions in the License, the grant of rights under the The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
License will not include, and the License does not grant to you, the right to
Sell the Software.
For purposes of the foregoing, “Sell” means practicing any or all of the rights THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
granted to you under the License to provide to third parties, for a fee or other
consideration (including without limitation fees for hosting or consulting/
support services related to the Software), a product or service whose value
derives, entirely or substantially, from the functionality of the Software. Any
license notice or attribution required by the License must also include this
Commons Clause License Condition notice.
Software: Beau
License: MIT
Licensor: David Díaz
---
Copyright 2020 David Díaz
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -18,7 +18,7 @@ class Base extends Command {
} }
let config let config
yaml.loadAll(fs.readFileSync(configFile, 'utf-8'), (doc) => { yaml.safeLoadAll(fs.readFileSync(configFile, 'utf-8'), (doc) => {
const valid = validate(doc) const valid = validate(doc)
if (!valid) { if (!valid) {

View File

@ -1,6 +1,5 @@
const clc = require('cli-color') const clc = require('cli-color')
const { Line } = require('clui') const { Line } = require('clui')
const { expandPath } = require('../../../src/shared')
const Base = require('../base') const Base = require('../base')
class ListCommand extends Base { class ListCommand extends Base {
@ -32,7 +31,9 @@ class ListCommand extends Base {
.padding(2) .padding(2)
.column(VERB, 20, [clc.yellow]) .column(VERB, 20, [clc.yellow])
.column(ALIAS, 30, [clc.yellow]) .column(ALIAS, 30, [clc.yellow])
.column(expandPath(ENDPOINT, PATH)) .column(
ENDPOINT.replace(/\/$/, '') + '/' + PATH.replace(/^\//, '')
)
.output() .output()
) )

View File

@ -4,7 +4,6 @@ const clc = require('cli-color')
const prompts = require('prompts') const prompts = require('prompts')
const { Line, Spinner } = require('clui') const { Line, Spinner } = require('clui')
const { flags } = require('@oclif/command') const { flags } = require('@oclif/command')
const { expandPath } = require('../../../src/shared')
class RequestCommand extends Base { class RequestCommand extends Base {
prettyOutput(res, verbose = false) { prettyOutput(res, verbose = false) {
@ -70,13 +69,13 @@ class RequestCommand extends Base {
({ VERB, ALIAS, ENDPOINT, PATH }) => ({ ({ VERB, ALIAS, ENDPOINT, PATH }) => ({
title: `${VERB} ${PATH} - ${ALIAS}`, title: `${VERB} ${PATH} - ${ALIAS}`,
value: ALIAS, value: ALIAS,
description: expandPath(ENDPOINT, PATH) description: `${ENDPOINT}${PATH}`
}) })
) )
const { name } = await prompts({ const { name } = await prompts({
name: 'name', name: 'name',
message: 'Pick a Request to execute', message: 'Pick as Request to execute',
type: 'select', type: 'select',
choices: requests choices: requests
}) })

View File

@ -1,37 +1,19 @@
endpoint: https://pokeapi.co/api/v2/ endpoint: https://pokeapi.co/api/v2
# Try replacing this pokemon using params: # Try replacing this pokemon using params:
# beau request get-pokemon -P "pokemon=dragapult" # beau request get-pokemon -P "pokemon=dragapult"
environment: environment:
_: _:
pokemon: ditto pokemon: ditto
cookiejar: true
GET /pokemon/$env._.pokemon: get-pokemon GET /pokemon/$env._.pokemon: get-pokemon
GET $get-pokemon.body.location_area_encounters: get-encounters GET $get-pokemon.body.location_area_encounters: get-encounters
POST https://httpbin.org/anything: POST https://httpbin.org/anything:
- alias: post-first-area - alias: post-first-area
payload: payload:
area: $get-encounters.body.0.location_area.name area: $get-encounters.body.0.location_area.name
- alias: post-pokemon-type - alias: post-pokemon-type
payload: payload:
type: $get-pokemon.body.types.0.type.name type: $get-pokemon.body.types.0.type.name
- alias: form-submission
form:
name: Dragapult
- alias: file-upload
formdata:
name: Beau
logo: $[createReadStream('../media/beau.png')]
GET https://httpbin.org/status/418: teapot
GET https://httpbin.org/cookies/set:
alias: set-cookies
params:
hello: World

1310
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,10 @@
{ {
"name": "beau", "name": "beau",
"version": "0.11.3", "version": "0.11.1",
"description": "Testing APIs made easy.", "description": "Testing APIs made easy.",
"main": "./src/beau.js", "main": "./src/beau.js",
"author": "David Díaz <seich@martianwabbit.com>", "author": "Sergio Diaz <seich@martianwabbit.com>",
"license": "MIT + Commons Clause", "license": "MIT",
"scripts": { "scripts": {
"test": "jest -i", "test": "jest -i",
"test:coverage": "jest --coverage ./src", "test:coverage": "jest --coverage ./src",
@ -17,19 +17,19 @@
"dependencies": { "dependencies": {
"@oclif/command": "1.8.0", "@oclif/command": "1.8.0",
"@oclif/config": "1.17.0", "@oclif/config": "1.17.0",
"@oclif/plugin-help": "3.2.1", "@oclif/plugin-help": "3.2.0",
"@oclif/plugin-warn-if-update-available": "1.7.0", "@oclif/plugin-warn-if-update-available": "1.7.0",
"ajv": "7.0.3", "ajv": "7.0.0-beta.6",
"beau-std": "0.9.4", "beau-std": "0.9.4",
"better-ajv-errors": "0.7.0", "better-ajv-errors": "0.6.7",
"cli-color": "2.0.0", "cli-color": "2.0.0",
"clui": "0.3.6", "clui": "0.3.6",
"color-json": "2.0.1", "color-json": "2.0.1",
"deepmerge": "4.2.2", "deepmerge": "4.2.2",
"dotenv": "8.2.0", "dotenv": "8.2.0",
"globby": "11.0.2", "globby": "11.0.1",
"is-plain-object": "5.0.0", "is-plain-object": "5.0.0",
"js-yaml": "4.0.0", "js-yaml": "3.14.0",
"prompts": "2.4.0", "prompts": "2.4.0",
"request": "2.88.2", "request": "2.88.2",
"request-promise-native": "1.0.9", "request-promise-native": "1.0.9",
@ -40,7 +40,7 @@
"jest": "26.6.3", "jest": "26.6.3",
"jest-watch-typeahead": "0.6.1", "jest-watch-typeahead": "0.6.1",
"strip-ansi": "6.0.0", "strip-ansi": "6.0.0",
"np": "7.2.0" "np": "7.0.0"
}, },
"oclif": { "oclif": {
"commands": "./bin/cli/commands", "commands": "./bin/cli/commands",

View File

@ -11,7 +11,7 @@ describe(`Beau's config Loader.`, () => {
it('should load the config', () => { it('should load the config', () => {
moduleVersion.mockReturnValue(1) moduleVersion.mockReturnValue(1)
const doc = yaml.load(` const doc = yaml.safeLoad(`
version: 1 version: 1
endpoint: 'http://example.com' endpoint: 'http://example.com'
@ -27,7 +27,7 @@ describe(`Beau's config Loader.`, () => {
it(`should load the request list using the configuration`, () => { it(`should load the request list using the configuration`, () => {
moduleVersion.mockReturnValue(1) moduleVersion.mockReturnValue(1)
const doc = yaml.load(` const doc = yaml.safeLoad(`
version: 1 version: 1
endpoint: 'http://example.com' endpoint: 'http://example.com'

View File

@ -6,7 +6,7 @@ requireg.resolving = false
describe('Config', () => { describe('Config', () => {
it('should load valid config keys', () => { it('should load valid config keys', () => {
const doc = yaml.load(` const doc = yaml.safeLoad(`
version: 1 version: 1
endpoint: http://martianwabbit.com endpoint: http://martianwabbit.com
shouldntBeAdded: true shouldntBeAdded: true
@ -19,7 +19,7 @@ describe('Config', () => {
}) })
it('should load requests', () => { it('should load requests', () => {
const doc = yaml.load(` const doc = yaml.safeLoad(`
endpoint: http://example.com endpoint: http://example.com
GET /profile: get-profile GET /profile: get-profile
@ -36,7 +36,7 @@ describe('Config', () => {
}) })
it('should set up defaults for all requests', () => { it('should set up defaults for all requests', () => {
const doc = yaml.load(` const doc = yaml.safeLoad(`
version: 1 version: 1
endpoint: 'http://example.com' endpoint: 'http://example.com'
@ -60,7 +60,7 @@ describe('Config', () => {
}) })
it('should load multiple hosts', () => { it('should load multiple hosts', () => {
const doc = yaml.load(` const doc = yaml.safeLoad(`
version: 1 version: 1
endpoint: http://example.org endpoint: http://example.org
@ -105,7 +105,7 @@ describe('Config', () => {
}) })
it('should namespace all aliases within an host', () => { it('should namespace all aliases within an host', () => {
const doc = yaml.load(` const doc = yaml.safeLoad(`
hosts: hosts:
- host: test1 - host: test1
endpoint: http://example.com endpoint: http://example.com
@ -122,7 +122,7 @@ describe('Config', () => {
}) })
it(`should throw if host doesn't have a host key`, () => { it(`should throw if host doesn't have a host key`, () => {
const doc = yaml.load(` const doc = yaml.safeLoad(`
hosts: hosts:
- endpoint: http://example.com - endpoint: http://example.com
GET /posts: posts GET /posts: posts
@ -136,7 +136,7 @@ describe('Config', () => {
}) })
it(`should merge host settings with global settings`, () => { it(`should merge host settings with global settings`, () => {
const doc = yaml.load(` const doc = yaml.safeLoad(`
defaults: defaults:
headers: headers:
hello: 1 hello: 1
@ -159,7 +159,7 @@ describe('Config', () => {
}) })
it(`should allow different settings for the same request`, () => { it(`should allow different settings for the same request`, () => {
const doc = yaml.load(` const doc = yaml.safeLoad(`
host: https://example.com host: https://example.com
GET /1: GET /1:
- alias: req1 - alias: req1

View File

@ -5,8 +5,7 @@ const {
UpperCaseKeys, UpperCaseKeys,
removeOptionalKeys, removeOptionalKeys,
toKebabCase, toKebabCase,
replaceInObject, replaceInObject
expandPath
} = require('../shared') } = require('../shared')
describe('Shared Utilities', () => { describe('Shared Utilities', () => {
@ -73,26 +72,4 @@ describe('Shared Utilities', () => {
expect(replaceInObject(a, (obj) => 'a')).toEqual({ b: 'a', c: 'a' }) expect(replaceInObject(a, (obj) => 'a')).toEqual({ b: 'a', c: 'a' })
}) })
}) })
describe('expandPath', () => {
test.each([
['https://alchem.ee', 'api/v1/hello'],
['https://alchem.ee/', '/api/v1/hello'],
['https://alchem.ee', '/api/v1/hello'],
['https://alchem.ee/', 'api/v1/hello']
])(
'should add a base url to the path is the path is not a url: %s, %s',
(url, path) => {
expect(expandPath(url, path)).toEqual(
'https://alchem.ee/api/v1/hello'
)
}
)
it('should return the path if its a fully fledged url on its own', () => {
expect(
expandPath('https://alchem.ee', 'https://martianwabbit.com')
).toEqual('https://martianwabbit.com')
})
})
}) })

View File

@ -77,14 +77,6 @@ const isUrl = function (str) {
} }
} }
const expandPath = (url, path) => {
if (isUrl(path)) {
return path
}
return url.replace(/\/+$/, '') + '/' + path.replace(/^\/+/, '')
}
module.exports = { module.exports = {
requestRegex, requestRegex,
replacementRegex, replacementRegex,
@ -94,6 +86,5 @@ module.exports = {
toKebabCase, toKebabCase,
replaceInObject, replaceInObject,
moduleVersion, moduleVersion,
isUrl, isUrl
expandPath
} }