From aaf0928a4dbbb02398c91bd2dfde6abbfe3a6eba Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Sun, 4 Aug 2024 00:15:07 +0200 Subject: [PATCH] src, test: improve coverage --- src/node_sqlite.cc | 4 +-- test/parallel/test-sqlite.js | 70 ++++++++++++++++++++++++++++-------- 2 files changed, 57 insertions(+), 17 deletions(-) diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index 4b347dbbe2a59e..482aaa89df0616 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -330,7 +330,7 @@ void DatabaseSync::ApplyChangeset(const FunctionCallbackInfo& args) { if (!args[1]->IsObject()) { node::THROW_ERR_INVALID_ARG_TYPE( env->isolate(), - "The second argument, if provided, must be an options object."); + "The \"options\" argument must be an object."); return; } @@ -348,7 +348,7 @@ void DatabaseSync::ApplyChangeset(const FunctionCallbackInfo& args) { if (!conflictValue->IsNumber()) { node::THROW_ERR_INVALID_ARG_TYPE( env->isolate(), - "The \"options.onConflict\" argument must be an number."); + "The \"options.onConflict\" argument must be a number."); return; } diff --git a/test/parallel/test-sqlite.js b/test/parallel/test-sqlite.js index 8d0bbaa44e4ff1..7946e1caf2faa1 100644 --- a/test/parallel/test-sqlite.js +++ b/test/parallel/test-sqlite.js @@ -831,18 +831,6 @@ suite('session extension', () => { }); }); - test('set table with wrong type when creating session', (t) => { - const database = new DatabaseSync(':memory:'); - t.assert.throws(() => { - database.createSession({ - table: true - }); - }, { - name: 'TypeError', - message: 'The "options.table" argument must be a string.' - }); - }); - test('setting options.table causes only one table to be tracked', (t) => { const database1 = new DatabaseSync(':memory:'); const database2 = new DatabaseSync(':memory:'); @@ -974,9 +962,9 @@ suite('session extension', () => { const data1Rows = database2.prepare('SELECT * FROM data1').all(); const data2Rows = database2.prepare('SELECT * FROM data2').all(); - // Expect no rows since all changes where filtered out + // Expect no rows since all changes were filtered out t.assert.strictEqual(data1Rows.length, 0); - // Expect 5 rows since these changes where not filtered out + // Expect 5 rows since these changes were not filtered out t.assert.strictEqual(data2Rows.length, 5); }); @@ -997,8 +985,24 @@ suite('session extension', () => { t.assert.strictEqual(sessionTest.changeset().length, 0); }); - test('wrong argument name of other database', (t) => { + test('wrong arguments database.createSession()', (t) => { const database = new DatabaseSync(':memory:'); + t.assert.throws(() => { + database.createSession(null); + }, { + name: 'TypeError', + message: 'The "options" argument must be an object.' + }); + + t.assert.throws(() => { + database.createSession({ + table: 123 + }); + }, { + name: 'TypeError', + message: 'The "options.table" argument must be a string.' + }); + t.assert.throws(() => { database.createSession({ db: 123 @@ -1009,6 +1013,42 @@ suite('session extension', () => { }); }); + test('wrong arguments database.applyChangeset()', (t) => { + const database = new DatabaseSync(':memory:'); + const session = database.createSession(); + t.assert.throws(() => { + database.applyChangeset(null); + }, { + name: 'TypeError', + message: 'The "changeset" argument must be a Uint8Array.' + }); + + t.assert.throws(() => { + database.applyChangeset(session.changeset(), null); + }, { + name: 'TypeError', + message: 'The "options" argument must be an object.' + }); + + t.assert.throws(() => { + database.applyChangeset(session.changeset(), { + filter: null + }, null); + }, { + name: 'TypeError', + message: 'The "options.filter" argument must be a function.' + }); + + t.assert.throws(() => { + database.applyChangeset(session.changeset(), { + onConflict: null + }, null); + }, { + name: 'TypeError', + message: 'The "options.onConflict" argument must be a number.' + }); + }); + test('generate patchset', (t) => { const database = new DatabaseSync(':memory:'); database.exec('CREATE TABLE data(key INTEGER PRIMARY KEY, value TEXT)');