Skip to content

Commit e372cf6

Browse files
committed
Fixed crud tests. Removed boolean parameter from BucketStorageTests.
1 parent f731d70 commit e372cf6

File tree

3 files changed

+44
-37
lines changed

3 files changed

+44
-37
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"methodDisplay": "method",
3+
"diagnosticMessages": true,
4+
"longRunningTestSeconds": 10
5+
}

Tests/PowerSync/PowerSync.Common.Tests/Client/Sync/BucketStorageTests.cs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public async Task BasicSetup()
130130
var initialBucketStates = await bucketStorage.GetBucketStates();
131131
Assert.Empty(initialBucketStates);
132132

133-
await bucketStorage.SaveSyncData(new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3], false)]));
133+
await bucketStorage.SaveSyncData(new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3])]));
134134

135135
var bucketStates = await bucketStorage.GetBucketStates();
136136

@@ -154,7 +154,7 @@ public async Task ShouldGetObjectFromMultipleBuckets()
154154
{
155155
await bucketStorage.SaveSyncData(
156156
new SyncDataBatch(
157-
[new SyncDataBucket("bucket1", [TestData.putAsset1_3], false), new SyncDataBucket("bucket2", [TestData.putAsset1_3], false)])
157+
[new SyncDataBucket("bucket1", [TestData.putAsset1_3]), new SyncDataBucket("bucket2", [TestData.putAsset1_3])])
158158
);
159159

160160
await SyncLocalChecked(new Checkpoint
@@ -176,7 +176,7 @@ public async Task ShouldPrioritizeLaterUpdates()
176176

177177
await bucketStorage.SaveSyncData(
178178
new SyncDataBatch(
179-
[new SyncDataBucket("bucket1", [TestData.putAsset1_3], false), new SyncDataBucket("bucket2", [TestData.putAsset1_1], false)])
179+
[new SyncDataBucket("bucket1", [TestData.putAsset1_3]), new SyncDataBucket("bucket2", [TestData.putAsset1_1])])
180180
);
181181

182182
await SyncLocalChecked(new Checkpoint
@@ -193,7 +193,7 @@ public async Task ShouldIgnoreRemoveFromOneBucket()
193193
{
194194
// When we have 1 PUT and 1 REMOVE, the object must be kept.);
195195
await bucketStorage.SaveSyncData(
196-
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_3], false), new SyncDataBucket("bucket2", [TestData.putAsset1_3, TestData.removeAsset1_4], false)])
196+
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_3]), new SyncDataBucket("bucket2", [TestData.putAsset1_3, TestData.removeAsset1_4])])
197197
);
198198

199199
await SyncLocalChecked(new Checkpoint
@@ -210,7 +210,7 @@ public async Task ShouldRemoveWhenRemovedFromAllBuckets()
210210
{
211211
// When we only have REMOVE left for an object, it must be deleted.
212212
await bucketStorage.SaveSyncData(
213-
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_3, TestData.removeAsset1_5], false), new SyncDataBucket("bucket2", [TestData.putAsset1_3, TestData.removeAsset1_4], false)])
213+
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_3, TestData.removeAsset1_5]), new SyncDataBucket("bucket2", [TestData.putAsset1_3, TestData.removeAsset1_4])])
214214
);
215215

216216
await SyncLocalChecked(new Checkpoint
@@ -250,7 +250,7 @@ public async Task ShouldUseSubkeys()
250250
});
251251

252252
await bucketStorage.SaveSyncData(
253-
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset1_3, put4], false)])
253+
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset1_3, put4])])
254254
);
255255

256256
await SyncLocalChecked(new Checkpoint
@@ -262,7 +262,7 @@ await SyncLocalChecked(new Checkpoint
262262
var result = await db.GetAll<AssetResult>("SELECT id, description, make FROM assets WHERE id = 'O1'");
263263
Assert.Equal(new AssetResult("O1", "B", null), result[0]);
264264

265-
await bucketStorage.SaveSyncData(new SyncDataBatch([new SyncDataBucket("bucket1", [remove5], false)]));
265+
await bucketStorage.SaveSyncData(new SyncDataBatch([new SyncDataBucket("bucket1", [remove5])]));
266266

267267
await SyncLocalChecked(new Checkpoint
268268
{
@@ -278,7 +278,7 @@ public async Task ShouldFailChecksumValidation()
278278
{
279279
// Simple checksum validation
280280
await bucketStorage.SaveSyncData(
281-
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3], false)])
281+
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3])])
282282
);
283283

