43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { createAnonClient } from './setup.ts';
|
|
|
|
const client = createAnonClient();
|
|
const email = `test-${Date.now()}@example.com`;
|
|
const password = 'password123';
|
|
|
|
describe('Authentication', () => {
|
|
it('should sign up a new user', async () => {
|
|
const { data, error } = await client.auth.signUp({
|
|
email,
|
|
password,
|
|
});
|
|
|
|
expect(error).toBeNull();
|
|
expect(data.user).toBeDefined();
|
|
expect(data.user?.email).toBe(email);
|
|
expect(data.session).toBeDefined(); // Assuming auto-sign-in on signup
|
|
});
|
|
|
|
it('should sign in an existing user', async () => {
|
|
const { data, error } = await client.auth.signInWithPassword({
|
|
email,
|
|
password,
|
|
});
|
|
|
|
expect(error).toBeNull();
|
|
expect(data.session).toBeDefined();
|
|
expect(data.user).toBeDefined();
|
|
expect(data.user?.email).toBe(email);
|
|
});
|
|
|
|
it('should fail with incorrect password', async () => {
|
|
const { data, error } = await client.auth.signInWithPassword({
|
|
email,
|
|
password: 'wrongpassword',
|
|
});
|
|
|
|
expect(error).toBeDefined();
|
|
expect(data.session).toBeNull();
|
|
});
|
|
});
|