-
-
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.
client constructor now takes just ONE options argument BREAKING CHANGE: client constructor now takes just ONE options argument, with "server" property as an object or a string
- Loading branch information
Ahmad Nassri
committed
Mar 28, 2021
1 parent
a707d41
commit d408b0b
Showing
8 changed files
with
168 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const { test } = require('tap') | ||
|
||
const OASRequestError = require('../lib/error') | ||
|
||
const regex = /(\w|\/)+test\/error\.js:\d{2}:\d{2}/ | ||
|
||
test('Empty ExtendableError', assert => { | ||
assert.plan(5) | ||
|
||
const err = new OASRequestError('foobar') | ||
|
||
assert.type(err, OASRequestError) | ||
|
||
assert.equal(err.name, 'OASRequestError') | ||
assert.match(err.message, 'foobar') | ||
assert.match(err.stack, regex) | ||
assert.equal(err.toString(), 'OASRequestError: foobar') | ||
}) |
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,12 @@ | ||
const { test } = require('tap') | ||
|
||
const parsePathTemplate = require('../lib/parse-path-template') | ||
|
||
test('parse path templates', assert => { | ||
assert.plan(4) | ||
|
||
assert.equal(parsePathTemplate('/pets/{petId}'), '/pets/{petId}', 'keep variable template if no variables present') | ||
assert.equal(parsePathTemplate('/pets/{petId}', { petId: 'foo' }), '/pets/foo', 'replaces one value') | ||
assert.equal(parsePathTemplate('/{entity}/{id}', { entity: 'pet', id: '123' }), '/pet/123', 'replaces all the value') | ||
assert.equal(parsePathTemplate('/{entity}/{id}/{id}', { entity: 'pet', id: '123' }), '/pet/123/123', 'replaces the same value multiple times') | ||
}) |
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,82 @@ | ||
const { test } = require('tap') | ||
|
||
const parseServer = require('../lib/parse-server') | ||
const OASRequestError = require('../lib/error') | ||
|
||
test('throws if no server', assert => { | ||
assert.plan(1) | ||
|
||
assert.throws(() => parseServer(), new OASRequestError('missing argument: server')) | ||
}) | ||
|
||
test('throws if no server.url', assert => { | ||
assert.plan(1) | ||
|
||
assert.throws(() => parseServer({}), new OASRequestError('missing argument: server.url')) | ||
}) | ||
|
||
test('returns the server.url', assert => { | ||
assert.plan(1) | ||
|
||
const url = parseServer({ url: 'foo' }, {}) | ||
|
||
assert.equal(url, 'foo') | ||
}) | ||
|
||
test('returns the server if a string', assert => { | ||
assert.plan(1) | ||
|
||
const url = parseServer('foo', {}) | ||
|
||
assert.equal(url, 'foo') | ||
}) | ||
|
||
test('returns the server.url', assert => { | ||
assert.plan(1) | ||
|
||
const url = parseServer({ url: 'foo' }, {}) | ||
|
||
assert.equal(url, 'foo') | ||
}) | ||
|
||
test('populates the server.url with a defined spec.servers', assert => { | ||
assert.plan(1) | ||
|
||
const spec = { | ||
servers: [{ | ||
url: 'localhost' | ||
}] | ||
} | ||
|
||
const url = parseServer({ url: 'foo' }, spec) | ||
|
||
assert.equal(url, 'foo') | ||
}) | ||
|
||
test('populates the server.url with spec variables', assert => { | ||
assert.plan(1) | ||
|
||
const spec = { | ||
servers: [{ | ||
url: 'localhost', | ||
variables: { foo: { default: 'bar' } } | ||
}] | ||
} | ||
|
||
const url = parseServer({ url: 'localhost/{foo}' }, spec) | ||
|
||
assert.equal(url, 'localhost/bar') | ||
}) | ||
|
||
test('populates the server.url with server.variables', assert => { | ||
assert.plan(1) | ||
|
||
const spec = { | ||
servers: [{ | ||
url: 'localhost', | ||
variables: { foo: {} } | ||
}] | ||
} | ||
|
||
assert.equal(parseServer({ url: 'localhost/{foo}', variables: { foo: 'bar' } }, spec), 'localhost/bar') | ||
}) |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.