Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

git-csv-diff

Package Overview
Dependencies
Maintainers
7
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

git-csv-diff - npm Package Compare versions

Comparing version 1.3.0 to 1.3.1

test/unit/diff-by-file.spec.js

4

package.json
{
"name": "git-csv-diff",
"author": "Valor-Software",
"version": "1.3.0",
"version": "1.3.1",
"license": "GPL-3.0",

@@ -26,3 +26,3 @@ "description": "Library generate difference between csv-files based on Git commit hash",

"test:e2e": "./node_modules/.bin/mocha test/e2e/*.js --reporter spec",
"test:unit": "istanbul cover _mocha -- -R spec 'test/unit/*.spec.js'"
"test:unit": "istanbul --include-all-sources cover _mocha -- -R spec 'test/unit/*.spec.js'"
},

@@ -29,0 +29,0 @@ "dependencies": {

@@ -20,8 +20,2 @@ 'use strict';

function diffByFile() {
return {
process: _process
};
}
// metaData.fileName;

@@ -36,4 +30,11 @@ // metaData.fileModifier;

module.exports = {
process: _process,
_splitPrimaryKeysByPathToOldAndNew: splitPrimaryKeysByPathToOldAndNew
};
function _process(metaData, dataDiff, streams) {
metaData = Object.assign({}, metaData, splitPrimaryKeysByPathToOldAndNew(metaData));
const isTranslations = diffHelpers.isLanguageFile(metaData.fileName);

@@ -50,3 +51,3 @@ const baseStream = isTranslations ? streams.lang : streams.diff;

// validate input data
if(!isSchemaExists(modelResponse.metadata) || !isValidFilePath(metaData.fileName)) {
if (!isSchemaExists(modelResponse.metadata) || !isValidFilePath(metaData.fileName)) {
return;

@@ -86,7 +87,7 @@ }

if (modificationType !== diffModifiers.BLANK) {
if(diffStrategy.has(modificationType)){
if (diffStrategy.has(modificationType)) {
const diffInstance = diffStrategy.get(modificationType);
diffInstance.process(baseStream, metaData, modelResponse, modelDiff, diffResultColumns, rowValue);
}
// if nothing changed
// if nothing changed
} else {

@@ -121,3 +122,3 @@ // Case: new columns were added

let lang = 'default';
if(diffHelpers.isLanguageFile(fileName)) {
if (diffHelpers.isLanguageFile(fileName)) {
const regexpRes = /lang\/(.+)\//.exec(fileName);

@@ -135,3 +136,3 @@ lang = regexpRes[1] || lang;

// info is not available if file was removed
if(metaData.fileModifier != "D") {
if (metaData.fileModifier != "D") {
const resourcesByPathNew = _.keyBy(metaData.datapackage.new.resources, 'path');

@@ -183,2 +184,16 @@ file.new = resourcesByPathNew[fileName];

module.exports = new diffByFile();
function splitPrimaryKeysByPathToOldAndNew(metadata) {
return {
primaryKeyByPath: {
old: convertResourcesToPrimaryKeyByPath(_.get(metadata, 'datapackage.old.resources')),
new: convertResourcesToPrimaryKeyByPath(_.get(metadata, 'datapackage.new.resources'))
}
};
}
function convertResourcesToPrimaryKeyByPath(resources) {
return _.reduce(resources, (result, resource) => {
result[resource.path] = resource.schema.primaryKey;
return result;
}, {});
}

@@ -25,3 +25,3 @@ 'use strict';

const isTranslations = diffHelpers.isLanguageFile(metaData.fileName);
const isDataPointsFile = diffHelpers.isDatapointFile(metaData.fileName);
const isDataPointsFile = diffHelpers.isDatapointFile(metaData);

@@ -63,2 +63,2 @@ if(isDataPointsFile && isTranslations) {

module.exports = new diffHeaderRemove();
module.exports = new diffHeaderRemove();

@@ -20,4 +20,11 @@ 'use strict';

diffHelpers.prototype.isDatapointFile = function (filename) {
return _.includes(filename, "--datapoints--");
diffHelpers.prototype.isDatapointFile = function (metadata) {
const fileName = this.isLanguageFile(metadata.fileName) ? _.last(_.split(metadata.fileName, '/')) : metadata.fileName;
const primaryKeyByPath = _.get(metadata, 'primaryKeyByPath');
const newPrimaryKey = _.get(primaryKeyByPath, ['new', fileName]);
const oldPrimaryKey = _.get(primaryKeyByPath, ['old', fileName]);
const primaryKey = newPrimaryKey || oldPrimaryKey;
return _.isArray(primaryKey) && primaryKey.length > 1;
};

@@ -46,2 +53,2 @@

module.exports = new diffHelpers();
module.exports = new diffHelpers();

@@ -28,3 +28,3 @@ 'use strict';

const isDataPointsFile = diffHelpers.isDatapointFile(metaData.fileName);
const isDataPointsFile = diffHelpers.isDatapointFile(metaData);
const isTranslations = diffHelpers.isLanguageFile(metaData.fileName);

@@ -31,0 +31,0 @@

@@ -19,3 +19,3 @@ 'use strict';

diffRowRemove.prototype.process = function (baseStream, metaData, modelResponse, modelDiff, diffResultColumns, rowValue) {
const isDataPointsFile = diffHelpers.isDatapointFile(metaData.fileName);
const isDataPointsFile = diffHelpers.isDatapointFile(metaData);

@@ -22,0 +22,0 @@ const primaryKey = _.first(diffHelpers.getPrimaryKeys(modelResponse.metadata));

@@ -34,2 +34,7 @@ const expect = require("chai").expect;

const metaDataDatapoint = {
primaryKeyByPath: {
new: {
'ddf--datapoints--lines.csv': ['bla', 'bla']
},
},
file: {old: {schema: {primaryKey: 'column 1'}}, new: {schema: {primaryKey: 'column 2'}}},

@@ -103,3 +108,3 @@ fileName: '/lang/nl-nl/ddf--datapoints--lines.csv'

testFile.process(baseStream, metaDataDatapoint, modelResponse, modelDiff, diffResultColumns, rowValue);
expect(diffHelpersStub.calledOnce).to.equal(true);
sinon.assert.calledOnce(diffHelpersStub);
expect(diffHelpersStub.getCall(0).args[1]).to.deep.equal(resultFixture);

@@ -113,2 +118,2 @@

});
});

@@ -79,25 +79,110 @@ const expect = require("chai").expect;

describe("API::isDatapointFile", function () {
it("should return correct result for datapoint file: taken from new datapackage", function () {
const metadata = {
fileName: 'ddf--datapoints--lines_of_code--by--company--project--anno.csv',
primaryKeyByPath: {
new: {
'ddf--datapoints--lines_of_code--by--company--project--anno.csv': ['company', 'project', 'anno']
}
}
};
it("should return correct result for datapoint file", function (done) {
expect(testFile.isDatapointFile(metadata)).to.equal(true);
});
const input = 'ddf--datapoints--lines_of_code--by--company--project--anno.csv';
const resultFixture = true;
it("should return correct result for datapoint file: taken from old datapackage", function () {
const metadata = {
fileName: 'ddf--datapoints--lines_of_code--by--company--project--anno.csv',
primaryKeyByPath: {
old: {
'ddf--datapoints--lines_of_code--by--company--project--anno.csv': ['company', 'project', 'anno']
}
}
};
const result = testFile.isDatapointFile(input);
expect(result).to.deep.equal(resultFixture);
expect(testFile.isDatapointFile(metadata)).to.equal(true);
});
done();
it("should return correct result for datapoint file: new datapackage has priority over the old datapackage", function () {
const metadata = {
fileName: 'ddf--datapoints--lines_of_code--by--company--project--anno.csv',
primaryKeyByPath: {
old: {
'ddf--datapoints--lines_of_code--by--company--project--anno.csv': []
},
new: {
'ddf--datapoints--lines_of_code--by--company--project--anno.csv': ['company', 'project', 'anno']
},
}
};
expect(testFile.isDatapointFile(metadata)).to.equal(true);
});
it("should return correct result for non-datapoint file", function (done) {
it("should return correct result for datapoint file: datapoints translations are also included", function () {
const metadata = {
fileName: 'lang/path/ddf--datapoints--lines_of_code--by--company--project--anno.csv',
primaryKeyByPath: {
new: {
'ddf--datapoints--lines_of_code--by--company--project--anno.csv': ['company', 'project', 'anno']
}
}
};
const input = 'ddf--concepts.csv';
const resultFixture = false;
expect(testFile.isDatapointFile(metadata)).to.equal(true);
});
const result = testFile.isDatapointFile(input);
expect(result).to.deep.equal(resultFixture);
it("should detect when a file is not about datapoints: primaryKey is a single non-array value", function () {
const metadata = {
fileName: 'lang/path/ddf--datapoints--lines_of_code--by--company--project--anno.csv',
primaryKeyByPath: {
new: {
'ddf--datapoints--lines_of_code--by--company--project--anno.csv': 'company'
}
}
};
done();
expect(testFile.isDatapointFile(metadata)).to.deep.equal(false);
});
it("should detect when a file is not about datapoints: primaryKey is null", function () {
const metadata = {
fileName: 'lang/path/ddf--datapoints--lines_of_code--by--company--project--anno.csv',
primaryKeyByPath: {
new: {
'ddf--datapoints--lines_of_code--by--company--project--anno.csv': null
}
}
};
expect(testFile.isDatapointFile(metadata)).to.deep.equal(false);
});
it("should detect when a file is not about datapoints: primaryKey is an array with a single value", function () {
const metadata = {
fileName: 'lang/path/ddf--datapoints--lines_of_code--by--company--project--anno.csv',
primaryKeyByPath: {
new: {
'ddf--datapoints--lines_of_code--by--company--project--anno.csv': ['bla']
}
}
};
expect(testFile.isDatapointFile(metadata)).to.deep.equal(false);
});
it("should not treat file as a datapoints' one when there is not enough info in metadata to detect this: there are no new and old primary keys by path", function () {
const metadata = {
fileName: 'lang/path/ddf--datapoints--lines_of_code--by--company--project--anno.csv',
primaryKeyByPath: {}
};
expect(testFile.isDatapointFile(metadata)).to.deep.equal(false);
});
it("should not treat file as a datapoints' one when there is not enough info in metadata to detect this: there is no primary keys by path property", function () {
const metadata = {
fileName: 'lang/path/ddf--datapoints--lines_of_code--by--company--project--anno.csv',
};
expect(testFile.isDatapointFile(metadata)).to.deep.equal(false);
});
});

@@ -204,2 +289,2 @@

});
});

@@ -34,2 +34,7 @@ const expect = require("chai").expect;

const metaDataDatapoint = {
primaryKeyByPath: {
new: {
'ddf--datapoints--lines.csv': ['bla', 'bla']
}
},
file: {old: {schema: {primaryKey: 'column 1'}}, new: {schema: {primaryKey: 'column 2'}}},

@@ -36,0 +41,0 @@ fileName: 'ddf--datapoints--lines.csv'

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc