Skip to content

Commit

Permalink
fix(deps): bump csv-string from 3.2.0 to 4.0.1 (opengovsg#344)
Browse files Browse the repository at this point in the history
* fix(deps): bump csv-string from 3.2.0 to 4.0.1

Bumps [csv-string](https://github.com/Inist-CNRS/node-csv-string) from 3.2.0 to 4.0.1.
- [Release notes](https://github.com/Inist-CNRS/node-csv-string/releases)
- [Commits](Inist-CNRS/node-csv-string@v3.2.0...v4.0.1)

Signed-off-by: dependabot[bot] <[email protected]>

* fix: use correctly imported stringify function

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Kar Rui Lau <[email protected]>
  • Loading branch information
dependabot[bot] and karrui authored Sep 21, 2020
1 parent 99f4266 commit ce4a82d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"cookie-parser": "~1.4.0",
"crypto-js": "^4.0.0",
"css-toggle-switch": "^4.1.0",
"csv-string": "^3.1.5",
"csv-string": "^4.0.1",
"dedent-js": "^1.0.1",
"deep-diff": "^1.0.1",
"ejs": "^3.1.5",
Expand Down
8 changes: 4 additions & 4 deletions src/public/modules/forms/helpers/CsvGenerator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const CSV = require('csv-string')
const { stringify } = require('csv-string')
const { triggerFileDownload } = require('./util')

// Used to denote to Excel that the CSV is UTF8-encoded. See
Expand Down Expand Up @@ -30,7 +30,7 @@ module.exports = class CsvGenerator {
* @param {Array} rowData array of data to be inserted
*/
addLine(rowData) {
this.records[this.idx] = CSV.stringify(rowData)
this.records[this.idx] = stringify(rowData)
this.idx++
}

Expand All @@ -39,15 +39,15 @@ module.exports = class CsvGenerator {
* @param {Array} headerLabels array of labels for header row
*/
setHeader(headerLabels) {
this.records[this.startIdx - 1] = CSV.stringify(headerLabels)
this.records[this.startIdx - 1] = stringify(headerLabels)
}

/**
* Insert meta-data array into the start of the CSV file
* @param {Array} metaDataRows array of arrays, metaDataRows[i][j] holds the data for row i, col j of the metaData table
*/
addMetaData(metaDataRows) {
const metaData = metaDataRows.map((data) => CSV.stringify(data))
const metaData = metaDataRows.map((data) => stringify(data))
// Start splicing at index 1 because BOM is at index 0.
this.records.splice(1, this.numOfMetaDataRows, ...metaData)
}
Expand Down
32 changes: 16 additions & 16 deletions tests/unit/frontend/forms/helpers/CsvMergedHeadersGenerator.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import CSV from 'csv-string'
import { stringify } from 'csv-string'
import moment from 'moment-timezone'

import CsvMergedHeadersGenerator from '../../../../../src/public/modules/forms/helpers/CsvMergedHeadersGenerator'
Expand Down Expand Up @@ -273,15 +273,15 @@ describe('CsvMergedHeadersGenerator', () => {
// Assert
// Should have 1 header row and 1 submission row
expect(generator.records.length).toEqual(2 + BOM_LENGTH)
const expectedHeaderRow = CSV.stringify([
const expectedHeaderRow = stringify([
'Reference number',
'Timestamp',
mockDecryptedRecord[0].question,
mockDecryptedRecord[1].question,
mockDecryptedRecord[2].question,
mockDecryptedRecord[3].question,
])
const expectedSubmissionRow = CSV.stringify([
const expectedSubmissionRow = stringify([
mockRecord.submissionId,
moment(mockRecord.created)
.tz('Asia/Singapore')
Expand Down Expand Up @@ -335,15 +335,15 @@ describe('CsvMergedHeadersGenerator', () => {
// Assert
// Should have 1 header row and 2 submission row
expect(generator.records.length).toEqual(3 + BOM_LENGTH)
const expectedHeaderRow = CSV.stringify([
const expectedHeaderRow = stringify([
'Reference number',
'Timestamp',
mockFirstDecryptedRecord[0].question,
mockFirstDecryptedRecord[1].question,
mockFirstDecryptedRecord[2].question,
mockFirstDecryptedRecord[3].question,
])
const expectedSubmissionRow1 = CSV.stringify([
const expectedSubmissionRow1 = stringify([
mockFirstRecord.submissionId,
moment(mockFirstRecord.created)
.tz('Asia/Singapore')
Expand All @@ -355,7 +355,7 @@ describe('CsvMergedHeadersGenerator', () => {
])
// Second processed row should be mockReversedRecord's answers in reversed
// order since the fieldIds are reversed
const expectedSubmissionRow2 = CSV.stringify([
const expectedSubmissionRow2 = stringify([
mockReversedRecord.submissionId,
moment(mockReversedRecord.created)
.tz('Asia/Singapore')
Expand Down Expand Up @@ -408,7 +408,7 @@ describe('CsvMergedHeadersGenerator', () => {
// Assert
// Should have 1 header row and 2 submission row
expect(generator.records.length).toEqual(3 + BOM_LENGTH)
const expectedHeaderRow = CSV.stringify([
const expectedHeaderRow = stringify([
'Reference number',
'Timestamp',
mockDecryptedRecord[0].question,
Expand All @@ -421,7 +421,7 @@ describe('CsvMergedHeadersGenerator', () => {
])

// First row should be the first submission
const expectedSubmissionRow1 = CSV.stringify([
const expectedSubmissionRow1 = stringify([
mockRecord.submissionId,
moment(mockRecord.created)
.tz('Asia/Singapore')
Expand All @@ -436,7 +436,7 @@ describe('CsvMergedHeadersGenerator', () => {
// Second processed row should be second submission, with fields it does
// not have blank.
// Should only have questionId of `intersectFieldId` and `new` filled.
const expectedSubmissionRow2 = CSV.stringify([
const expectedSubmissionRow2 = stringify([
mockNewRecord.submissionId,
moment(mockNewRecord.created)
.tz('Asia/Singapore')
Expand Down Expand Up @@ -476,13 +476,13 @@ describe('CsvMergedHeadersGenerator', () => {
// Assert
// Should have 1 header row and 1 submission row
expect(generator.records.length).toEqual(2 + BOM_LENGTH)
const expectedHeaderRow = CSV.stringify([
const expectedHeaderRow = stringify([
'Reference number',
'Timestamp',
mockDecryptedRecord[0].question,
])

const expectedSubmissionRow = CSV.stringify([
const expectedSubmissionRow = stringify([
mockRecord.submissionId,
moment(mockRecord.created)
.tz('Asia/Singapore')
Expand Down Expand Up @@ -524,14 +524,14 @@ describe('CsvMergedHeadersGenerator', () => {
// Should have 1 header row and 1 submission row
expect(generator.records.length).toEqual(2 + BOM_LENGTH)
// Question is repeated for two columns
const expectedHeaderRow = CSV.stringify([
const expectedHeaderRow = stringify([
'Reference number',
'Timestamp',
mockDecryptedRecord[0].question,
mockDecryptedRecord[0].question,
])

const expectedSubmissionRow = CSV.stringify([
const expectedSubmissionRow = stringify([
mockRecord.submissionId,
moment(mockRecord.created)
.tz('Asia/Singapore')
Expand Down Expand Up @@ -571,14 +571,14 @@ describe('CsvMergedHeadersGenerator', () => {
// Assert
// Should have 1 header row and 2 submission rows
expect(generator.records.length).toEqual(3 + BOM_LENGTH)
const expectedHeaderRow = CSV.stringify([
const expectedHeaderRow = stringify([
'Reference number',
'Timestamp',
mockAnswerArray[0].question,
])

// First row is answer array
const expectedSubmissionRow1 = CSV.stringify([
const expectedSubmissionRow1 = stringify([
mockAnswerArrayRecord.submissionId,
moment(mockAnswerArrayRecord.created)
.tz('Asia/Singapore')
Expand All @@ -587,7 +587,7 @@ describe('CsvMergedHeadersGenerator', () => {
mockAnswerArray[0].answerArray.join(';'),
])
// Second row is answer, but same field Id, so same number of headers
const expectedSubmissionRow2 = CSV.stringify([
const expectedSubmissionRow2 = stringify([
mockAnswerRecord.submissionId,
moment(mockAnswerRecord.created)
.tz('Asia/Singapore')
Expand Down

0 comments on commit ce4a82d

Please sign in to comment.