Improved prompt descriptions.

I was really naive with combining urls and paths. This should fix it.
This commit is contained in:
David Diaz 2020-11-22 01:01:01 -06:00
parent 78596a154d
commit 23e9d5480c
4 changed files with 63 additions and 12 deletions

View File

@ -4,6 +4,7 @@ const clc = require('cli-color')
const prompts = require('prompts')
const { Line, Spinner } = require('clui')
const { flags } = require('@oclif/command')
const { expandPath } = require('../../../src/shared')
class RequestCommand extends Base {
prettyOutput(res, verbose = false) {
@ -69,7 +70,7 @@ class RequestCommand extends Base {
({ VERB, ALIAS, ENDPOINT, PATH }) => ({
title: `${VERB} ${PATH} - ${ALIAS}`,
value: ALIAS,
description: `${ENDPOINT}${PATH}`
description: expandPath(ENDPOINT, PATH)
})
)

View File

@ -1,19 +1,37 @@
endpoint: https://pokeapi.co/api/v2
endpoint: https://pokeapi.co/api/v2/
# Try replacing this pokemon using params:
# beau request get-pokemon -P "pokemon=dragapult"
environment:
_:
pokemon: ditto
_:
pokemon: ditto
cookiejar: true
GET /pokemon/$env._.pokemon: get-pokemon
GET $get-pokemon.body.location_area_encounters: get-encounters
POST https://httpbin.org/anything:
- alias: post-first-area
payload:
area: $get-encounters.body.0.location_area.name
- alias: post-first-area
payload:
area: $get-encounters.body.0.location_area.name
- alias: post-pokemon-type
payload:
type: $get-pokemon.body.types.0.type.name
- alias: post-pokemon-type
payload:
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

View File

@ -5,7 +5,8 @@ const {
UpperCaseKeys,
removeOptionalKeys,
toKebabCase,
replaceInObject
replaceInObject,
expandPath
} = require('../shared')
describe('Shared Utilities', () => {
@ -72,4 +73,26 @@ describe('Shared Utilities', () => {
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,6 +77,14 @@ const isUrl = function (str) {
}
}
const expandPath = (url, path) => {
if (isUrl(path)) {
return path
}
return url.replace(/\/+$/, '') + '/' + path.replace(/^\/+/, '')
}
module.exports = {
requestRegex,
replacementRegex,
@ -86,5 +94,6 @@ module.exports = {
toKebabCase,
replaceInObject,
moduleVersion,
isUrl
isUrl,
expandPath
}