1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-06 10:08:52 +08:00

add tests for dbUtils module #27

This commit is contained in:
lana-k
2021-04-10 21:19:00 +02:00
parent c7039e144a
commit 8867092601
3 changed files with 23 additions and 6 deletions

View File

@@ -11,7 +11,7 @@ export default {
getInsertStmt (columns) {
const colList = `"${columns.join('", "')}"`
const params = columns.map(() => '?').join(' ,')
const params = columns.map(() => '?').join(', ')
return `INSERT INTO csv_import (${colList}) VALUES (${params});`
},
@@ -36,9 +36,9 @@ export default {
}
default: type = 'TEXT'
}
result += `"${col}" ${type},`
result += `"${col}" ${type}, `
})
result = result.replace(/.$/, ');')
result = result.replace(/,\s$/, ');')
return result
}
}

View File

@@ -58,7 +58,7 @@ export default {
return new Promise((resolve, reject) => {
fileReader.onerror = () => {
fileReader.abort()
reject(new DOMException('Problem parsing input file.'))
reject(new Error('Problem parsing input file.'))
}
fileReader.onload = () => {

View File

@@ -1,8 +1,8 @@
import { expect } from 'chai'
import dbUtils from '@/dbUtils.js'
import dbUtils from '@/dbUtils'
describe('dbUtils.js', () => {
it('generator', () => {
it('generateChunks', () => {
const arr = ['1', '2', '3', '4', '5']
const size = 2
const chunks = dbUtils.generateChunks(arr, size)
@@ -14,4 +14,21 @@ describe('dbUtils.js', () => {
expect(output[1]).to.eql(['3', '4'])
expect(output[2]).to.eql(['5'])
})
it('getInsertStmt', () => {
const columns = ['id', 'name']
expect(dbUtils.getInsertStmt(columns))
.to.equal('INSERT INTO csv_import ("id", "name") VALUES (?, ?);')
})
it('getCreateStatement', () => {
const columns = ['id', 'name', 'isAdmin', 'startDate']
const values = [
[1, 'foo', true, new Date()],
[2, 'bar', false, new Date()]
]
expect(dbUtils.getCreateStatement(columns, values)).to.equal(
'CREATE table csv_import("id" REAL, "name" TEXT, "isAdmin" INTEGER, "startDate" TEXT);'
)
})
})