Skip to content

Commit 98fb01e

Browse files
committed
test: add tests for record empty last value scenarios
* Adds tests for #109.
1 parent 174a4ed commit 98fb01e

File tree

8 files changed

+55
-6
lines changed

8 files changed

+55
-6
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@ $ npm run coverage
176176

177177
Current Coverage is:
178178
```
179-
Statements : 100% ( 272/272 )
180-
Branches : 100% ( 143/143 )
179+
Statements : 100% ( 275/275 )
180+
Branches : 100% ( 149/149 )
181181
Functions : 100% ( 49/49 )
182-
Lines : 100% ( 266/266 )
182+
Lines : 100% ( 269/269 )
183183
```
184184

185185
## Frequently Asked Questions (FAQ)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"types": "./src/converter.d.ts",
2222
"scripts": {
2323
"test": "mocha test/tests.js",
24-
"coverage": "istanbul cover mocha -- -R spec",
24+
"coverage": "istanbul cover _mocha -- -R spec",
2525
"lint": "npm run lint:eslint && npm run lint:tslint",
2626
"lint:eslint": "eslint src bin test",
2727
"lint:tslint": "tslint -c tslint.json 'src/**/*.ts'"

test/config/testCsvFilesList.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const fs = require('fs'),
2626
{key: 'extraLine', file: '../data/csv/extraLine.csv'},
2727
{key: 'noHeader', file: '../data/csv/noHeader.csv'},
2828
{key: 'sortedHeader', file: '../data/csv/sortedHeader.csv'},
29-
{key: 'emptyFieldValues', file: '../data/csv/emptyFieldValues.csv'}
29+
{key: 'emptyFieldValues', file: '../data/csv/emptyFieldValues.csv'},
30+
{key: 'csvEmptyLastValue', file: '../data/csv/csvEmptyLastValue.csv'}
3031
];
3132

3233
function readCsvFile(filePath) {

test/config/testJsonFilesList.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ module.exports = {
1919
trimHeader: require('../data/json/trimHeader'),
2020
trimmedHeader: require('../data/json/trimmedHeader'),
2121
specifiedKeys: require('../data/json/specifiedKeys'),
22-
emptyFieldValues: require('../data/json/emptyFieldValues')
22+
emptyFieldValues: require('../data/json/emptyFieldValues'),
23+
csvEmptyLastValue: require('../data/json/csvEmptyLastValue')
2324
};

test/csv2json.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ function runTests(jsonTestData, csvTestData) {
137137
done();
138138
});
139139
});
140+
141+
// Test case for #109
142+
it('should properly handle the cases involving an empty field value', (done) => {
143+
converter.csv2json(csvTestData.csvEmptyLastValue, (err, json) => {
144+
if (err) done(err);
145+
json.should.deepEqual(jsonTestData.csvEmptyLastValue);
146+
done();
147+
});
148+
});
140149
});
141150

142151
describe('Error Handling', () => {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Name,Category,On Sale,On Closeout,Outsourced,Certification Required
2+
Installation,Service,X,,,
3+
"Wireless ""Wi-Fi"" Configuration",Service,X,,X,
4+
New Phone Setup,Service,X,X,X,X
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[
2+
{
3+
"Name": "Installation",
4+
"Category": "Service",
5+
"On Sale": "X",
6+
"On Closeout": "",
7+
"Outsourced": "",
8+
"Certification Required": ""
9+
},
10+
{
11+
"Name": "Wireless \"Wi-Fi\" Configuration",
12+
"Category": "Service",
13+
"On Sale": "X",
14+
"On Closeout": "",
15+
"Outsourced": "X",
16+
"Certification Required": ""
17+
},
18+
{
19+
"Name": "New Phone Setup",
20+
"Category": "Service",
21+
"On Sale": "X",
22+
"On Closeout": "X",
23+
"Outsourced": "X",
24+
"Certification Required": "X"
25+
}
26+
]

test/json2csv.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ function runTests(jsonTestData, csvTestData) {
129129
done();
130130
});
131131
});
132+
133+
it('should properly convert the cases involving an empty field value in the csv', (done) => {
134+
converter.json2csv(jsonTestData.csvEmptyLastValue, (err, csv) => {
135+
if (err) done(err);
136+
csv.should.equal(csvTestData.csvEmptyLastValue);
137+
done();
138+
});
139+
});
132140
});
133141

134142
describe('Error Handling', () => {

0 commit comments

Comments
 (0)