Skip to content

Commit c3714f4

Browse files
committed
Cleanup, added more helpers for test NodeClient.
1 parent eaef06d commit c3714f4

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

PowerSync/PowerSync.Common/Client/PowerSyncDatabase.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ public interface IPowerSyncDatabase : IEventStream<PowerSyncDBEvent>
8080

8181
public class PowerSyncDatabase : EventStream<PowerSyncDBEvent>, IPowerSyncDatabase
8282
{
83-
private static readonly int FULL_SYNC_PRIORITY = 2147483647;
84-
8583
public IDBAdapter Database;
8684
private Schema schema;
8785

Tests/PowerSync/PowerSync.Common.IntegrationTests/NodeClient.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public Task<string> CreateList(string id, string name)
3232
{
3333
return CreateItem("lists", id, name);
3434
}
35+
3536
async Task<string> CreateItem(string table, string id, string name)
3637
{
3738
var data = new Dictionary<string, object>
@@ -74,6 +75,55 @@ public Task<string> DeleteList(string id)
7475
return DeleteItem("lists", id);
7576
}
7677

78+
public Task<string> CreateTodo(string id, string listId, string description)
79+
{
80+
return CreateTodoItem("todos", id, listId, description);
81+
}
82+
83+
async Task<string> CreateTodoItem(string table, string id, string listId, string description)
84+
{
85+
var data = new Dictionary<string, object>
86+
{
87+
{ "created_at", DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") },
88+
{ "description", description },
89+
{ "list_id", listId },
90+
{ "created_by", _userId },
91+
{ "completed", 0 },
92+
};
93+
94+
var batch = new[]
95+
{
96+
new
97+
{
98+
op = UpdateType.PUT.ToString(),
99+
table = table,
100+
id = id,
101+
data = data
102+
}
103+
};
104+
105+
var payload = JsonSerializer.Serialize(new { batch });
106+
var content = new StringContent(payload, Encoding.UTF8, "application/json");
107+
108+
HttpResponseMessage response = await _httpClient.PostAsync($"{_backendUrl}/api/data", content);
109+
110+
if (!response.IsSuccessStatusCode)
111+
{
112+
Console.WriteLine(await response.Content.ReadAsStringAsync());
113+
throw new Exception(
114+
$"Failed to create todo. Status: {response.StatusCode}, " +
115+
$"Response: {await response.Content.ReadAsStringAsync()}"
116+
);
117+
}
118+
119+
return await response.Content.ReadAsStringAsync();
120+
}
121+
122+
public Task<string> DeleteTodo(string id)
123+
{
124+
return DeleteItem("todos", id);
125+
}
126+
77127
async Task<string> DeleteItem(string table, string id)
78128
{
79129
var batch = new[]

Tests/PowerSync/PowerSync.Common.IntegrationTests/SyncIntegrationTests.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using Newtonsoft.Json;
21
using PowerSync.Common.Client;
3-
using System.Data.Common;
4-
using System.Diagnostics;
5-
using System.Threading.Tasks;
62
using Microsoft.Extensions.Logging;
73
using PowerSync.Common.Client.Sync.Stream;
84

@@ -14,6 +10,8 @@ public class SyncIntegrationTests : IAsyncLifetime
1410
{
1511
private record ListResult(string id, string name, string owner_id, string created_at);
1612

13+
private record TodoResult(string id, string list_id, string content, string owner_id, string created_at);
14+
1715
private string userId = Uuid();
1816

1917
private NodeClient nodeClient = default!;
@@ -253,7 +251,7 @@ await db.Execute("insert into lists (id, name, owner_id, created_at) values (uui
253251
// try
254252
// {
255253
// Console.WriteLine("Total: " + update.StatusChanged.DownloadProgress()?.TotalOperations + " Downloaded: " + update.StatusChanged.DownloadProgress()?.DownloadedOperations);
256-
// Console.WriteLine("Synced: " + Math.Round((decimal)(update.StatusChanged.DownloadProgress()?.DownloadedFraction * 100)) + "%");
254+
// Console.WriteLine("Synced: " + Math.Round((decimal)((update.StatusChanged.DownloadProgress()?.DownloadedFraction ?? 0) * 100)) + "%");
257255

258256
// }
259257
// catch (Exception ex)
@@ -267,6 +265,7 @@ await db.Execute("insert into lists (id, name, owner_id, created_at) values (uui
267265
// await db.Connect(connector);
268266
// await db.WaitForFirstSync();
269267

268+
270269
// clearListener.Dispose();
271270
// await db.DisconnectAndClear();
272271
// await db.Close();

0 commit comments

Comments
 (0)