@@ -13,45 +13,55 @@ import kotlinx.coroutines.test.runTest
1313import kotlin.test.Test
1414
1515class SupabaseConnectorTest {
16-
1716 @Test
18- fun errorHandling () = runTest {
19- val db = PowerSyncDatabase .inMemory(scope= this , schema= Schema (Table (" users" , listOf (
20- Column .text(" name" )
21- ))))
22-
23- try {
24- db.writeTransaction { tx ->
25- tx.execute(" INSERT INTO users (id, name) VALUES (uuid(), ?)" , listOf (" a" ))
26- tx.execute(" INSERT INTO users (id, name) VALUES (uuid(), ?)" , listOf (" b" ))
27- tx.execute(" INSERT INTO users (id, name) VALUES (uuid(), ?)" , listOf (" c" ))
28- }
17+ fun errorHandling () =
18+ runTest {
19+ val db =
20+ PowerSyncDatabase .inMemory(
21+ scope = this ,
22+ schema =
23+ Schema (
24+ Table (
25+ " users" ,
26+ listOf (
27+ Column .text(" name" ),
28+ ),
29+ ),
30+ ),
31+ )
2932
30- var calledErrorHandler = false
31- val connector = object : SupabaseConnector (" " , " " , " " ) {
32- override suspend fun uploadCrudEntry (entry : CrudEntry ) {
33- throw Exception (" Expected exception, failing in uploadCrudEntry" )
33+ try {
34+ db.writeTransaction { tx ->
35+ tx.execute(" INSERT INTO users (id, name) VALUES (uuid(), ?)" , listOf (" a" ))
36+ tx.execute(" INSERT INTO users (id, name) VALUES (uuid(), ?)" , listOf (" b" ))
37+ tx.execute(" INSERT INTO users (id, name) VALUES (uuid(), ?)" , listOf (" c" ))
3438 }
3539
36- override suspend fun handleError (
37- tx : CrudTransaction ,
38- entry : CrudEntry ,
39- exception : Exception ,
40- errorCode : String?
41- ) {
42- calledErrorHandler = true
40+ var calledErrorHandler = false
41+ val connector =
42+ object : SupabaseConnector (" " , " " , " " ) {
43+ override suspend fun uploadCrudEntry (entry : CrudEntry ): Unit =
44+ throw Exception (" Expected exception, failing in uploadCrudEntry" )
4345
44- tx.crud shouldHaveSize 3
45- entry shouldBeEqual tx.crud[0 ]
46- exception.message shouldBe " Expected exception, failing in uploadCrudEntry"
47- tx.complete(null )
48- }
49- }
46+ override suspend fun handleError (
47+ tx : CrudTransaction ,
48+ entry : CrudEntry ,
49+ exception : Exception ,
50+ errorCode : String? ,
51+ ) {
52+ calledErrorHandler = true
53+
54+ tx.crud shouldHaveSize 3
55+ entry shouldBeEqual tx.crud[0 ]
56+ exception.message shouldBe " Expected exception, failing in uploadCrudEntry"
57+ tx.complete(null )
58+ }
59+ }
5060
51- connector.uploadData(db)
52- calledErrorHandler shouldBe true
53- } finally {
54- db.close()
61+ connector.uploadData(db)
62+ calledErrorHandler shouldBe true
63+ } finally {
64+ db.close()
65+ }
5566 }
56- }
5767}
0 commit comments