Skip to content

Commit

Permalink
src, test: improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
louwers committed Aug 3, 2024
1 parent af7d38e commit 8fc1cf0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void DatabaseSync::ApplyChangeset(const FunctionCallbackInfo<Value>& 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;
}

Expand Down
70 changes: 55 additions & 15 deletions test/parallel/test-sqlite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:');
Expand Down Expand Up @@ -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);
});

Expand All @@ -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
Expand All @@ -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 an number.'
});
});

test('generate patchset', (t) => {
const database = new DatabaseSync(':memory:');
database.exec('CREATE TABLE data(key INTEGER PRIMARY KEY, value TEXT)');
Expand Down

0 comments on commit 8fc1cf0

Please sign in to comment.