Skip to content

Commit

Permalink
Add another test
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Sep 23, 2023
1 parent 7593572 commit e607187
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### replays updates that arrived after the snapshot
### replays updates that are more recent than snapshot and arrived after

```mermaid
sequenceDiagram
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
### replays updates that are more recent than snapshot and arrived before

```mermaid
sequenceDiagram
LiveTable->>+Supabase: subscribe
Supabase->>-LiveTable: subscription active
LiveTable->>+Supabase: get snapshot
Supabase-->>LiveTable: UPDATE {"id":1,"created_at":"1","updated_at":"3","name":"Bike","type":"vehicle"}
Supabase->>-LiveTable: snaphot: [{"id":1,"created_at":"1","updated_at":"2","name":"Bicycle","type":"vehicle"}]
```

### replica
```json
[
{
"id": 1,
"created_at": "1",
"updated_at": "3",
"name": "Bike",
"type": "vehicle"
}
]
```
32 changes: 31 additions & 1 deletion test/liveTableBuffering.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('LiveTable Buffering', () => {
await lt.close();
});

it('replays updates that arrived after the snapshot', async (test) => {
it('replays updates that are more recent than snapshot and arrived after', async (test) => {
const lt = new MermaidLiveTable(new LiveTable<ThingRow>(parseTimestamp), test.task.name);

lt.subscribe();
Expand Down Expand Up @@ -139,6 +139,36 @@ describe('LiveTable Buffering', () => {
await lt.close();
});

it('replays updates that are more recent than snapshot and arrived before', async (test) => {
const lt = new MermaidLiveTable(new LiveTable<ThingRow>(parseTimestamp), test.task.name);

lt.subscribe();
lt.subscribed();
lt.requestSnapshot();

const streamRecord: ThingRow = {
id: 1,
created_at: t1,
updated_at: t3,
name: 'Bike',
type: 'vehicle',
};
lt.processEvent({ timestamp: t3, type: 'UPDATE', record: streamRecord });

const snapshotRecord = {
id: 1,
created_at: t1,
updated_at: t2,
name: 'Bicycle',
type: 'vehicle',
};
lt.processSnapshot([snapshotRecord]);

expect(lt.records).toEqual([streamRecord]);

await lt.close();
});

it('replays deletes that arrived after the snapshot', async (test) => {
const lt = new MermaidLiveTable(new LiveTable<ThingRow>(parseTimestamp), test.task.name);

Expand Down

0 comments on commit e607187

Please sign in to comment.