From 9dea73e2c8bb859afb90c1253e148b640eb1f1c3 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Wed, 3 Jul 2019 14:35:57 -0400 Subject: [PATCH 1/2] chore(suites): Ensure endpoint is set on all test suites This makes determining the endpoint easier in later code. --- lib/validate_test_suites.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/validate_test_suites.js b/lib/validate_test_suites.js index 1fae045..407f226 100644 --- a/lib/validate_test_suites.js +++ b/lib/validate_test_suites.js @@ -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 ){ @@ -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' ){ From f909fb432a3450b5294915e03e2201801cb4956c Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Wed, 3 Jul 2019 14:46:42 -0400 Subject: [PATCH 2/2] feat(output): Print request URLs instead of JSON Changes test case output to print a URL instead of a JSON object. This makes it much easier to copy and paste the output of the fuzzy-tester and examine the results in a browser. Fixes https://github.com/pelias/fuzzy-tester/issues/58 Connects https://github.com/pelias/fuzzy-tester/issues/113 --- output_generators/terminal.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/output_generators/terminal.js b/output_generators/terminal.js index afde226..5b8b994 100644 --- a/output_generators/terminal.js +++ b/output_generators/terminal.js @@ -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. */ @@ -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) { @@ -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 ){