From 9b3cee2c28f6f0974965d179da6693f8d350f65e Mon Sep 17 00:00:00 2001 From: Alex Loyko Date: Tue, 24 Oct 2017 13:16:11 -0400 Subject: [PATCH] Added some tests --- .../predicates/is_intersection_layer.js | 77 +++++++++++++++++++ test/unit/helper/intersectionsParsing.js | 65 ++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 test/unit/controller/predicates/is_intersection_layer.js create mode 100644 test/unit/helper/intersectionsParsing.js diff --git a/test/unit/controller/predicates/is_intersection_layer.js b/test/unit/controller/predicates/is_intersection_layer.js new file mode 100644 index 00000000..134d98d1 --- /dev/null +++ b/test/unit/controller/predicates/is_intersection_layer.js @@ -0,0 +1,77 @@ +'use strict'; + +const _ = require('lodash'); +const is_intersection_layer = require('../../../../controller/predicates/is_intersection_layer'); + +module.exports.tests = {}; + +module.exports.tests.interface = (test, common) => { + test('valid interface', t => { + t.ok(_.isFunction(is_intersection_layer), 'is_intersection_layer is a function'); + t.end(); + }); +}; + +module.exports.tests.true_conditions = (test, common) => { + test('"Main & Broadway" should return true', t => { + const req = {}; + req.query = {}; + req.query.text = 'Main & Broadway'; + + t.ok(is_intersection_layer(req)); + t.end(); + }); + + test('"23rd and 5th" should return true', t => { + const req = {}; + req.query = {}; + req.query.text = '23rd and 5th'; + + t.ok(is_intersection_layer(req)); + t.end(); + }); + + test('"73rd& Bay pkwy" should return true', t => { + const req = {}; + req.query = {}; + req.query.text = '73rd& Bay pkwy'; + + t.ok(is_intersection_layer(req)); + t.end(); + }); + + test('"73rd&Broadway" should return true', t => { + const req = {}; + req.query = {}; + req.query.text = '73rd&Bay pkwy'; + + t.ok(is_intersection_layer(req)); + t.end(); + }); +}; + +module.exports.tests.false_conditions = (test, common) => { + test('undefined request should return false', t => { + t.notOk(is_intersection_layer(undefined)); + t.end(); + }); + + test('"Nostrand Avenue" should return false', t => { + const req = {}; + req.query = {}; + req.query.text = 'Nostrand Avenue'; + + t.notOk(is_intersection_layer(req)); + t.end(); + }); +}; + +module.exports.all = (tape, common) => { + function test(name, testFunction) { + return tape(`GET /is_intersection_layer ${name}`, testFunction); + } + + for( const testCase in module.exports.tests ){ + module.exports.tests[testCase](test, common); + } +}; \ No newline at end of file diff --git a/test/unit/helper/intersectionsParsing.js b/test/unit/helper/intersectionsParsing.js new file mode 100644 index 00000000..171056aa --- /dev/null +++ b/test/unit/helper/intersectionsParsing.js @@ -0,0 +1,65 @@ +'use strict'; + +const _ = require('lodash'); +var intersectionsParser = require('../../../helper/intersectionsParsing'); + +module.exports.tests = {}; + +module.exports.tests.interface = function (test) { + test('valid interface', t => { + t.equal(typeof intersectionsParser, 'function', 'parseIntersections is a function'); + t.end(); + }); +}; + +module.exports.tests.intersectionsParser = function (test) { + + test('parseIntersections', t => { + t.deepEqual(intersectionsParser('72 and 18'), { street1: '72nd', street2: '18th'}, + 'intersectionsParser parsed "72 and 18" correctly!'); + t.end(); + }); + + test('parseIntersections', t => { + t.deepEqual(intersectionsParser('61 & Bay'), { street1: '61st', street2: 'bay'}, + 'intersectionsParser parsed "61 and Bay" correctly!'); + t.end(); + }); + + test('parseIntersections', t => { + t.deepEqual(intersectionsParser('73 & e5'), {street1: '73rd', street2: 'East 5th'}, + 'intersectionsParser parsed "73 and e5" correctly!'); + t.end(); + }); + + test('parseIntersections', t => { + t.deepEqual(intersectionsParser('25 & w5'), { street1: '25th', street2: 'West 5th'}, + 'intersectionsParser parsed "25 and w5" correctly!'); + t.end(); + }); + + test('parseIntersections', t => { + t.deepEqual(intersectionsParser('ne26 & nw5'), { street1: 'Northeast 26th', street2: 'Northwest 5th'}, + 'intersectionsParser parsed "26 and nw5" correctly!'); + t.end(); + }); + + test('parseIntersections', t => { + t.deepEqual(intersectionsParser('se26 & sw5'), { street1: 'Southeast 26th', street2: 'Southwest 5th'}, + 'intersectionsParser parsed "26 and nw5" correctly!'); + t.end(); + }); + +}; + +module.exports.all = (tape, common) => { + + // this part I am not sure about. Subject to review + function test(name, testFunction) { + return tape(`intersections: ${name}`, testFunction); + } + + for( const testCase in module.exports.tests ){ + module.exports.tests[testCase](test, common); + } +}; \ No newline at end of file