Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding 100% Unit Test Coverage #31

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
Empty file added index.ts
Empty file.
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ module.exports = {
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
prefix: '<rootDir>/',
}),
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
},
},
moduleDirectories: ['node_modules', 'src'],
modulePaths: ['<rootDir>'],
setupFiles: ['<rootDir>/jest.setup.js'],
Expand Down
188 changes: 188 additions & 0 deletions package-lock.json

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

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
"handlebars": "^4.7.8"
},
"devDependencies": {
"@types/fetch-mock": "^7.3.8",
"fetch-mock": "^9.11.0",
"node-fetch": "^2.7.0",
"@jest/globals": "^29.7.0",
"@types/node": "^20.12.12",
"husky": "^9.0.11",
Expand Down
22 changes: 9 additions & 13 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,6 @@ function buildQueryString(

break
case 'update':
if (!queryBuilder || !queryBuilder.whereClauses) {
break
}

const columnsToUpdate = Object.keys(queryBuilder.data || {})
const setClauses =
queryType === QueryType.named
Expand All @@ -361,8 +357,8 @@ function buildQueryString(
.join(', ')

query.query = `UPDATE ${queryBuilder.table || ''} SET ${setClauses}`
if (queryBuilder.whereClauses?.length > 0) {
query.query += ` WHERE ${queryBuilder.whereClauses.join(' AND ')}`
if (queryBuilder.whereClauses?.length ?? 0 > 0) {
query.query += ` WHERE ${queryBuilder.whereClauses?.join(' AND ')}`
}

if (queryType === QueryType.named) {
Expand All @@ -387,8 +383,6 @@ function buildQueryString(
query.query += ` WHERE ${queryBuilder.whereClauses.join(' AND ')}`
}
break
default:
throw new Error('Invalid action')
}

return query
Expand Down Expand Up @@ -619,16 +613,18 @@ export function lessThanOrEqualNumber(a: any, b: any) {
return `${a} <= ${b}`
}

export function inValues(a: any, b: any[]) {
return `${a} IN ('${b.join("', '").replace(/'/g, "\\'")}')`
export function inValues(a: any, b: any[]): string {
const sanitizedValues = b.map((val) => val.replace(/'/g, "\\'"))
return `${a} IN ('${sanitizedValues.join("', '")}')`
}

export function inNumbers(a: any, b: any[]) {
return `${a} IN (${b.join(', ')})`
}

export function notInValues(a: any, b: any[]) {
return `${a} NOT IN ('${b.join("', '").replace(/'/g, "\\'")}')`
export function notInValues(a: any, b: any[]): string {
const sanitizedValues = b.map((val) => val.replace(/'/g, "\\'"))
return `${a} NOT IN ('${sanitizedValues.join("', '")}')`
}

export function notInNumbers(a: any, b: any[]) {
Expand All @@ -644,7 +640,7 @@ export function isNumber(a: any, b: any) {
return `${a} IS ${b}`
}

export function isNot(this: any, a: any, b: null) {
export function isNot(this: any, a: any, b: string | null) {
if (b === null) return `${this} IS NOT NULL`
return `${a} IS NOT ${b}`
}
Expand Down
Loading
Loading