Skip to content

Commit

Permalink
Merge pull request #450 from adamstoffel/fix-use-subscription-query-d…
Browse files Browse the repository at this point in the history
…eletes
  • Loading branch information
psteinroe authored May 14, 2024
2 parents 6acc709 + 230a0b1 commit a8e5d2d
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/small-trainers-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@supabase-cache-helpers/postgrest-react-query": patch
"@supabase-cache-helpers/postgrest-swr": patch
---

fix: correctly handle delete payloads in useSubscriptionQuery
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ describe('useSubscriptionQuery', () => {
);
expect(screen.getByTestId('count').textContent).toEqual('count: 1');
await screen.findByText('cbCalled: true', {}, { timeout: 10000 });
await act(async () => {
await client
.from('contact')
.delete()
.eq('username', USERNAME_1)
.throwOnError();
});
await screen.findByText('count: 0', {}, { timeout: 10000 });
expect(screen.getByTestId('count').textContent).toEqual('count: 0');
unmount();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ describe('useSubscription', () => {
await screen.findByText('ticket_number: 5', {}, { timeout: 10000 });
expect(screen.getByTestId('count').textContent).toEqual('count: 1');
await screen.findByText('cbCalled: true', {}, { timeout: 10000 });
await act(async () => {
await client
.from('contact')
.delete()
.eq('username', USERNAME_1)
.throwOnError();
});
await screen.findByText('count: 0', {}, { timeout: 10000 });
expect(screen.getByTestId('count').textContent).toEqual('count: 0');
unmount();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function useSubscriptionQuery<
} else if (
payload.eventType === REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.DELETE
) {
await deleteItem(data as Record<string, unknown>);
await deleteItem(payload.old);
}
if (opts?.callback) {
opts.callback({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ describe('useSubscriptionQuery', () => {
);
expect(screen.getByTestId('count').textContent).toEqual('count: 1');
await screen.findByText('cbCalled: true', {}, { timeout: 10000 });
await act(async () => {
await client
.from('contact')
.delete()
.eq('username', USERNAME_1)
.throwOnError();
});
await screen.findByText('count: 0', {}, { timeout: 10000 });
expect(screen.getByTestId('count').textContent).toEqual('count: 0');
unmount();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,18 @@ describe('useSubscription', () => {
.eq('username', USERNAME_1)
.throwOnError();
});
await screen.findByText('cbCalled: true', {}, { timeout: 10000 });
await screen.findByText('ticket_number: 5', {}, { timeout: 20000 });
await screen.findByText('cbCalled: true', {}, { timeout: 10000 });
expect(screen.getByTestId('count').textContent).toEqual('count: 1');
await act(async () => {
await client
.from('contact')
.delete()
.eq('username', USERNAME_1)
.throwOnError();
});
await screen.findByText('count: 0', {}, { timeout: 10000 });
expect(screen.getByTestId('count').textContent).toEqual('count: 0');
unmount();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function useSubscriptionQuery<
} else if (
payload.eventType === REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.DELETE
) {
await deleteItem(data as Record<string, unknown>);
await deleteItem(payload.old);
}
if (opts?.callback) {
opts.callback({
Expand Down

0 comments on commit a8e5d2d

Please sign in to comment.