added initial roadmap and implementation
This commit is contained in:
38
tests/integration/realtime.test.ts
Normal file
38
tests/integration/realtime.test.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { createAnonClient } from './setup.ts';
|
||||
|
||||
const client = createAnonClient();
|
||||
|
||||
describe('Realtime', () => {
|
||||
it('should receive insert events', async () => {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const channel = client
|
||||
.channel('public:todos')
|
||||
.on(
|
||||
'postgres_changes',
|
||||
{ event: 'INSERT', schema: 'public', table: 'todos' },
|
||||
(payload) => {
|
||||
console.log('Received INSERT event:', payload);
|
||||
expect(payload.new).toBeDefined();
|
||||
expect(payload.new.title).toBe('Realtime Test');
|
||||
client.removeChannel(channel).then(() => resolve());
|
||||
}
|
||||
)
|
||||
.subscribe(async (status) => {
|
||||
if (status === 'SUBSCRIBED') {
|
||||
// Trigger an insert
|
||||
const { error } = await client
|
||||
.from('todos')
|
||||
.insert({ title: 'Realtime Test', completed: false });
|
||||
|
||||
if (error) reject(error);
|
||||
}
|
||||
});
|
||||
|
||||
// Timeout if no event received
|
||||
setTimeout(() => {
|
||||
reject(new Error('Timeout waiting for Realtime event'));
|
||||
}, 10000);
|
||||
});
|
||||
}, 10000);
|
||||
});
|
||||
Reference in New Issue
Block a user