<commit_before>/**
 * @file The main entry point for the OpenAddresses importer's unit-tests.
 */

'use strict';

var tape = require( 'tape' );
var through = require( 'through2' );
var importPipelines = require( '../lib/import_pipelines' );

tape( 'importPipelines.createRecordStream().', function ( test ){
  function createTestRec( lon, lat, name ){
    return { lon: lon, lat: lat, name: name };
  }

  var expectedRecords = [
    createTestRec( -118.0170157, 55.546026835788886, "23042 Twp Road 755 A" ),
    createTestRec( -118.75318353, 55.14959214890181, "712046 Rge Road 34" ),
    createTestRec( -118.8218384, 55.15506788763259, "712078 Rge Road 34" ),
    createTestRec( -118.79719936, 55.153343057595535, "712068 Rge Road 34" ),
    createTestRec( -118.66743097, 55.151807043809917, "712060 Rge Road 34" ),
    createTestRec( -118.74783569, 55.155320792497442, "712082 Rge Road 35" )
  ];
  test.plan( expectedRecords.length * 3 + 1);

  var dataStream = importPipelines.createRecordStream(
    'test/openaddresses_sample.csv'
  );
  test.ok( dataStream.readable, 'Stream is readable.' );
  var testStream = through.obj(function ( data, enc, next ){
    var expected = expectedRecords.splice( 0, 1 )[ 0 ];
    var centroid = data.getCentroid();
    test.ok( expected.lon - centroid.lon < 1e-6, 'Longitude matches.' );
    test.ok( expected.lat - centroid.lat < 1e-6, 'Latitude matches.' );
    test.equal( expected.name, data.getName( 'default' ), 'Name matches.' );
    next();
  });
  dataStream.pipe( testStream );
});<commit_msg>Add a test for createPeliasElasticsearchPipeline().<commit_after>/**
 * @file The main entry point for the OpenAddresses importer's unit-tests.
 */

'use strict';

var peliasModel = require( 'pelias-model' );
var tape = require( 'tape' );
var through = require( 'through2' );
var importPipelines = require( '../lib/import_pipelines' );

/**
 * Tests whether records read from `test/openaddresses_sample.csv` are created
 * into Document objects with expected values.
 */
tape(
  'importPipelines.createRecordStream() creates Document objects with expected values.',
  function ( test ){
    function createTestRec( lon, lat, name ){
      return { lon: lon, lat: lat, name: name };
    }

    var expectedRecords = [
      createTestRec( -118.0170157, 55.546026835788886, "23042 Twp Road 755 A" ),
      createTestRec( -118.75318353, 55.14959214890181, "712046 Rge Road 34" ),
      createTestRec( -118.8218384, 55.15506788763259, "712078 Rge Road 34" ),
      createTestRec( -118.79719936, 55.153343057595535, "712068 Rge Road 34" ),
      createTestRec( -118.66743097, 55.151807043809917, "712060 Rge Road 34" ),
      createTestRec( -118.74783569, 55.155320792497442, "712082 Rge Road 35" )
    ];
    test.plan( expectedRecords.length * 4 + 1);

    var dataStream = importPipelines.createRecordStream(
      'test/openaddresses_sample.csv'
    );
    test.ok( dataStream.readable, 'Stream is readable.' );
    var testStream = through.obj(function ( data, enc, next ){
      test.ok(
        data instanceof peliasModel.Document, 'Data is a Document object.'
      );

      var expected = expectedRecords.splice( 0, 1 )[ 0 ];
      var centroid = data.getCentroid();
      test.ok( expected.lon - centroid.lon < 1e-6, 'Longitude matches.' );
      test.ok( expected.lat - centroid.lat < 1e-6, 'Latitude matches.' );
      test.equal( expected.name, data.getName( 'default' ), 'Name matches.' );
      next();
    });
    dataStream.pipe( testStream );
  }
);

tape(
  'importPipeline.createPeliasElasticsearchPipeline() interface',
  function ( test ){
    test.plan( 1 );
    var esPipeline = importPipelines.createPeliasElasticsearchPipeline();
    test.ok( esPipeline.writable, 'Stream is writable' );
  }
);
{'fraction_non_alphanumeric': 0.1363998936453071, 'fraction_numerical': 0.11831959585216698, 'mean_word_length': 3.5655339805825244, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2792255', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1259, 'n_words': 322}