Permalink
Browse files

Fixed file.js step - compare xlsx with stored data. Added functional …

…tests covering this step.
  • Loading branch information...
Tomasz Górski Tomasz Górski
Tomasz Górski authored and Tomasz Górski committed Sep 11, 2018
1 parent 182f917 commit 375103f0351fb98ef9925a0b8e4ac7f1164448e1
View
@@ -10,6 +10,8 @@ tmp-*
npm-debug.log
.idea
downloads/*
!functional-tests/downloads/.gitkeep
!functional-tests/downloads/example.xlsx
docker-compose.override.yml
!downloads/.gitkeep
!functional-tests/reports/.gitkeep
View
0 dist/cli.js 100644 → 100755
No changes.
@@ -30,7 +30,7 @@ const FileManager = {
},
parseXLS: function (expectedFileName) {
return _nodeXlsx2.default.parse(_path2.default.join(_config2.default.projectPath, _config2.default.downloads, expectedFileName)[0].data);
return _nodeXlsx2.default.parse(_path2.default.join(_config2.default.projectPath, _config2.default.downloads, expectedFileName))[0].data;
}
};
@@ -128,7 +128,7 @@ class Initializer {
if (conf.email && conf.email.type === 'mailtrap') {
conf.email = _extends({}, conf.email, {
config: {
url: 'https://mailtrap.io/api/v1',
url: 'https://mailtrap.io',
apiKey: '',
inboxId: ''
}
@@ -19,40 +19,64 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
Then(/^the file "([^"]*)" contains table data stored under "([^"]*)" variable$/, function (filename, variableName) {
const file = _fileManager2.default.parseXLS(_variableStore2.default.replaceTextVariables(filename));
let availableData = _variableStore2.default.getVariableValue(variableName);
const rows = file.filter(function (row, index) {
return row.length > 0 && index > 0;
});
const missingRows = rows.reduce((previous, current) => {
const expectedRowIndex = availableData.findIndex(item => {
let hasAllProperties = true;
for (let i = 0; i < current.length; i++) {
if (current[i] !== item[i]) {
hasAllProperties = false;
break;
const storedData = _variableStore2.default.getVariableValue(variableName);
const rows = file.filter((row, index) => row.length > 0 && index > 0);
const findIndexes = () => {
const allFoundIndexesInRows = [];
storedData.forEach(storedItems => {
const foundIndexesInRow = [];
let previousFoundIndex = null;
storedItems.forEach(storedValue => {
for (const index in rows) {
if (storedValue.match(/^\d+$/)) {
if (previousFoundIndex !== null) {
foundIndexesInRow.push(rows[previousFoundIndex].indexOf(parseInt(storedValue)));
break;
}
if (rows[index].includes(parseInt(storedValue))) {
previousFoundIndex = index;
foundIndexesInRow.push(rows[index].indexOf(parseInt(storedValue)));
break;
}
}
if (previousFoundIndex !== null) {
foundIndexesInRow.push(rows[previousFoundIndex].indexOf(storedValue));
break;
}
if (rows[index].includes(storedValue)) {
previousFoundIndex = index;
foundIndexesInRow.push(rows[index].indexOf(storedValue));
break;
}
}
}
});
return hasAllProperties;
allFoundIndexesInRows.push(foundIndexesInRow);
});
if (expectedRowIndex === -1) {
previous.push(current);
return previous;
}
availableData = availableData.filter((item, index) => index !== expectedRowIndex);
return Promise.resolve(allFoundIndexesInRows);
};
return previous;
}, []);
return findIndexes().then(allFoundIndexes => {
if (allFoundIndexes[0].length !== storedData[0].length) {
return Promise.reject('Values not found!');
}
if (missingRows.length === 0) {
return Promise.resolve();
}
if (allFoundIndexes.length === 1) {
return Promise.resolve();
}
return Promise.reject('Some rows not found: ' + missingRows.map(row => row[0]).join(', '));
for (let index = 1; index < allFoundIndexes.length; index++) {
if (JSON.stringify(allFoundIndexes[index]) !== JSON.stringify(allFoundIndexes[index - 1])) {
return Promise.reject('Arrays are different!');
}
}
});
});
});
No changes.
View
Binary file not shown.
@@ -19,3 +19,27 @@ Feature: Store table and compare jsons
["4", "1", "View"]
]
"""
Scenario: Compare stored values with the content from a xlsx file - equal rows and four stored values
Given I store the content from "http://localhost:8080/xlsx/data-9rows" endpoint as "storedTable" variable
Then the file "example.xlsx" contains table data stored under "storedTable" variable
Scenario: Compare stored values with the content from a xlsx file - equal rows and one stored value
Given I store the content from "http://localhost:8080/xlsx/data-9rows-part" endpoint as "storedTable" variable
Then the file "example.xlsx" contains table data stored under "storedTable" variable
Scenario: Compare stored values with the content from a xlsx file - three rows and four stored values
Given I store the content from "http://localhost:8080/xlsx/data-3rows" endpoint as "storedTable" variable
Then the file "example.xlsx" contains table data stored under "storedTable" variable
Scenario: Compare stored values with the content from a xlsx file - three rows and two stored values
Given I store the content from "http://localhost:8080/xlsx/data-3rows-part" endpoint as "storedTable" variable
Then the file "example.xlsx" contains table data stored under "storedTable" variable
Scenario: Compare stored values with the content from a xlsx file - one row and four stored values
Given I store the content from "http://localhost:8080/xlsx/data-1row" endpoint as "storedTable" variable
Then the file "example.xlsx" contains table data stored under "storedTable" variable
Scenario: Compare stored values with the content from a xlsx file - one row and two stored values
Given I store the content from "http://localhost:8080/xlsx/data-1row-part" endpoint as "storedTable" variable
Then the file "example.xlsx" contains table data stored under "storedTable" variable
Oops, something went wrong.

0 comments on commit 375103f

Please sign in to comment.