Skip to content

Commit

Permalink
implements e2e auth
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgnlez committed Oct 8, 2024
1 parent 701ce13 commit 8945ab0
Show file tree
Hide file tree
Showing 15 changed files with 552 additions and 28 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: e2e Tests

on:
push:
paths:
- 'e2e/**'
- 'shared/**'
- 'api/**'
- 'client/**'
- '.github/workflows/e2e-tests.yml'
- '/*' # include changes in root
- '!infrastructure/**' # exclude infra folder
- 'package.json'

workflow_dispatch:


jobs:
e2e-tests:
name: e2e tests
runs-on: ubuntu-22.04

services:
database:
image: postgres:13
ports:
- 5432:5432
env:
POSTGRES_USER: blue-carbon-cost
POSTGRES_PASSWORD: blue-carbon-cost
POSTGRES_DB: blc

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Node setup
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'

- uses: pnpm/action-setup@v4

- name: Cache dependencies
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-node_modules-
- name: Install dependencies
working-directory: .
run: pnpm install

- name: Install Chromium browser
working-directory: e2e
run: npx playwright install --with-deps chromium

- name: Run e2e tests
working-directory: e2e
run: pnpm test

- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,8 @@ dist
/infrastructure/.terraform/

# MacOs
.DS_Store
.DS_Store

# e2e
/e2e/playwright-report/
/e2e/test-results/
3 changes: 3 additions & 0 deletions client/.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NEXTAUTH_URL=http://localhost:$PORT
NEXTAUTH_SECRET=WAzjpS46vFxp17TsRDU3FXo+TF0vrfy6uhCXwGMBUE8=
NEXT_PUBLIC_API_URL=https://dev.blue-carbon-cost-tool.dev-vizzuality.com/api
6 changes: 3 additions & 3 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"react": "^18",
"react-dom": "^18",
"tailwind-merge": "2.5.3",
"tailwindcss-animate": "1.0.7"
"tailwindcss-animate": "1.0.7",
"zod": "catalog:"
},
"devDependencies": {
"@types/node": "catalog:",
Expand All @@ -38,7 +39,6 @@
"prettier-plugin-tailwindcss": "0.6.8",
"react-hook-form": "7.53.0",
"tailwindcss": "^3.4.1",
"typescript": "catalog:",
"zod": "catalog:"
"typescript": "catalog:"
}
}
20 changes: 20 additions & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "e2e",
"private": true,
"dependencies": {
"shared": "workspace:*"
},
"devDependencies": {
"@playwright/test": "1.44.1",
"@types/lodash": "4.17.4",
"@types/node": "catalog:",
"tsc-alias": "1.8.10",
"typescript": "catalog:"
},
"scripts": {
"pretest": "tsc && tsc-alias",
"test": "playwright test -c ./dist/e2e",
"test:ui": "pnpm pretest && playwright test --ui -c ./dist/e2e",
"codegen": "pnpm --filter api start:dev & pnpm --filter client dev & playwright codegen localhost:3000"
}
}
48 changes: 48 additions & 0 deletions e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { defineConfig, devices } from '@playwright/test';

const API_URL = 'http://localhost:4000';
const APP_URL = 'http://localhost:3000';

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
/* Run your local dev server before starting the tests */
webServer: [
{
command: 'pnpm --filter api run build && NODE_ENV=test pnpm --filter api run start:prod',
url: API_URL,
reuseExistingServer: !process.env.CI,
},
{
command: 'NODE_ENV=test pnpm --filter client run build && NODE_ENV=test pnpm --filter client run start',
url: APP_URL,
reuseExistingServer: !process.env.CI,
},
],
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: false,
workers: 1,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: process.env.CI ? 'list' : 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: APP_URL,
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},
/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
],
});
62 changes: 62 additions & 0 deletions e2e/tests/auth/auth.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { test, expect, Page } from '@playwright/test';
import { E2eTestManager } from '@shared/lib/e2e-test-manager';
import { User } from '@shared/entities/users/user.entity';

let testManager: E2eTestManager;
let page: Page;

test.beforeAll(async ({ browser }) => {
page = await browser.newPage();
testManager = await E2eTestManager.load(page);
});

test.beforeEach(async () => {
await testManager.clearDatabase();
});

test.afterEach(async () => {
await testManager.clearDatabase();
});

test.afterAll(async () => {
await testManager.close();
});

// test('an user signs up successfully', async ({ page }) => {
// const user: Pick<User, 'email' | 'password'> = {
// email: '[email protected]',
// password: 'password',
// };
//
// await page.goto('/auth/signup');
//
// await page.getByLabel('Email').fill(user.email);
// await page.locator('input[type="password"]').fill(user.password);
// await page.getByRole('checkbox').check();
//
// await page.getByRole('button', { name: /sign up/i }).click();
//
// await page.waitForURL('/auth/signin');
//
// await page.getByLabel('Email').fill(user.email);
// await page.locator('input[type="password"]').fill(user.password);
//
// await page.getByRole('button', { name: /log in/i }).click();
//
// await page.waitForURL('/profile');
// await expect(await page.locator('input[type="email"]')).toHaveValue(
// user.email
// );
// });

test('an user signs in successfully', async ({ page }) => {
const user: Pick<User, 'email' | 'password' | 'partnerName'> = {
email: '[email protected]',
password: '12345678',
partnerName: 'partner-test'
};

await testManager.mocks().createUser(user);
await testManager.login(user as User)
await expect(page.getByText(`Email: ${user.email}`)).toBeVisible();
});
10 changes: 10 additions & 0 deletions e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"module": "CommonJS",
"moduleResolution": "Node",
"sourceMap": false,
"outDir": "./dist",
}
}
Loading

0 comments on commit 8945ab0

Please sign in to comment.