Skip to content

Commit

Permalink
Add test for executeWithHostObjects
Browse files Browse the repository at this point in the history
  • Loading branch information
ospfranco committed Sep 10, 2024
1 parent d222457 commit a4500e5
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions example/src/tests/queries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,38 @@ export function queriesTests() {
expect(res.rows?.item).to.be.a('function');
});

it('Insert and query with host objects', async () => {
const id = chance.integer();
const name = chance.name();
const age = chance.integer();
const networth = chance.floating();
const res = await db.executeWithHostObjects(
'INSERT INTO "User" (id, name, age, networth) VALUES(?, ?, ?, ?)',
[id, name, age, networth],
);

expect(res.rowsAffected).to.equal(1);
expect(res.insertId).to.equal(1);
// expect(res.metadata).to.eql([]);
expect(res.rows?._array).to.eql([]);
expect(res.rows?.length).to.equal(0);
expect(res.rows?.item).to.be.a('function');

const queryRes = await db.executeWithHostObjects('SELECT * FROM User');

expect(queryRes.rowsAffected).to.equal(1);
expect(queryRes.insertId).to.equal(1);
expect(queryRes.rows?._array).to.eql([
{
id,
name,
age,
networth,
nickname: null,
},
]);
});

it('Query without params', async () => {
const id = chance.integer();
const name = chance.name();
Expand Down

0 comments on commit a4500e5

Please sign in to comment.