Skip to content

Commit

Permalink
Merge pull request #48 from WildCodeSchool/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Onivoid authored Aug 28, 2024
2 parents fad5e06 + dbc4a4f commit 6c9f692
Show file tree
Hide file tree
Showing 90 changed files with 4,479 additions and 1,274 deletions.
6 changes: 5 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ POSTGRES_HOST=
POSTGRES_PORT=
POSTGRES_USER=
POSTGRES_DB=
POSTGRES_PASSWORD=
POSTGRES_PASSWORD=

JWT_SECRET_KEY=

COOKIE_TTL=
46 changes: 46 additions & 0 deletions .github/workflows/Backend-Static.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Backend CI

on:
push:
paths:
- 'back/**'

jobs:
format:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: 20

- name: Install dependencies
run: npm install
working-directory: back

- name: Check formatting
run: npx prettier .
working-directory: back

lint:
needs: format
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: 20

- name: Install dependencies
run: npm install
working-directory: back

- name: Lint
run: npm run lint
working-directory: back
46 changes: 46 additions & 0 deletions .github/workflows/Frontend-Static.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Frontend CI

on:
push:
paths:
- 'front/**'

jobs:
format:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: 20

- name: Install dependencies
run: npm install
working-directory: front

- name: Check formatting
run: npx prettier .
working-directory: front

lint:
needs: format
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: 20

- name: Install dependencies
run: npm install
working-directory: front

- name: Lint
run: npm run lint
working-directory: front
28 changes: 28 additions & 0 deletions .github/workflows/test-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: test-ci


