Skip to content
This repository has been archived by the owner on Nov 18, 2024. It is now read-only.

Commit

Permalink
Tests (#28)
Browse files Browse the repository at this point in the history
* Ressources

* Rajout front (/creer-ressource, une-ressource/id, /ressrouces)

* Create layout.tsx

* Modification affichage des ressources

Autres points d'améliorations :
- Faire l'affichage d'une ressource (par catégorie)
-Terminer les filtres
-Rajouter des détails

* Update page.tsx

* Modification créer/liste ressource

Rajout envoi de l'idUser et ressource publique (true/false)

* add type
+ DB
+ API v26

* badge number of categories

* Création du back getARessource

* stats/users
+ API
+ CR of ressources

* dashboard & some details

* fix build errors

* add "+1" to view_count

* ressource update live

* CreateRessource
API
DB

* working on create ressource

* withCredentials

* accept/reject
+ API

* [Back-office] Ressource pages

* Ressources pages & middleware

* accept/reject/block
pending
accepted/rejected/blocked
+ API

* subfolder for ressource management

* first look of pending ressources with partial mocks

* accept / reject / block a ressource

* popconfirm on actions

* jsp si j'ai tout cassé
start REFACTO category / ressource
API

* getRessource

* test without mock

* j'ai pas test

* Fixed layout

* Nouvelle hiérarchisation des fichiers

(connected) - (disconnected)

* refacto + add myRessources
+ API

* stats ressources + myRessources
+ API

* Only view profil (update is disable for the moment (not dev) ) (#27)

* Commit des modification sur le profil + branche basée sur dev

* Update général

Rajout layout global pour le front office + rajout dashboard + modification de l'affichage du profil par le user provider + rajout drapeaux sur l'affichage du profil

* Update page.tsx

* update

* Update général fonctionnalité viewUpdateProfil

* Update header.tsx

* Update header.tsx

* Modification du component PasswordInput

Rajout boolean useRegex (true/false)

* Disable bouton "Modifier" car la fonctionnalité n'est pas encore développée

* fixed layouts & folders

* fixed build error

* List of pending ressources in "my ressources"

* Disable modifier on view profil

* UX for disabled modify on profil

* Moved Page Summarry component

* add staffComment
+ API
+ DB

* add staffComment to /block (patch to post)
+ API

* add profile picture random on create / signup
+ DB (new table)

* change route to "ressource/create"
add route edit
+ API

* edit route correction

* delete route
+ API

* change access stats ressource

* edit ressource all field required.

* dashboard preview for ressources stats

* fixed create ressource endpoint

* fixed build error

* comments for refuse & block ressource

* staff comment to ressource type for block & refuse ressource

* Edit a ressource

* UI tabs for mes-ressources

* accepted / blocked / refused ressources

* Change api / user
api / users
api / category

+ API

* remove disabled ressources from sidebar

* delete ressource by moderator +
+ API

* Si la ressource n'est pas acceptée, seul l'owner et le staff peuvent la voir

* delete a ressource & display a ressource

* recommended extensions

* fixed verify email

Since an unverified account can log in, the verification-email page must be accessible to everyone

* Modification viewAndUpdate profile

création composant "changeUserPassword" + modification de la page profil existante

* Update couleur border viewAndUpdateProfile

* Ajout des mentions légales

* refractor ressources accordions

* Rajout des bouton supprimer profil/données profil + récuperer ses données

* Profil : align to left

* edit swagger

* scroll admin sidebar

* List des catégories + affichage des ressources par catégorie

* empty email & password test

* wrong credentials & pipeline

* remove right credentials tests

* Update cypress.yml

* Par pitié le K

* test

* test password visibility

* test empty signup

* Init test
DB ! create the DB and import it before test :)

* fixed middleware

* Display empty element if no ressources to display

* test cookies

* test login right credentials

* dashboard tests

* update layouts, not found page and routing

* button link to homepage

* more tests
Categories test must be based on ressources branch

* Update Test DB

* some tests

* show empty component when no ressources

* remove ressources list from header

remove ressources list from header since ressources are available through the categories

* reroute user based on role

* display modify ressource only if owner

* display list of ressources

---------

Co-authored-by: KilianBre <[email protected]>
Co-authored-by: Capryc0rne <[email protected]>
  • Loading branch information
3 people authored Apr 25, 2024
1 parent 35ff9f9 commit c2b49a3
Show file tree
Hide file tree
Showing 144 changed files with 9,477 additions and 2,334 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Cypress Tests
on: [push]
jobs:
cypress-run:
runs-on: ubuntu-latest
# Runs tests in parallel with matrix strategy https://docs.cypress.io/guides/guides/parallelization
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs
# Also see warning here https://github.com/cypress-io/github-action#parallel
strategy:
fail-fast: false # https://github.com/cypress-io/github-action/issues/48
matrix:
containers: [1, 2] # Uses 2 parallel instances
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cypress run
# Uses the official Cypress GitHub action https://github.com/cypress-io/github-action
uses: cypress-io/github-action@v6
with:
# Starts web server for E2E tests - replace with your own server invocation
# https://docs.cypress.io/guides/continuous-integration/introduction#Boot-your-server
# we must cd in frontend
working-directory: frontend
install: npm install
build: npm run build
start: npm start
wait-on: "http://localhost:3000" # Waits for above
# Records to Cypress Cloud
# https://docs.cypress.io/guides/cloud/projects#Set-up-a-project-to-record
record: true
parallel: true # Runs test in parallel using settings above
env:
# For recording and parallelization to work you must set your CYPRESS_RECORD_KEY
# in GitHub repo → Settings → Secrets → Actions
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
# Creating a token https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }}
6 changes: 5 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"bradlc.vscode-tailwindcss",
"chakrounanas.turbo-console-log",
"aaron-bond.better-comments",
"redhat.vscode-yaml"
"redhat.vscode-yaml",
"formulahendry.auto-rename-tag",
"bierner.color-info",
"ms-vsliveshare.vsliveshare",
"chinchiheather.vscode-margin-colours"
]
}
1,247 changes: 686 additions & 561 deletions DB/ressources_relationnelles.sql

