Skip to content

Commit

Permalink
fix(recordStream): document ids should end with .geojson (#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joxit authored Jan 4, 2023
1 parent e11e657 commit 00fccf8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/streams/recordStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ function getIdPrefix(filename, dirPath) {
// of the directory tree to create the id
if (filename.indexOf(dirPath) !== -1) {
var subpath = _.replace(filename, dirPath, '');
var prefix = _.replace(subpath, '.csv', '');
var prefix = _.replace(subpath, /\.(csv|geojson)/, '');
return _.trim(prefix, '/');
}
}

// if the dirPath doesn't contain this file, return the basename without extension
return path.basename(filename, '.csv');
return path.basename(path.basename(filename, '.csv'), '.geojson');
}

/**
Expand Down
39 changes: 36 additions & 3 deletions test/streams/recordStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ tape( 'Don\'t create records for invalid data.', function ( test ){
));
});

tape( 'getIdPrefix returns prefix based on OA directory structure', function( test ) {
tape( 'getIdPrefix returns prefix based on OA directory structure - csv', function( test ) {
var filename = '/base/path/us/ca/san_francisco.csv';
var basePath = '/base/path';

Expand All @@ -73,7 +73,7 @@ tape( 'getIdPrefix returns prefix based on OA directory structure', function( te
test.end();
});

tape( 'getIdPrefix handles multiple levels of heirarchy', function ( test ) {
tape( 'getIdPrefix handles multiple levels of heirarchy - csv', function ( test ) {
var filename = '/base/path/cz/countrywide.csv';
var basePath = '/base/path';

Expand All @@ -84,7 +84,7 @@ tape( 'getIdPrefix handles multiple levels of heirarchy', function ( test ) {
test.end();
});

tape( 'getIdPrefix returns basename without extension when invalid basepath given', function( test ) {
tape( 'getIdPrefix returns basename without extension when invalid basepath given - csv', function( test ) {
var filename = '/path/to/a/document.csv';
var basePath = '/somewhere/else';

Expand All @@ -94,3 +94,36 @@ tape( 'getIdPrefix returns basename without extension when invalid basepath give
test.equal(actual, expected);
test.end();
});

tape( 'getIdPrefix returns prefix based on OA directory structure - geojson', function( test ) {
var filename = '/base/path/us/ca/san_francisco.geojson';
var basePath = '/base/path';

var actual = recordStream.getIdPrefix(filename, basePath);

var expected = 'us/ca/san_francisco';
test.equal(actual, expected, 'correct prefix generated');
test.end();
});

tape( 'getIdPrefix handles multiple levels of heirarchy - geojson', function ( test ) {
var filename = '/base/path/cz/countrywide.geojson';
var basePath = '/base/path';

var actual = recordStream.getIdPrefix(filename, basePath);

var expected = 'cz/countrywide';
test.equal(actual, expected, 'correct prefix generated');
test.end();
});

tape( 'getIdPrefix returns basename without extension when invalid basepath given - geojson', function( test ) {
var filename = '/path/to/a/document.geojson';
var basePath = '/somewhere/else';

var actual = recordStream.getIdPrefix(filename, basePath);
var expected = 'document';

test.equal(actual, expected);
test.end();
});

0 comments on commit 00fccf8

Please sign in to comment.