feat: Add tests for signout button
This commit is contained in:
parent
78bdfad8b9
commit
7e29219f9c
14
src/routes/(server)/api/checkauth/+server.ts
Normal file
14
src/routes/(server)/api/checkauth/+server.ts
Normal 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
39
tests/signout.spec.ts
Normal 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);
|
||||||
|
});
|
||||||
|
});
|
@ -65,8 +65,8 @@ test.describe('Password Update Form', () => {
|
|||||||
await expectError('Password must not be empty.', page);
|
await expectError('Password must not be empty.', page);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Test update functionalityz
|
// Test update functionality
|
||||||
test('should successfully update usser password', async () => {
|
test('should successfully update user password', async () => {
|
||||||
await currentPasswordInput.fill(currentPassword);
|
await currentPasswordInput.fill(currentPassword);
|
||||||
await newPasswordInput.fill('newPassword123!');
|
await newPasswordInput.fill('newPassword123!');
|
||||||
await submitButton.click();
|
await submitButton.click();
|
||||||
|
Loading…
Reference in New Issue
Block a user