Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e login test #609

Merged
merged 21 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ yarn-error.log*

# Tests
/report
/test-results/
/playwright-report/
/playwright/.cache/

# eslint
.eslintcache
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@ services:
POSTGRES_DB: saas-starter-kit
ports:
- 5432:5432
test-db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: testpassword
POSTGRES_USER: testuser
POSTGRES_DB: saas-starter-kit
ports:
- 5432:5432
15 changes: 11 additions & 4 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const config: PlaywrightTestConfig = {
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},
// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'] },
// },
],
reporter: [
[
Expand All @@ -23,12 +23,19 @@ const config: PlaywrightTestConfig = {
webServer: {
command: 'npm run start',
url: 'http://localhost:4002',
reuseExistingServer: true,
env: {
NODE_ENV: 'test',
DATABASE_URL:
'postgresql://testuser:testpassword@localhost:5432/saas-starter-kit',
},
},
use: {
headless: true,
ignoreHTTPSErrors: true,
baseURL: 'http://localhost:4002',
video: 'off',
},
testDir: './tests',
};
export default config;
37 changes: 36 additions & 1 deletion tests/e2e/auth/login.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
import { expect, test } from '@playwright/test';
import { prisma } from '@/lib/prisma';

const userCred = {
name: 'test',
email: 'test@ggxd.com',
password: 'Test123#',
emailVerified: new Date(),
};

test.beforeEach(async () => {
devkiran marked this conversation as resolved.
Show resolved Hide resolved
await prisma.user.create({
data: userCred,
});

console.log('user created');
});

test('Should navigate to login page', async ({ page }) => {
page.goto('/');
await page.goto('/auth/login');
await expect(page).toHaveURL('/auth/login');
await page.getByPlaceholder('Email').fill(userCred.email);
await page.getByPlaceholder('Password').fill(userCred.password);
await page.getByRole('button', { name: 'Sign in' }).click();
// await expect(page).toHaveURL(/\/teams\/.*\/settings/);
});

test.afterEach(async () => {
// 1. Clean the database
const deleteUserDetails = prisma.user.delete({
where: {
email: userCred.email,
},
});
await prisma.$transaction([deleteUserDetails]);

// 2. Disconnect
await prisma.$disconnect();

console.log('Account disconnected successfully');
});
Loading