on:
pull_request:
paths-ignore:
- 'data/**'
- 'front/src/generated/**'

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Build and test
run: docker compose -f docker-compose.test.yaml up --abort-on-container-exit
env:
APP_ENV: ${{ secrets.APP_ENV }}
VITE_API_URL: ${{ secrets.VITE_API_URL }}
BACKEND_PORT: ${{ secrets.BACKEND_PORT }}
POSTGRES_HOST: ${{ secrets.POSTGRES_HOST }}
POSTGRES_PORT: ${{ secrets.POSTGRES_PORT }}
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
JWT_SECRET_KEY: ${{ secrets.JWT_SECRET_KEY }}
COOKIE_TTL: ${{ secrets.COOKIE_TTL }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
.env.test
data/*
data/*
docker-compose-local.test.yaml
28 changes: 27 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
OS := $(shell uname -s)

ifeq ($(OS), Linux)
RM = sudo rm -rf
else ifeq ($(OS), Darwin) # macOS
RM = sudo rm -rf
else ifeq ($(OS), Windows_NT)
RM = rmdir /s /q
else
RM = echo "Unsupported OS"
endif

build-dev:
docker compose -f docker-compose.dev.yaml up --build

Expand All @@ -11,4 +23,18 @@ build-prod:
docker compose -f docker-compose.yaml up --build

run-prod:
docker compose -f docker-compose.yaml up
docker compose -f docker-compose.yaml up

# Après la commande, ajouter name=(NomDeLaMigration)
generate-migration:
docker exec -it backend npm run migration:generate -- src/database/migrations/$(name)

populate-db:
docker exec -it backend npm run populate-db

clean-dev:
docker compose -f docker-compose.dev.yaml down
docker rm -f $(shell docker ps -a -q) 2> /dev/null || true
docker volume rm $(shell docker volume ls -q) 2> /dev/null || true
$(RM) data
docker system prune -f
5 changes: 5 additions & 0 deletions back/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ module.exports = {
rules: {
// Vous pouvez ajouter ou modifier des règles spécifiques ici
},
overrides: [
{
files: ["*.ts"],
},
],
};
30 changes: 18 additions & 12 deletions back/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,48 @@
"main": "src/index.ts",
"scripts": {
"test": "jest",
"lint": "npx eslint --ext .ts src",
"lint": "npx eslint src",
"dev": "ts-node-dev --poll src/index.ts",
"seed": "ts-node-dev src/database/seeder/fixtures.ts"
"seed": "ts-node-dev src/database/seeder/fixtures.ts",
"populate-db": "ts-node src/database/scripts/PopulateDB.ts",
"migration:create": "typeorm-ts-node-commonjs migration:create",
"migration:generate": "typeorm-ts-node-commonjs migration:generate -d src/database/dataSource.ts",
"migration:up": "typeorm-ts-node-commonjs migration:run -d src/database/dataSource.ts",
"migration:down": "typeorm-ts-node-commonjs migration:revert -d src/database/dataSource.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@apollo/server": "4.10.4",
"argon2": "0.40.3",
"axios": "^1.7.2",
"class-validator": "^0.14.1",
"axios": "1.7.2",
"class-validator": "0.14.1",
"cors": "2.8.5",
"dotenv": "16.4.5",
"express": "4.19.2",
"graphql": "16.8.2",
"graphql-scalars": "1.23.0",
"jsonwebtoken": "9.0.2",
"pg": "^8.12.0",
"pg": "8.12.0",
"reflect-metadata": "0.2.2",
"type-graphql": "2.0.0-rc.1",
"typeorm": "0.3.20"
},
"devDependencies": {
"@types/cors": "2.8.17",
"@types/express": "4.17.21",
"@types/jest": "^29.5.12",
"@types/jest": "29.5.12",
"@types/jsonwebtoken": "9.0.6",
"@types/node": "20.14.9",
"@types/supertest": "^6.0.2",
"@typescript-eslint/eslint-plugin": "^7.15.0",
"eslint": "8.56.0",
"@types/supertest": "6.0.2",
"@typescript-eslint/eslint-plugin": "7.15.0",
"eslint": "8.57.0",
"globals": "15.8.0",
"jest": "^29.7.0",
"supertest": "^7.0.0",
"ts-jest": "^29.2.0",
"jest": "29.7.0",
"prettier": "3.3.2",
"supertest": "7.0.0",
"ts-jest": "29.2.0",
"ts-node-dev": "2.0.0"
}
}
99 changes: 92 additions & 7 deletions back/src/__tests__/Url.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import dataSource from "../database/dataSource";
import { Url } from "../entities/Url";


describe("Integration Test Url Entity", () => {
beforeAll(async () => {
await dataSource.initialize();
Expand All @@ -9,18 +10,102 @@ describe("Integration Test Url Entity", () => {
await dataSource.destroy();
});

it("find method should return a list of Url", async () => {
const urls = await Url.find();
it("getPaginateUrls method should return a list of Url", async () => {
const paginateUrls = await Url.getPaginateUrls(1);

// Check if the result has the expected structure
expect(paginateUrls).toHaveProperty('urls');
expect(paginateUrls).toHaveProperty('totalPages');
expect(paginateUrls).toHaveProperty('currentPage');
expect(paginateUrls).toHaveProperty('previousPage');
expect(paginateUrls).toHaveProperty('nextPage');
expect(Array.isArray(paginateUrls.urls)).toBe(true);

// Check if values have the expected structure
paginateUrls.urls.forEach((url) => {
expect(url).toHaveProperty('id');
expect(url).toHaveProperty('name');
expect(url).toHaveProperty('path');
});
});

it("getPaginateUrls method whith searchText should return a list of Url", async () => {
const paginateUrls = await Url.getPaginateUrls(1, "a");

// Check if the result has the expected structure
expect(paginateUrls).toHaveProperty('urls');
expect(paginateUrls).toHaveProperty('totalPages');
expect(paginateUrls).toHaveProperty('currentPage');
expect(paginateUrls).toHaveProperty('previousPage');
expect(paginateUrls).toHaveProperty('nextPage');
expect(Array.isArray(paginateUrls.urls)).toBe(true);

// Check if values have the expected structure
paginateUrls.urls.forEach((url) => {
expect(url).toHaveProperty('id');
expect(url).toHaveProperty('name');
expect(url).toHaveProperty('path');
});
});

it("getPaginateUrls method whith searchText and sortField should return a list of Url", async () => {
const paginateUrls = await Url.getPaginateUrls(1, "a", "name");

// Check if the result is an array
expect(Array.isArray(urls)).toBeTruthy();
// Check if the result has the expected structure
expect(paginateUrls).toHaveProperty('urls');
expect(paginateUrls).toHaveProperty('totalPages');
expect(paginateUrls).toHaveProperty('currentPage');
expect(paginateUrls).toHaveProperty('previousPage');
expect(paginateUrls).toHaveProperty('nextPage');
expect(Array.isArray(paginateUrls.urls)).toBe(true);

// Check if values are instances of Url
urls.forEach((url) => {
expect(url).toBeInstanceOf(Url);
// Check if values have the expected structure
paginateUrls.urls.forEach((url) => {
expect(url).toHaveProperty('id');
expect(url).toHaveProperty('name');
expect(url).toHaveProperty('path');
});
});

it("getPaginateUrls method whith connected user and private url should return a list of Url", async () => {
const paginateUrls = await Url.getPaginateUrls(1, "a", "name", true, "741fbb42-1dd9-40c5-a29e-604407a7bc8c");

// Check if the result has the expected structure
expect(paginateUrls).toHaveProperty('urls');
expect(paginateUrls).toHaveProperty('totalPages');
expect(paginateUrls).toHaveProperty('currentPage');
expect(paginateUrls).toHaveProperty('previousPage');
expect(paginateUrls).toHaveProperty('nextPage');
expect(Array.isArray(paginateUrls.urls)).toBe(true);

// Check if values have the expected structure
paginateUrls.urls.forEach((url) => {
expect(url).toHaveProperty('id');
expect(url).toHaveProperty('name');
expect(url).toHaveProperty('path');
});
});

it("getPaginateUrls method whith connected user and public url should return a list of Url", async () => {
const paginateUrls = await Url.getPaginateUrls(1, "a", "name", false, "741fbb42-1dd9-40c5-a29e-604407a7bc8c");

// Check if the result has the expected structure
expect(paginateUrls).toHaveProperty('urls');
expect(paginateUrls).toHaveProperty('totalPages');
expect(paginateUrls).toHaveProperty('currentPage');
expect(paginateUrls).toHaveProperty('previousPage');
expect(paginateUrls).toHaveProperty('nextPage');
expect(Array.isArray(paginateUrls.urls)).toBe(true);

// Check if values have the expected structure
paginateUrls.urls.forEach((url) => {
expect(url).toHaveProperty('id');
expect(url).toHaveProperty('name');
expect(url).toHaveProperty('path');
});
});


it("findOneByOrFail method should return a single Url", async () => {
const url = await Url.findOneByOrFail({
id: "737fbb42-1dd9-40c5-a29e-604407a7bc7b",
Expand Down
Loading

0 comments on commit 6c9f692

Please sign in to comment.