Skip to content

Commit 3a97f7a

Browse files
author
georgiy.rusanov
committed
added more auth tests
1 parent f9a2624 commit 3a97f7a

File tree

5 files changed

+198
-12
lines changed

5 files changed

+198
-12
lines changed

test/deno/integration.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,64 @@ Deno.test(
8888
assertEquals(data.user!.email, email)
8989
})
9090

91+
await t.step('Authentication - should sign in and out successfully', async () => {
92+
const email = `deno-signout-${Date.now()}@example.com`
93+
const password = 'password123'
94+
95+
await supabase.auth.signUp({ email, password })
96+
const { data, error } = await supabase.auth.signInWithPassword({ email, password })
97+
98+
assertEquals(error, null)
99+
assertExists(data.user)
100+
assertEquals(data.user!.email, email)
101+
102+
const { error: signOutError } = await supabase.auth.signOut()
103+
104+
assertEquals(signOutError, null)
105+
})
106+
107+
await t.step('Authentication - should get current user', async () => {
108+
const email = `deno-getuser-${Date.now()}@example.com`
109+
const password = 'password123'
110+
111+
await supabase.auth.signUp({ email, password })
112+
await supabase.auth.signInWithPassword({ email, password })
113+
114+
const { data, error } = await supabase.auth.getUser()
115+
116+
assertEquals(error, null)
117+
assertExists(data.user)
118+
assertEquals(data.user!.email, email)
119+
})
120+
121+
await t.step('Authentication - should handle invalid credentials', async () => {
122+
const email = `deno-invalid-${Date.now()}@example.com`
123+
const password = 'password123'
124+
125+
await supabase.auth.signUp({ email, password })
126+
127+
const { data, error } = await supabase.auth.signInWithPassword({
128+
email,
129+
password: 'wrongpassword',
130+
})
131+
132+
assertExists(error)
133+
assertEquals(data.user, null)
134+
})
135+
136+
await t.step('Authentication - should handle non-existent user', async () => {
137+
const email = `deno-nonexistent-${Date.now()}@example.com`
138+
const password = 'password123'
139+
140+
const { data, error } = await supabase.auth.signInWithPassword({
141+
email,
142+
password,
143+
})
144+
145+
assertExists(error)
146+
assertEquals(data.user, null)
147+
})
148+
91149
await t.step('Realtime - is able to connect and broadcast', async () => {
92150
const channelName = `channel-${crypto.randomUUID()}`
93151
let channel: RealtimeChannel

test/integration.test.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ describe('Supabase Integration Tests', () => {
176176
// Clean up by signing out the user
177177
await supabase.auth.signOut()
178178
})
179+
179180
test('should sign up a user', async () => {
180181
const email = `test-${Date.now()}@example.com`
181182
const password = 'password123'
@@ -189,6 +190,64 @@ describe('Supabase Integration Tests', () => {
189190
expect(data.user).toBeDefined()
190191
expect(data.user!.email).toBe(email)
191192
})
193+
194+
test('should sign in and out successfully', async () => {
195+
const email = `test-${Date.now()}@example.com`
196+
const password = 'password123'
197+
198+
await supabase.auth.signUp({ email, password })
199+
const { data, error } = await supabase.auth.signInWithPassword({ email, password })
200+
201+
expect(error).toBeNull()
202+
expect(data.user).toBeDefined()
203+
expect(data.user!.email).toBe(email)
204+
205+
const { error: signOutError } = await supabase.auth.signOut()
206+
207+
expect(signOutError).toBeNull()
208+
})
209+
210+
test('should get current user', async () => {
211+
const email = `test-${Date.now()}@example.com`
212+
const password = 'password123'
213+
214+
await supabase.auth.signUp({ email, password })
215+
await supabase.auth.signInWithPassword({ email, password })
216+
217+
const { data, error } = await supabase.auth.getUser()
218+
219+
expect(error).toBeNull()
220+
expect(data.user).toBeDefined()
221+
expect(data.user!.email).toBe(email)
222+
})
223+
224+
test('should handle invalid credentials', async () => {
225+
const email = `test-${Date.now()}@example.com`
226+
const password = 'password123'
227+
228+
await supabase.auth.signUp({ email, password })
229+
230+
const { data, error } = await supabase.auth.signInWithPassword({
231+
email,
232+
password: 'wrongpassword',
233+
})
234+
235+
expect(error).not.toBeNull()
236+
expect(data.user).toBeNull()
237+
})
238+
239+
test('should handle non-existent user', async () => {
240+
const email = `nonexistent-${Date.now()}@example.com`
241+
const password = 'password123'
242+
243+
const { data, error } = await supabase.auth.signInWithPassword({
244+
email,
245+
password,
246+
})
247+
248+
expect(error).not.toBeNull()
249+
expect(data.user).toBeNull()
250+
})
192251
})
193252

194253
describe('Realtime', () => {

test/integration/bun/integration.test.ts

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import { test, expect } from 'bun:test'
22
import { createClient } from '@supabase/supabase-js'
33

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'
87

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+
})
1211

13-
// Setup authentication
12+
test('should subscribe to realtime channel', async () => {
1413
await supabase.auth.signOut()
1514
const email = `bun-test-${Date.now()}@example.com`
1615
const password = 'password123'
@@ -43,3 +42,70 @@ test('should subscribe to realtime channel', async () => {
4342
// Cleanup
4443
await supabase.removeAllChannels()
4544
}, 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+
})

test/integration/next/playwright.config.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ export default defineConfig({
44
testDir: './tests',
55
fullyParallel: true,
66
forbidOnly: !!process.env.CI,
7-
retries: process.env.CI ? 2 : 0,
7+
retries: 0,
88
workers: process.env.CI ? 1 : undefined,
9+
timeout: 20000,
910
reporter: 'html',
1011
use: {
1112
baseURL: 'http://localhost:3000',
12-
trace: 'on-first-retry',
13-
video: 'on-first-retry',
13+
trace: 'retain-on-failure',
14+
screenshot: 'only-on-failure',
1415
},
1516
projects: [
1617
{

test/integration/node-browser/playwright.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ export default defineConfig({
66
forbidOnly: !!process.env.CI,
77
retries: 0,
88
workers: process.env.CI ? 1 : undefined,
9+
timeout: 20000,
910
reporter: 'html',
1011
use: {
1112
baseURL: 'http://localhost:8004',
12-
trace: 'on-first-retry',
13+
trace: 'retain-on-failure',
14+
screenshot: 'only-on-failure',
1315
},
1416
projects: [
1517
{

0 commit comments

Comments
 (0)