Skip to content

Commit

Permalink
test: ✅ add test coverage to objectToWhereClause
Browse files Browse the repository at this point in the history
  • Loading branch information
CRBroughton committed Mar 10, 2024
1 parent 898cd3b commit a42b18e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export async function Sibyl<T extends Record<string, any>>(db: Database, table:
Insert,
Select,
All,
objectToWhereClause,
buildSelectQuery,
convertToObjects,
}
Expand Down
50 changes: 50 additions & 0 deletions src/tests/objectToWhereClause.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { describe, expect, it } from 'vitest'
import sql from 'sql.js'
import { Sibyl } from '../index'

interface TableRow {
id: number
name: string
location: string
}

describe('objectToWhereClause tests', () => {
it('converts a single where object clause to a SQL WHERE clause', async () => {
const DBName = 'testingDB'
const SQL = await sql({
locateFile: () => {
return 'playground/public/sql-wasm.wasm'
},
})
const db = new SQL.Database()
const { objectToWhereClause } = await Sibyl<TableRow>(db, DBName)

const actual = objectToWhereClause({
name: 'Craig',
})

const expectation = 'name = \'Craig\''

expect(actual).toStrictEqual(expectation)
})
it('converts the where object with multiple WHERE clauses to a SQL WHERE clause', async () => {
const DBName = 'testingDB'
const SQL = await sql({
locateFile: () => {
return 'playground/public/sql-wasm.wasm'
},
})
const db = new SQL.Database()
const { objectToWhereClause } = await Sibyl<TableRow>(db, DBName)

const actual = objectToWhereClause({
id: 1,
location: 'Brighton',
name: 'Craig',
})

const expectation = 'id = \'1\' AND location = \'Brighton\' AND name = \'Craig\''

expect(actual).toStrictEqual(expectation)
})
})

0 comments on commit a42b18e

Please sign in to comment.