Skip to content

Commit

Permalink
Merge pull request #171 from pelias/print-urls-instead-of-json
Browse files Browse the repository at this point in the history
feat(output): Print request URLs instead of JSON
  • Loading branch information
orangejulius authored Jul 3, 2019
2 parents b30e4e6 + f909fb4 commit e082c0f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/validate_test_suites.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ var util = require( 'util' );

var validTestStatuses = [ 'pass', 'fail', undefined ];

function setEndpoint(testCase, testSuite) {
testCase.endpoint = testCase.endpoint || testSuite.endpoint || 'search';
}

function validateTestSuite(testSuite) {
return testSuite.tests.map( function ( testCase ){
if( validTestStatuses.indexOf( testCase.status ) === -1 ){
Expand All @@ -11,6 +15,9 @@ function validateTestSuite(testSuite) {
);
}

// ensure endpoint is set for later use
setEndpoint(testCase, testSuite);

if( 'unexpected' in testCase ){
testCase.unexpected.properties.forEach( function ( props ){
if( typeof props !== 'object' ){
Expand Down
33 changes: 31 additions & 2 deletions output_generators/terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,38 @@
require( 'colors' );

var util = require( 'util' );
const url = require('url');

var percentageForDisplay = require('../lib/percentageForDisplay');
var testSuiteHelpers = require('../lib/test_suite_helpers');

function inputToUrl(testCase) {
const path = `/v1/${testCase.endpoint}`;

const paramStrings = [];

const priorityParams = ['point.lat', 'point.lon', 'text'];

Object.keys(testCase.in).forEach(function(key) {
// skip keys already in the priority list
if (priorityParams.includes(key)) {
return;
} else {
paramStrings.push(`${key}=${testCase.in[key]}`);
}
});

// ensure priority params are last
priorityParams.forEach(function (priorityParam) {
if (testCase.in[priorityParam]) {
paramStrings.push(`${priorityParam}=${testCase.in[priorityParam]}`);
}
});

return `${path}?${paramStrings.join('&')}`;
}


/**
* Format and print a test result to the terminal.
*/
Expand All @@ -20,7 +48,8 @@ function prettyPrintTestCase( testCase, quiet ){
var id = result.testCase.id;
delete result.testCase.in.api_key; // don't display API key

var input = JSON.stringify(result.testCase.in);
const query = inputToUrl(testCase);

var expectationCount;

if (result.testCase.expected && result.testCase.expected.properties) {
Expand All @@ -30,7 +59,7 @@ function prettyPrintTestCase( testCase, quiet ){
}

var expectationString = (expectationCount > 1) ? ' (' + expectationCount + ' expectations)' : '';
var testDescription = input + expectationString;
var testDescription = query + expectationString;

var status = (result.progress === undefined) ? '' : result.progress.inverse + ' ';
switch( result.result ){
Expand Down

0 comments on commit e082c0f

Please sign in to comment.