feat: Add tests for signout button

This commit is contained in:
April Hall 2025-02-26 12:25:02 -05:00
parent 78bdfad8b9
commit 7e29219f9c
3 changed files with 55 additions and 2 deletions

View File

@ -0,0 +1,14 @@
import { auth } from '$lib/server/db/auth';
import { json } from '@sveltejs/kit';
export const GET = async ({ request }) => {
const session = await auth.api.getSession({
headers: request.headers,
});
if (session) {
return json({ status: 200 });
} else {
return json({ status: 401 }, { status: 401 });
}
};

39
tests/signout.spec.ts Normal file
View File

@ -0,0 +1,39 @@
import { test, expect, type Page, type Locator } from '@playwright/test';
import { login } from './utils';
test.describe('Sign Out Button', () => {
let page: Page;
let button: Locator;
test.beforeEach(async ({ browser }) => {
page = await browser.newPage();
// Login and navigate
await login(page);
await page.goto('/account', { timeout: 30000, waitUntil: 'domcontentloaded' });
// Initialize locators
button = page.getByRole('button', { name: 'Sign Out' });
});
test('sign out button signs user out', async ({ request }) => {
// Get cookies from the browser context
const cookies = await page.context().cookies();
const cookieHeader = cookies.map((cookie) => `${cookie.name}=${cookie.value}`).join('; ');
const initalfetch = await request.get('/api/checkauth', {
headers: {
Cookie: cookieHeader,
},
});
expect(initalfetch.status()).toEqual(200);
await button.click();
const finalfetch = await request.get('/api/checkauth', {
headers: {
Cookie: cookieHeader,
},
});
expect(finalfetch.status()).toEqual(401);
});
});

View File

@ -65,8 +65,8 @@ test.describe('Password Update Form', () => {
await expectError('Password must not be empty.', page);
});
// Test update functionalityz
test('should successfully update usser password', async () => {
// Test update functionality
test('should successfully update user password', async () => {
await currentPasswordInput.fill(currentPassword);
await newPasswordInput.fill('newPassword123!');
await submitButton.click();