bridge-node-server/node_server/utils/specs/postcodes.spec.js

138 lines
4.3 KiB
JavaScript
Raw Normal View History

2018-06-24 20:15:03 +00:00
/* globals describe, beforeEach, afterEach, it */
/**
* Unit testing file for the validation code
*/
'use strict';
// eslint-disable-next-line no-unused-vars
const testGlobals = require('../../tools/test/testGlobals.js');
const chai = require('chai');
const rewire = require('rewire');
const expect = chai.expect;
/**
* Use `rewire` instead of require so that we can access private functions for test
*/
const postcodes = rewire('../postcodes.js');
/**
* Get the private function using the `rewire`-ed object.
*/
const pafToBridgeAddress = postcodes.__get__('pafToBridgeAddress');
/**
* Testcases for testing the conversion from PAF format to our format
*/
const TESTCASES = [
{
description: 'sub_building_name should be put in BuildingNameFlat',
paf: {
postcode: 'G12 9UY',
postcode_inward: '9UY',
postcode_outward: 'G12',
post_town: 'GLASGOW',
dependant_locality: '',
double_dependant_locality: '',
thoroughfare: 'Hyndland Road',
dependant_thoroughfare: '',
building_number: '31',
building_name: '',
sub_building_name: '0/1',
po_box: '',
department_name: '',
organisation_name: '',
udprn: 9298788,
umprn: '',
postcode_type: 'S',
su_organisation_indicator: '',
delivery_point_suffix: '1A',
line_1: '0/1',
line_2: '31 Hyndland Road',
line_3: '',
premise: '0/1, 31',
longitude: -4.30397743012253,
latitude: 55.8811827343641,
eastings: 255974,
northings: 667736,
country: 'Scotland',
traditional_county: 'Lanarkshire',
administrative_county: '',
postal_county: 'Lanarkshire',
county: 'Lanarkshire',
district: 'Glasgow City',
ward: 'Hillhead'
},
expect: {
BuildingNameFlat: '0/1',
Address1: '31 Hyndland Road',
Town: 'GLASGOW',
PostCode: 'G12 9UY',
Country: 'United Kingdom'
}
},
{
description: 'longer addresses should be spread across BuildingNameFlat, Address1, Address2',
paf: {
postcode: 'EH54 7GA',
postcode_inward: '7GA',
postcode_outward: 'EH54',
post_town: 'LIVINGSTON',
dependant_locality: '',
double_dependant_locality: '',
thoroughfare: 'Rosebank',
dependant_thoroughfare: 'The Alba Campus',
building_number: '',
building_name: 'Alba Innovation Centre',
sub_building_name: '',
po_box: '',
department_name: '',
organisation_name: 'Comcarde Ltd',
udprn: 52317380,
umprn: '',
postcode_type: 'S',
su_organisation_indicator: 'Y',
delivery_point_suffix: '1P',
line_1: 'Comcarde Ltd',
line_2: 'Alba Innovation Centre',
line_3: 'The Alba Campus, Rosebank',
premise: 'Alba Innovation Centre',
longitude: -3.54888286304114,
latitude: 55.8726117996675,
eastings: 303182,
northings: 665467,
country: 'Scotland',
traditional_county: 'West Lothian',
administrative_county: '',
postal_county: 'West Lothian',
county: 'West Lothian',
district: 'West Lothian',
ward: 'Livingston South'
},
expect: {
BuildingNameFlat: 'Comcarde Ltd',
Address1: 'Alba Innovation Centre',
Address2: 'The Alba Campus, Rosebank',
Town: 'LIVINGSTON',
PostCode: 'EH54 7GA',
Country: 'United Kingdom'
}
}
];
/**
* Unit test definitions
*/
describe('postcodes', () => {
describe('pafToBridge conversion', () => {
//
// Loop through all the groups of tests cases, adding a describe for each one
//
for (let i = 0; i < TESTCASES.length; ++i) {
const CASE = TESTCASES[i];
it(CASE.description, () => {
expect(pafToBridgeAddress(CASE.paf)).to.deep.equal(CASE.expect);
});
}
});
});