From 41ebc64af2acfac8ad64d47ba1d561bd27fa16e2 Mon Sep 17 00:00:00 2001 From: Oscar Franco Date: Sat, 12 Oct 2024 18:12:29 +0200 Subject: [PATCH] Update hook tests --- example/ios/Podfile.lock | 4 ++-- example/src/tests/hooks.spec.ts | 36 +++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 5433ac10..2d6c9c48 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -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 @@ -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 diff --git a/example/src/tests/hooks.spec.ts b/example/src/tests/hooks.spec.ts index 3c7a6461..34d155ce 100644 --- a/example/src/tests/hooks.spec.ts +++ b/example/src/tests/hooks.spec.ts @@ -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; @@ -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(); @@ -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 () => {