284284
var result = await bucketStorage.SyncLocalDatabase(new Checkpoint
@@ -304,7 +304,7 @@ public async Task ShouldDeleteBuckets()
304304
{
305305
await bucketStorage.SaveSyncData(
306306
new SyncDataBatch(
307-
[new SyncDataBucket("bucket1", [TestData.putAsset1_3], false), new SyncDataBucket("bucket2", [TestData.putAsset1_3], false)])
307+
[new SyncDataBucket("bucket1", [TestData.putAsset1_3]), new SyncDataBucket("bucket2", [TestData.putAsset1_3])])
308308
);
309309

310310
await bucketStorage.RemoveBuckets(["bucket2"]);
@@ -335,23 +335,23 @@ public async Task ShouldDeleteAndRecreateBuckets()
335335
{
336336
// Save some data
337337
await bucketStorage.SaveSyncData(
338-
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1], false)])
338+
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1])])
339339
);
340340

341341
// Delete the bucket
342342
await bucketStorage.RemoveBuckets(["bucket1"]);
343343

344344
// Save some data again
345345
await bucketStorage.SaveSyncData(
346-
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset1_3], false)])
346+
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset1_3])])
347347
);
348348

349349
// Delete again
350350
await bucketStorage.RemoveBuckets(["bucket1"]);
351351

352352
// Final save of data
353353
await bucketStorage.SaveSyncData(
354-
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset1_3], false)])
354+
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset1_3])])
355355
);
356356

357357
// Check that the data is there
@@ -388,12 +388,12 @@ await bucketStorage.SaveSyncData(
388388
Op = new OpType(OpTypeEnum.MOVE).ToJSON(),
389389
Checksum = 1
390390
})
391-
], false)
391+
])
392392
])
393393
);
394394

395395
await bucketStorage.SaveSyncData(
396-
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_3], false)])
396+
new SyncDataBatch([new SyncDataBucket("bucket1", [TestData.putAsset1_3])])
397397
);
398398

399399
await SyncLocalChecked(new Checkpoint
@@ -412,7 +412,7 @@ public async Task ShouldHandleClear()
412412
await bucketStorage.SaveSyncData(
413413
new SyncDataBatch(
414414
[
415-
new SyncDataBucket("bucket1", [TestData.putAsset1_1], false)
415+
new SyncDataBucket("bucket1", [TestData.putAsset1_1])
416416
])
417417
);
418418

@@ -446,7 +446,7 @@ await bucketStorage.SaveSyncData(
446446
ObjectId = TestData.putAsset2_2.ObjectId,
447447
ObjectType = TestData.putAsset2_2.ObjectType
448448
})
449-
], false)
449+
])
450450
])
451451
);
452452

@@ -478,7 +478,7 @@ public async Task UpdateWithNewTypes()
478478

479479
await bucketStorage.SaveSyncData(
480480
new SyncDataBatch(
481-
[new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3], false)])
481+
[new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3])])
482482
);
483483

484484
await SyncLocalChecked(new Checkpoint
@@ -524,7 +524,7 @@ public async Task ShouldRemoveTypes()
524524
await bucketStorage.SaveSyncData(
525525
new SyncDataBatch(
526526
[
527-
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3], false)
527+
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3])
528528
])
529529
);
530530

@@ -578,7 +578,7 @@ public async Task ShouldCompact()
578578
await bucketStorage.SaveSyncData(
579579
new SyncDataBatch(
580580
[
581-
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.removeAsset1_4], false)
581+
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.removeAsset1_4])
582582
])
583583
);
584584

@@ -613,7 +613,7 @@ public async Task ShouldNotSyncLocalDbWithPendingCrud_ServerRemoved()
613613
await bucketStorage.SaveSyncData(
614614
new SyncDataBatch(
615615
[
616-
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3], false)
616+
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3])
617617
])
618618
);
619619

@@ -676,7 +676,7 @@ await SyncLocalChecked(new Checkpoint
676676
await bucketStorage.SaveSyncData(
677677
new SyncDataBatch(
678678
[
679-
new SyncDataBucket("bucket1", Array.Empty<OplogEntry>(), false)
679+
new SyncDataBucket("bucket1", Array.Empty<OplogEntry>())
680680
])
681681
);
682682

@@ -700,7 +700,7 @@ public async Task ShouldNotSyncLocalDbWithPendingCrud_WhenMoreCrudIsAdded_1()
700700
await bucketStorage.SaveSyncData(
701701
new SyncDataBatch(
702702
[
703-
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3], false)
703+
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3])
704704
])
705705
);
706706

@@ -743,7 +743,7 @@ await SyncLocalChecked(new Checkpoint
743743
await bucketStorage.SaveSyncData(
744744
new SyncDataBatch(
745745
[
746-
new SyncDataBucket("bucket1", Array.Empty<OplogEntry>(), false)
746+
new SyncDataBucket("bucket1", Array.Empty<OplogEntry>())
747747
])
748748
);
749749

@@ -769,7 +769,7 @@ public async Task ShouldNotSyncLocalDbWithPendingCrud_WhenMoreCrudIsAdded_2()
769769
await bucketStorage.SaveSyncData(
770770
new SyncDataBatch(
771771
[
772-
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3], false)
772+
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3])
773773
])
774774
);
775775