Large diffs are not rendered by default.

1,052 changes: 1,052 additions & 0 deletions DB/test_ressources_relationnelles.sql

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
.env
.env.backup
.env.production
.env.testing
.phpunit.result.cache
Homestead.json
Homestead.yaml
Expand Down
28 changes: 11 additions & 17 deletions backend/app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Utils\Utils;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cookie;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;

Expand Down Expand Up @@ -57,8 +58,7 @@ class AuthController extends Controller
* )
* )
*/
public function login(Request $request)
{
public function login(Request $request) {
$credentials = $request->validate([
'email' => 'required|email',
'password' => 'required'
Expand Down Expand Up @@ -128,8 +128,7 @@ public function login(Request $request)
* ),
* )
*/
public function signup(Request $request)
{
public function signup(Request $request) {
$data = $request->validate([
'email' => 'required|email',
'firstName' => 'required',
Expand All @@ -156,7 +155,7 @@ public function signup(Request $request)
'is_verified' => self::EMAIL_NOT_VERIFIED,
'ban_until' => self::IS_NOT_BANNED,
'verification_token' => $verificationToken,
'path_picture' => 'https://api.dicebear.com/7.x/bottts-neutral/svg?seed=Angel',
'id_profile_picture' => Utils::getRandomProfilePicture()->id_profile_picture,
]);

$user->notify(new VerifyEmail());
Expand Down Expand Up @@ -184,16 +183,15 @@ public function signup(Request $request)
* response=401,
* description="Invalid verification token",
* @OA\JsonContent(
* @OA\Property(property="message", type="string", example="Token de vérification invalide")
* @OA\Property(property="message", type="string", example="Wrong number of segments")
* )
* )
* )
*/
public function logout()
{
public function logout() {
try {
auth()->logout();
$cookie = \Cookie::forget('token');
$cookie = Cookie::forget('token');
return response(null, 200)->withCookie($cookie);
} catch (\Exception $e) {
return response()->json(['message' => 'Token de vérification invalide'], 401);
Expand Down Expand Up @@ -233,8 +231,7 @@ protected function respondWithTokenAndUserData($token, $data = [])
* )
* )
*/
public function verifyUser()
{
public function verifyUser() {
$user = auth()->user();
if (!$user) return response()->json(['error' => 'Utilisateur non authentifié'], 401);
return response()->json(['user' => Utils::getUserData($user)]);
Expand Down Expand Up @@ -270,8 +267,7 @@ public function verifyUser()
* ),
* )
*/
public function verifyEmail(Request $request)
{
public function verifyEmail(Request $request) {
$token = $request->input('token');

$user = User::where('verification_token', $token)->first();
Expand Down Expand Up @@ -310,8 +306,7 @@ public function verifyEmail(Request $request)
* )
* )
*/
public function forgotPassword()
{
public function forgotPassword() {
$data = request()->validate([
'email' => 'required|email',
]);
Expand Down Expand Up @@ -361,8 +356,7 @@ public function forgotPassword()
*
* )
*/
public function resetPassword()
{
public function resetPassword() {
$data = request()->validate([
'token' => 'required',
'password' => 'required|min:8',
Expand Down
64 changes: 9 additions & 55 deletions backend/app/Http/Controllers/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CategoryController extends Controller {
public function getAllCategories() {
$categories = Category::all();
$categoriesTransformed = $categories->map(function ($category) {
return self::formatCategory($category, true);
return Utils::getCategoryDetail($category, true);
});

return response()->json(['categories' => $categoriesTransformed]);
Expand Down Expand Up @@ -87,7 +87,7 @@ public function getAllCategories() {
public function getActiveCategories() {
$activeCategories = Category::where('is_active', 1)->get();
$activeCategoriesTransformed = $activeCategories->map(function ($category) {
return self::formatCategory($category);
return Utils::getCategoryDetail($category, false);
});

return response()->json(['categories' => $activeCategoriesTransformed]);
Expand Down Expand Up @@ -117,13 +117,7 @@ public function getActiveCategories() {
* type="object",
* @OA\Property(
* property="category",
* ref="#/components/schemas/Category"
* ),
* @OA\Property(
* property="ressources",
* type="array",
* description="List of ressources associated with the category",
* @OA\Items(type="string")
* ref="#/components/schemas/CategoryDetailWithRessources"
* )
* )
* ),
Expand All @@ -141,13 +135,12 @@ public function getCategory($id) {
return response()->json(['message' => 'Catégorie non trouvée'], 404);
}

//TODO : Get ressources associated with the category and regenerate the documentation
return response()->json(['category' => self::formatCategory($category), 'ressources' => ['Not implemented yet']]);
return response()->json(['category' => Utils::getCategoryDetailWithRessources($category)]);
}

/**
* @OA\Post(
* path="/createCategory",
* path="/category/create",
* tags={"Categories"},
* summary="Create a category",
* description="Creates a new category. This endpoint is restricted to admin users.",
Expand Down Expand Up @@ -221,12 +214,12 @@ public function createCategory(Request $request) {
$category->created_by = auth()->user()->id_user;
$category->save();

return response()->json(['category' => self::formatCategory($category)], 201);
return response()->json(['category' => Utils::getCategoryDetail($category)], 201);
}

/**
* @OA\Post(
* path="/editCategory/{id}",
* path="/category/edit/{id}",
* tags={"Categories"},
* summary="Edit a category",
* description="Edit an existing category. This endpoint is restricted to admin users.",
Expand Down Expand Up @@ -314,12 +307,12 @@ public function editCategory($id, Request $request) {
$category->is_active = $request->input('isActive', $category->is_active);
$category->save();

return response()->json(['category' => self::formatCategory($category,true)], 200);
return response()->json(['category' => Utils::getCategoryDetail($category,true)], 200);
}

/**
* @OA\Delete(
* path="/deleteCategory/{id}",
* path="/category/delete/{id}",
* tags={"Categories"},
* summary="Delete a category",
* description="Deletes a category by its ID. This endpoint is restricted to admin users.",
Expand Down Expand Up @@ -370,43 +363,4 @@ public function deleteCategory($id) {
}


/**
* @OA\Schema(
* schema="CategoryDetail",
* type="object",
* description="Detailed information about a category",
* @OA\Property(property="id", type="integer", description="Category ID"),
* @OA\Property(property="title", type="string", description="Title of the category"),
* @OA\Property(property="description", type="string", description="Description of the category"),
* @OA\Property(property="icon", type="string", description="Icon representing the category"),
* @OA\Property(property="color", type="string", description="Color associated with the category. Hexadecimal format with '#': #000000"),
* @OA\Property(property="createdAt", type="string", format="date-time", description="Creation date of the category"),
* @OA\Property(property="updatedAt", type="string", format="date-time", description="Last update date of the category"),
* @OA\Property(property="isActive", type="boolean", description="Whether the category is active. Visible to admins only."),
* @OA\Property(
* property="createdBy",
* type="object",
* description="User details of the creator. Visible to admins only.",
* ref="#/components/schemas/UserDetail"
* ),
* )
*/
public static function formatCategory($category, $getDetails = false){
$user = User::find($category->created_by);
$categoryData = [
'id' => $category->id_category,
'title' => $category->title,
'description' => $category->description,
'icon' => $category->icon,
'color' => $category->color,
'createdAt' => $category->created_at->toDateTimeString(),
'updatedAt' => $category->updated_at->toDateTimeString(),
];

if($getDetails){
$categoryData['isActive'] = $category->is_active;
$categoryData['createdBy'] = Utils::getAllUserData($user);
}
return $categoryData;
}
}
2 changes: 1 addition & 1 deletion backend/app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Routing\Controller as BaseController;

/**
* @OA\Info(title="(Re)Sources Relationnelles", version="0.25")
* @OA\Info(title="(Re)Sources Relationnelles", version="0.26.2")
* @OA\Server(url="http://localhost:80/api")
*/
class Controller extends BaseController
Expand Down
Loading

0 comments on commit c2b49a3

Please sign in to comment.