-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: ✅ add test coverage to objectToWhereClause
- Loading branch information
1 parent
898cd3b
commit a42b18e
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |