Skip to content

Commit

Permalink
add log to test backend (#220)
Browse files Browse the repository at this point in the history
* add log to test backend

* fix tests
  • Loading branch information
younes200 authored Oct 30, 2023
1 parent 27ae215 commit 06281e1
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 112 deletions.
10 changes: 7 additions & 3 deletions .env.ci
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
NODE_ENV=test

CI_TEST=true
API_URL=http://localhost:2021/trpc
API_URL=http://127.0.0.1:2021/trpc

# Cookie secret key. Generate something random and long.
DATABASE_URL=postgres://postgres:[email protected]:5432/celluloid
REDIS_URL=redis://127.0.0.1

COOKIE_SECRET=cisecret3
DATABASE_URL=postgres://postgres:postgres@localhost:5432/celluloid
REDIS_URL=redis://localhost
COOKIE_DOMAIN=127.0.0.1
COOKIE_SECURE=false


# email params. Check with your SMTP provider
SMTP_HOST=
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/test-ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: CI e2e Testing
name: CI Testing

on:
push:
branches: [main, master]
branches: [main]
pull_request:
branches: [main, master]
branches: [main]
workflow_dispatch:

jobs:
tests:
Expand Down Expand Up @@ -60,11 +61,12 @@ jobs:

- name: Publish HTML report to gh-pages
if: always()
uses: peaceiris/actions-gh-pages@v3.7.3
uses: peaceiris/actions-gh-pages@v3.9.3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: playwright-report/
destination_dir: playwright-report/
# destination_dir: playwright-report/
keep_files: true
user_name: "github-actions[bot]"
user_email: "github-actions[bot]@users.noreply.github.com"
commit_message: ${{ github.event.head_commit.message }}
74 changes: 52 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ educational purposes." src="./apps/frontend/src/images/logo-sign.svg">

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Docker Build](https://github.com/celluloid-camp/celluloid/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/celluloid-camp/celluloid/actions/workflows/build.yml)
[![Tests](https://github.com/celluloid-camp/celluloid/actions/workflows/test-ci.yml/badge.svg)](https://celluloid-camp.github.io/celluloid/playwright-report)
[![Tests](https://github.com/celluloid-camp/celluloid/actions/workflows/test-ci.yml/badge.svg)](https://celluloid-camp.github.io/celluloid)

## Overview

Expand Down Expand Up @@ -35,35 +35,54 @@ Celluloid is designed to run on a Linux server. Proficiency with the command-lin

- Install the latest version of [Git](https://git-scm.com/).
- Install the latest version of [Node.js](https://nodejs.org/en/).
- Install the latest version of [Yarn](https://yarnpkg.com/en/) and use it instead of NPM. The project is organized as a [monorepo](https://blog.scottlogic.com/2018/02/23/javascript-monorepos.html), so Yarn is required to leverage [Yarn workspace](https://yarnpkg.com/blog/2017/08/02/introducing-workspaces/).
- Install the latest version of [Yarn](https://yarnpkg.com/en/) and use it instead of NPM.

The project is organized as a [monorepo](https://blog.scottlogic.com/2018/02/23/javascript-monorepos.html), so Yarn is required to leverage [Yarn workspace](https://yarnpkg.com/blog/2017/08/02/introducing-workspaces/).

```
.
├── apps/ # Main application containers
│ ├── frontend/ # Frontend application code
│ ├── backend/ # Backend application code
│ └── admin/ # Admin panel code
├── packages/ # Shared packages
│ ├── config/ # Configuration settings and files
│ ├── i18n/ # Internationalization settings and translations
│ ├── passport/ # Passport authentication settings
│ ├── prisma/ # Prisma ORM configurations and schema
│ ├── trpc/ # tRPC settings and utilities
│ ├── types/ # Shared TypeScript types
│ └── utils/ # Shared utilities
├── tests/ # Test scripts and test-related utilities
├── scripts/ # Miscellaneous scripts for automation
├── packages.json # Package manifest
└── .env # Environment variables
```


### 📦 Database

You will need a working [PostgreSQL server](https://www.postgresql.org/docs/current/static/tutorial-install.html), version 13 or later.

For development purposes, you can use the provided Docker Compose [docker-compose.yml](docker-compose.yml) and run the command:
We provide a complete docker compose [stack.yml](stack.yml) ready to run :

```bash
docker-compose up -d
docker compose -f stack.yml up
```

Afterward:

Run the command `yarn dev`

### Emails

A functioning SMTP server is necessary for sending account confirmation emails.
we've configured Nodemailer to use [ethereal.email](https://ethereal.email) to catch all development emails, and regular SMTP in production (easy to replace with a different provider thanks to Nodemailer)

## Installation from Source

### Initial Steps
### Initial steps

Open your terminal and execute the following commands:

```bash
git clone https://github.com/celluloid-edu/celluloid
git clone https://github.com/celluloid-camp/celluloid.git
cd celluloid/
yarn
```
Expand All @@ -78,15 +97,11 @@ cp sample.env .env

Open the newly created .env file with your preferred text editor and configure the values according to your requirements.

### Running the Application in Development Mode

First, ensure that the database is up and running. Then:
### Running the application in development mode

```bash
yarn database setup
```
For development purposes, you can use the provided Docker Compose [docker-compose.yml](docker-compose.yml) and run the command:

At the root of your repository, run:
At the root of your repository, run the projet in development mode:

```bash
yarn dev
Expand All @@ -95,23 +110,38 @@ yarn dev
This will initiate an interactive build and open the app in a browser window while continuously monitoring source files for modifications.
If everything worked without errors, you should be all set. Otherwise, please review the instructions above carefully.

### Building and Starting the Application in Production Mode
### Building and starting the application in production Mode

At the repository's root, execute:

```bash
yarn build
yarn start
```

You can access your app at http://localhost:3001.
To run the backend

### Building and Starting the Application as a Docker Container
```bash
yarn backend start
```

To run the frontend

```bash
yarn frontend start
```

You can access your app at http://localhost:3000.

### Building and starting the application as a docker Container

Open a terminal at the repository's root and run:

```bash
docker-compose up
docker build --build-arg APP=backend -t celluloid-backend:latest .
```

```bash
docker build --build-arg APP=frontend -t celluloid-frontend:latest .
```

(Ensure that [Docker](https://www.docker.com/get-started) is correctly installed.)
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function main() {

// Setup CORS
app.use(cors({
origin: process.env.NODE_ENV != "production" ? ['http://localhost:3000', 'http://localhost:4000'] : undefined,
origin: process.env.NODE_ENV != "production" ? ['http://localhost:3000', 'http://localhost:4000', 'http://127.0.0.1:3000', "http://127.0.0.1:4000"] : undefined,
credentials: true,
}));

Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
"clean": "for package in $(ls packages); do (cd packages/${package} && yarn clean); done",
"build": "dotenv -- turbo run build --no-cache",
"i18n:sync": "yarn workspace @celluloid/i18n sync",
"database:migrate": "./scripts/docker-bootstrap.sh admin",
"eslint": "eslint --ext .js,.jsx,.ts,.tsx",
"prepare": "husky install",
"prettier:all": "prettier --ignore-path .eslintignore \"**/*.{js,jsx,ts,tsx,md}\"",
"test": "npx playwright test",
"--shortcuts to run commands in workspaces--": "",
"frontend": "yarn workspace frontend",
"admin": "yarn workspace admin",
"backend": "yarn workspace backend",
"prisma": "yarn workspace @celluloid/prisma",
"admin": "dotenv -- yarn workspace admin",
"backend": "dotenv -- yarn workspace backend",
"prisma": "dotenv -- yarn workspace @celluloid/prisma",
"docker-build": "DOCKER_BUILDKIT=1 docker build --build-arg APP=backend --build-arg START_COMMAND=start -t celluloid-backend:latest --cache-from=celluloid-backend:latest . "
},
"devDependencies": {
Expand Down
3 changes: 1 addition & 2 deletions packages/prisma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@
"migrate:dev": "yarn prisma migrate dev",
"db:push": "yarn prisma db push",
"seed": "tsx src/seed.ts",
"format": "prisma format",
"generate": "yarn prisma generate",
"lint": "eslint \"src/**/*.ts\"",
"prebuild": "yarn run generate",
"predev": "yarn run generate",
"studio": "yarn prisma studio",
"prisma": "dotenv -e ../../.env -- npx prisma",
"prisma": "npx prisma",
"migrate-metadata": "tsx ./src/migrate-projects-metadata.ts",
"migrate-sharecode": "tsx ./src/migrate-sharecode.ts",
"tsx": "tsx"
Expand Down
18 changes: 8 additions & 10 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ export default defineConfig({
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'] },
// },

// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// },
{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},
{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},

/* Test against mobile viewports. */
// {
Expand Down
29 changes: 0 additions & 29 deletions scripts/docker-bootstrap.sh

This file was deleted.

14 changes: 10 additions & 4 deletions stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,28 @@ services:
- "3000:3000"
command: yarn workspace frontend start
environment:
- PORT=3000
PORT: 3000
build:
args:
NODE_ENV: production
APP: frontend
START_COMMAND: start
API_URL: http://127.0.0.1:2021
context: .

backend:
<<: *defaults
depends_on:
- postgres
ports:
- "3333:3333"
command: yarn workspace backend start
- "2021:2021"
command: ["sh", "-c", "yarn prisma migrate deploy yarn backend start"]
environment:
- PORT=3333
PORT: 2021
DATABASE_URL: postgres://postgres:root@localhost:5432/celluloid
COOKIE_SECRET: changethistosecretcookie
COOKIE_DOMAIN: 127.0.0.1
COOKIE_SECURE: false
build:
args:
APP: backend
Expand Down
61 changes: 51 additions & 10 deletions tests/01-signup.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import { expect, test } from '@playwright/test';
import { expect, Page, test } from '@playwright/test';

test('test signup', async ({ page }) => {
await page.goto('http://localhost:3000/');

const randomNum = Math.floor(Math.random() * 10000);
const TEST_USERNANE = `test${randomNum}`
const TEST_USER_EMAIL = `${TEST_USERNANE}@server.com`;

let page: Page;
test.describe.configure({ mode: 'serial' });

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

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

test('test signup', async () => {
await page.goto('http://127.0.0.1:3000/');
await page.getByTestId('header-login-button').click();
await page.getByTestId('signup').click();
await expect(page).toHaveURL(/.*\/signup/);

await page.getByTestId('username').click();
await page.getByTestId('username').fill('[email protected]');
await page.getByTestId('username').click();
await page.getByTestId('username').fill('test5');
await page.getByTestId('username').fill(TEST_USERNANE);
await page.getByTestId('email').click();
await page.getByTestId('email').fill('[email protected]');
await page.getByTestId('email').fill(TEST_USER_EMAIL);
await page.getByTestId('password').click();
await page.getByTestId('password').fill('testtest');
await page.getByTestId('passwordConfirmation').click();
Expand All @@ -25,7 +39,34 @@ test('test signup', async ({ page }) => {
await page.getByTestId('code').fill('0000');
await page.getByTestId('submit').click();

// await page.getByTestId('header-profile-button').click();
// await page.getByRole('heading', { name: 'test5' }).click();
// await page.getByText('[email protected] - Teacher').click();
await page.goto('http://127.0.0.1:3000/');

await page.getByTestId('header-account-menu').click();
await page.getByTestId('header-logout-button').click();

await expect(page.getByTestId('profile-header-title')).toHaveText(TEST_USERNANE)

});


test('test reconnect with existing account without confirmation', async () => {


await page.goto('http://127.0.0.1:3000/');
await page.getByTestId('header-login-button').click();
await expect(page).toHaveURL(/.*\/login/);

await page.getByTestId('username').click();
await page.getByTestId('username').fill(TEST_USER_EMAIL);
await page.getByTestId('username').press('Tab');
await page.getByTestId('password').fill('testtest');
await page.getByTestId('submit').click();

await expect(page).toHaveURL('http://127.0.0.1:3000/');

await page.getByTestId('header-account-menu').click();
await page.getByTestId('header-logout-button').click();

await expect(page).toHaveURL('http://127.0.0.1:3000/');

});
Loading

0 comments on commit 06281e1

Please sign in to comment.