Skip to content

Commit

Permalink
Added some more unit tests to improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
suityou01 committed Oct 1, 2024
1 parent cf1853d commit b112996
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/destinations/postgresDestination.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function getMappingForColumn(mapping, column){
function writeInsertStatement(columnMapping, table, chunk){
let statement = `INSERT INTO ${table} (${chunk._columns.map(column => {
const mapping = getMappingForColumn(columnMapping, column)
return mapping
return mapping.targetColumn
?
isKeyWord(mapping.targetColumn)
? `"${mapping.targetColumn}"`
Expand Down
5 changes: 3 additions & 2 deletions test/destinations/postgresDestination.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,19 @@ describe('postgresDestination tests', () => {
const result = writeInsertStatement(newMapping, mockTable, mockChunk)
expect(result).toEqual("INSERT INTO MockTable (target_column1,\"User\",target_column3) VALUES ('a',to_date('19-06-2024 00:00','DD-MM-YYYY HH24:MI:SS'),'c')")
})
it('should write a sql statement when a source column is a keyword', () => {
it('should write a sql statement when a source column is a keyword and there is no target column', () => {
const newMapping = JSON.parse(JSON.stringify(config.mapping))
newMapping[1].column = "User"
newMapping[1].targetType = "date"
delete newMapping[1].targetColumn
newMapping[1].format = "DD-MM-YYYY HH24:MI:SS"
const mockTable = "MockTable"
const mockChunk = ["a", "19-06-2024 00:00", "c"]
mockChunk.errors = []
mockChunk.rowId = 1
mockChunk._columns = ["column1", "User", "column3"]
const result = writeInsertStatement(newMapping, mockTable, mockChunk)
expect(result).toEqual("INSERT INTO MockTable (target_column1,target_column2,target_column3) VALUES ('a',to_date('19-06-2024 00:00','DD-MM-YYYY HH24:MI:SS'),'c')")
expect(result).toEqual("INSERT INTO MockTable (target_column1,\"User\",target_column3) VALUES ('a',to_date('19-06-2024 00:00','DD-MM-YYYY HH24:MI:SS'),'c')")
})
it('should write a sql statement when a target column type is a number', () => {
const newMapping = [...config.mapping]
Expand Down

0 comments on commit b112996

Please sign in to comment.