|
1 | 1 | import { test, expect } from 'bun:test'
|
2 | 2 | import { createClient } from '@supabase/supabase-js'
|
3 | 3 |
|
4 |
| -test('should subscribe to realtime channel', async () => { |
5 |
| - const SUPABASE_URL = 'http://127.0.0.1:54321' |
6 |
| - const ANON_KEY = |
7 |
| - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0' |
| 4 | +const SUPABASE_URL = 'http://127.0.0.1:54321' |
| 5 | +const ANON_KEY = |
| 6 | + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0' |
8 | 7 |
|
9 |
| - const supabase = createClient(SUPABASE_URL, ANON_KEY, { |
10 |
| - realtime: { heartbeatIntervalMs: 500 }, |
11 |
| - }) |
| 8 | +const supabase = createClient(SUPABASE_URL, ANON_KEY, { |
| 9 | + realtime: { heartbeatIntervalMs: 500 }, |
| 10 | +}) |
12 | 11 |
|
13 |
| - // Setup authentication |
| 12 | +test('should subscribe to realtime channel', async () => { |
14 | 13 | await supabase.auth.signOut()
|
15 | 14 | const email = `bun-test-${Date.now()}@example.com`
|
16 | 15 | const password = 'password123'
|
@@ -43,3 +42,70 @@ test('should subscribe to realtime channel', async () => {
|
43 | 42 | // Cleanup
|
44 | 43 | await supabase.removeAllChannels()
|
45 | 44 | }, 10000)
|
| 45 | + |
| 46 | +test('should sign up a user', async () => { |
| 47 | + await supabase.auth.signOut() |
| 48 | + const email = `bun-auth-${Date.now()}@example.com` |
| 49 | + const password = 'password123' |
| 50 | + |
| 51 | + const { data, error } = await supabase.auth.signUp({ |
| 52 | + email, |
| 53 | + password, |
| 54 | + }) |
| 55 | + |
| 56 | + expect(error).toBeNull() |
| 57 | + expect(data.user).toBeDefined() |
| 58 | + expect(data.user!.email).toBe(email) |
| 59 | +}) |
| 60 | + |
| 61 | +test('should sign in and out successfully', async () => { |
| 62 | + await supabase.auth.signOut() |
| 63 | + const email = `bun-signin-${Date.now()}@example.com` |
| 64 | + const password = 'password123' |
| 65 | + |
| 66 | + await supabase.auth.signUp({ email, password }) |
| 67 | + |
| 68 | + const { data, error } = await supabase.auth.signInWithPassword({ |
| 69 | + email, |
| 70 | + password, |
| 71 | + }) |
| 72 | + |
| 73 | + expect(error).toBeNull() |
| 74 | + expect(data.user).toBeDefined() |
| 75 | + expect(data.user!.email).toBe(email) |
| 76 | + |
| 77 | + const { error: signOutError } = await supabase.auth.signOut() |
| 78 | + |
| 79 | + expect(signOutError).toBeNull() |
| 80 | +}) |
| 81 | + |
| 82 | +test('should get current user', async () => { |
| 83 | + await supabase.auth.signOut() |
| 84 | + const email = `bun-getuser-${Date.now()}@example.com` |
| 85 | + const password = 'password123' |
| 86 | + |
| 87 | + await supabase.auth.signUp({ email, password }) |
| 88 | + await supabase.auth.signInWithPassword({ email, password }) |
| 89 | + |
| 90 | + const { data, error } = await supabase.auth.getUser() |
| 91 | + |
| 92 | + expect(error).toBeNull() |
| 93 | + expect(data.user).toBeDefined() |
| 94 | + expect(data.user!.email).toBe(email) |
| 95 | +}) |
| 96 | + |
| 97 | +test('should handle invalid credentials', async () => { |
| 98 | + await supabase.auth.signOut() |
| 99 | + const email = `bun-invalid-${Date.now()}@example.com` |
| 100 | + const password = 'password123' |
| 101 | + |
| 102 | + await supabase.auth.signUp({ email, password }) |
| 103 | + |
| 104 | + const { data, error } = await supabase.auth.signInWithPassword({ |
| 105 | + email, |
| 106 | + password: 'wrongpassword', |
| 107 | + }) |
| 108 | + |
| 109 | + expect(error).not.toBeNull() |
| 110 | + expect(data.user).toBeNull() |
| 111 | +}) |
0 commit comments