@@ -797,7 +797,7 @@ await SyncLocalChecked(new Checkpoint
797797
await bucketStorage.SaveSyncData(
798798
new SyncDataBatch(
799799
[
800-
new SyncDataBucket("bucket1", [], false)
800+
new SyncDataBucket("bucket1", [])
801801
])
802802
);
803803

@@ -826,7 +826,7 @@ public async Task ShouldNotSyncLocalDbWithPendingCrud_UpdateOnServer()
826826
await bucketStorage.SaveSyncData(
827827
new SyncDataBatch(
828828
[
829-
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3], false)
829+
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3])
830830
])
831831
);
832832

@@ -865,7 +865,7 @@ await bucketStorage.SaveSyncData(
865865
Checksum = 5,
866866
Data = new { description = "server updated" }
867867
})
868-
], false)
868+
])
869869
])
870870
);
871871

@@ -889,7 +889,7 @@ public async Task ShouldRevertAFailingInsert()
889889
await bucketStorage.SaveSyncData(
890890
new SyncDataBatch(
891891
[
892-
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3], false)
892+
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3])
893893
])
894894
);
895895

@@ -931,7 +931,7 @@ public async Task ShouldRevertAFailingDelete()
931931
await bucketStorage.SaveSyncData(
932932
new SyncDataBatch(
933933
[
934-
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3], false)
934+
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3])
935935
])
936936
);
937937

@@ -974,7 +974,7 @@ public async Task ShouldRevertAFailingUpdate()
974974
await bucketStorage.SaveSyncData(
975975
new SyncDataBatch(
976976
[
977-
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3], false)
977+
new SyncDataBucket("bucket1", [TestData.putAsset1_1, TestData.putAsset2_2, TestData.putAsset1_3])
978978
])
979979
);
980980

Tests/PowerSync/PowerSync.Common.Tests/Client/Sync/CRUDTests.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public async Task Insert_RecordCrudEntryTest()
4545
JsonConvert.SerializeObject(new
4646
{
4747
op = "PUT",
48-
type = "assets",
4948
id = testId,
49+
type = "assets",
5050
data = new { description = "test" }
5151
}),
5252
crudEntry.Data
@@ -80,8 +80,8 @@ public async Task InsertOrReplaceTest()
8080
JsonConvert.SerializeObject(new
8181
{
8282
op = "PUT",
83-
type = "assets",
8483
id = testId,
84+
type = "assets",
8585
data = new { description = "test2" }
8686
}),
8787
crudEntry.Data
@@ -112,8 +112,8 @@ public async Task UpdateTest()
112112
JsonConvert.SerializeObject(new
113113
{
114114
op = "PATCH",
115-
type = "assets",
116115
id = testId,
116+
type = "assets",
117117
data = new { description = "test2" }
118118
}),
119119
crudEntry.Data
@@ -127,6 +127,8 @@ public async Task UpdateTest()
127127
{ "description", "test2" }
128128
});
129129

130+
Console.WriteLine(JsonConvert.SerializeObject(tx.Crud.First()));
131+
Console.WriteLine(JsonConvert.SerializeObject(expectedCrudEntry));
130132
Assert.True(tx.Crud.First().Equals(expectedCrudEntry));
131133
}
132134

@@ -144,8 +146,8 @@ public async Task DeleteTest()
144146
JsonConvert.SerializeObject(new
145147
{
146148
op = "DELETE",
149+
id = testId,
147150
type = "assets",
148-
id = testId
149151
}),
150152
crudEntry.Data
151153
);
@@ -234,8 +236,8 @@ public async Task BigNumbersIntegerTest()
234236
JsonConvert.SerializeObject(new
235237
{
236238
op = "PUT",
237-
type = "assets",
238239
id = testId,
240+
type = "assets",
239241
data = new { quantity = bigNumber }
240242
}),
241243
crudEntry.Data
@@ -267,8 +269,8 @@ public async Task BigNumbersTextTest()
267269
JsonConvert.SerializeObject(new
268270
{
269271
op = "PUT",
270-
type = "assets",
271272
id = testId,
273+
type = "assets",
272274
data = new { quantity = bigNumber.ToString() }
273275
}),
274276
crudEntry.Data
@@ -287,8 +289,8 @@ await db.Execute("UPDATE assets SET description = ?, quantity = CAST(quantity AS
287289
JsonConvert.SerializeObject(new
288290
{
289291
op = "PATCH",
290-
type = "assets",
291292
id = testId,
293+
type = "assets",
292294
data = new { description = "updated", quantity = bigNumber + 1 }
293295
}),
294296
crudEntry.Data

0 commit comments

Comments
 (0)