-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow multiple server display via option (#381)
* allow multiple server display via option * changed comment * fixed tests
- Loading branch information
Showing
8 changed files
with
137 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module.exports = function (options) { | ||
const { url, server, servers } = options?.data?.root || {} | ||
|
||
const displayAllServers = | ||
options?.data?.root?.allOptions?.specData?.spectaql?.displayAllServers === | ||
true | ||
if (!displayAllServers) { | ||
if (url) { | ||
return url | ||
} | ||
if (server?.url) { | ||
return server.url | ||
} | ||
const fallbackServer = | ||
servers?.find((server) => server.url && server.production) || | ||
servers?.find((server) => server.url) | ||
if (fallbackServer) { | ||
return fallbackServer.url | ||
} | ||
} | ||
|
||
if (!servers?.length) { | ||
return '<<url is missing>>' | ||
} | ||
|
||
return servers | ||
.map( | ||
(server) => | ||
'# ' + | ||
(server.description?.trim() || 'Endpoint') + | ||
':\n' + | ||
(server.url?.trim() || '<<url is missing>>') + | ||
'\n' | ||
) | ||
.join('') | ||
} |
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,86 @@ | ||
const generateApiEndpoints = require('../../../dist/themes/default/helpers/generateApiEndpoints') | ||
|
||
describe('generateApiEndpoints', function () { | ||
def('displayAllServers', false) | ||
def('production', true) | ||
|
||
def('options', () => ({ | ||
data: { | ||
root: { | ||
allOptions: { | ||
specData: { | ||
spectaql: { | ||
displayAllServers: $.displayAllServers, | ||
}, | ||
}, | ||
}, | ||
url: $.url, | ||
server: $.server, | ||
servers: $.servers, | ||
}, | ||
}, | ||
})) | ||
|
||
def('url', () => 'foorl') | ||
def('server', () => ({ | ||
url: 'serverFoorl', | ||
})) | ||
def('servers', () => [ | ||
{ | ||
url: 'server1url', | ||
description: 'Server One', | ||
}, | ||
{ | ||
url: 'server2url', | ||
description: 'Server Two', | ||
production: $.production, | ||
}, | ||
]) | ||
|
||
context('displayAllServers is false', function () { | ||
it('uses url', function () { | ||
expect(generateApiEndpoints($.options)).to.eql('foorl') | ||
}) | ||
|
||
context('url is falsy', function () { | ||
def('url', () => undefined) | ||
|
||
it('uses server.url', function () { | ||
expect(generateApiEndpoints($.options)).to.eql('serverFoorl') | ||
}) | ||
|
||
context('server is falsy', function () { | ||
def('server', () => undefined) | ||
|
||
it('uses production server url', function () { | ||
expect(generateApiEndpoints($.options)).to.eql('server2url') | ||
}) | ||
|
||
context('production is false', function () { | ||
def('production', () => undefined) | ||
|
||
it('uses first server url', function () { | ||
expect(generateApiEndpoints($.options)).to.eql('server1url') | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
context('displayAllServers is true', function () { | ||
def('displayAllServers', () => true) | ||
|
||
it('works', function () { | ||
expect(generateApiEndpoints($.options)).to.eql( | ||
'# Server One:\nserver1url\n# Server Two:\nserver2url\n' | ||
) | ||
}) | ||
|
||
context('servers are empty', function () { | ||
def('servers', () => []) | ||
it('uses default message', function () { | ||
expect(generateApiEndpoints($.options)).to.eql('<<url is missing>>') | ||
}) | ||
}) | ||
}) | ||
}) |
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