Skip to content

Commit

Permalink
Update hook tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ospfranco committed Oct 12, 2024
1 parent e8b8b2d commit 41ebc64
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PODS:
- hermes-engine (0.74.0):
- hermes-engine/Pre-built (= 0.74.0)
- hermes-engine/Pre-built (0.74.0)
- op-sqlite (9.1.2):
- op-sqlite (9.1.3):
- React
- React-callinvoker
- React-Core
Expand Down Expand Up @@ -1393,7 +1393,7 @@ SPEC CHECKSUMS:
GCDWebServer: 2c156a56c8226e2d5c0c3f208a3621ccffbe3ce4
glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2
hermes-engine: 6eae7edb2f563ee41d7c1f91f4f2e57c26d8a5c3
op-sqlite: 8171f3e990b7d9d138fc818f1c2c5542687cc6e5
op-sqlite: efd0f6f9aa3215353b825625d4b132d5951e168e
RCT-Folly: 045d6ecaa59d826c5736dfba0b2f4083ff8d79df
RCTDeprecation: 3ca8b6c36bfb302e1895b72cfe7db0de0c92cd47
RCTRequired: 9fc183af555fd0c89a366c34c1ae70b7e03b1dc5
Expand Down
36 changes: 25 additions & 11 deletions example/src/tests/hooks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Chance from 'chance';

import {type DB, open, isLibsql} from '@op-engineering/op-sqlite';
import chai from 'chai';
import {describe, it, beforeEach, afterAll} from './MochaRNAdapter';
import {describe, it, beforeEach, afterAll, itOnly} from './MochaRNAdapter';
import {sleep} from './utils';

const expect = chai.expect;
Expand Down Expand Up @@ -46,17 +46,30 @@ export function registerHooksTests() {
if (isLibsql()) {
return;
}
it('update hook', async () => {

itOnly('update hook', async () => {
let promiseResolve: any;
let promise = new Promise(resolve => {
let promise = new Promise<{
rowId: number;
row?: any;
operation: string;
table: string;
}>(resolve => {
promiseResolve = resolve;
});
db.updateHook(({operation}) => {
// console.warn(
// `Hook has been called, rowId: ${rowId}, ${table}, ${operation}`,
// );
// console.warn(JSON.stringify(row, null, 2));
promiseResolve?.(operation);
let db = open({
name: 'updateHookDb.sqlite',
encryptionKey: 'blah',
});

await db.execute('DROP TABLE IF EXISTS User;');

await db.execute(
'CREATE TABLE User ( id INT PRIMARY KEY, name TEXT NOT NULL, age INT, networth REAL) STRICT;',
);

db.updateHook(data => {
promiseResolve(data);
});

const id = chance.integer();
Expand All @@ -68,9 +81,10 @@ export function registerHooksTests() {
[id, name, age, networth],
);

const operation = await promise;
const data = await promise;

expect(operation).to.equal('INSERT');
expect(data.operation).to.equal('INSERT');
expect(data.rowId).to.equal(1);
});

it('remove update hook', async () => {
Expand Down

0 comments on commit 41ebc64

Please sign in to comment.