diff --git a/backend/capellacollab/projects/crud.py b/backend/capellacollab/projects/crud.py index 09c7e71347..b7bc97d200 100644 --- a/backend/capellacollab/projects/crud.py +++ b/backend/capellacollab/projects/crud.py @@ -46,7 +46,7 @@ def update_project( patch_project: models.PatchProject, ) -> models.DatabaseProject: if patch_project.name: - patch_project.name = slugify.slugify(patch_project.name) + project.slug = slugify.slugify(patch_project.name) database.patch_database_with_pydantic_object(project, patch_project) diff --git a/backend/tests/projects/test_projects_routes.py b/backend/tests/projects/test_projects_routes.py index 165128fe8d..0b846f16c0 100644 --- a/backend/tests/projects/test_projects_routes.py +++ b/backend/tests/projects/test_projects_routes.py @@ -20,12 +20,12 @@ def test_get_projects_not_authenticated(client: testclient.TestClient): assert response.json() == {"detail": "Not authenticated"} -def test_get_projects_as_user_only_shows_default_internal_project( +def test_get_internal_default_project_as_user( client: testclient.TestClient, db: orm.Session, executor_name: str ): users_crud.create_user(db, executor_name, users_models.Role.USER) - response = client.get("/api/v1/projects") + response = client.get("/api/v1/projects/default") assert response.status_code == 200 assert { @@ -34,7 +34,24 @@ def test_get_projects_as_user_only_shows_default_internal_project( "description": "", "visibility": "internal", "users": {"leads": 0, "contributors": 0, "subscribers": 0}, - } in response.json() + "is_archived": False, + } == response.json() + + +def test_get_projects_as_user_only_shows_default_internal_project( + client: testclient.TestClient, db: orm.Session, executor_name: str +): + users_crud.create_user(db, executor_name, users_models.Role.USER) + + response = client.get("/api/v1/projects") + + assert response.status_code == 200 + + data = response.json() + + assert len(data) == 1 + assert data[0]["slug"] == "default" + assert data[0]["visibility"] == "internal" @pytest.mark.usefixtures("project_manager") @@ -44,47 +61,50 @@ def test_get_projects_as_user_with_project( response = client.get("/api/v1/projects") assert response.status_code == 200 - assert { - "name": project.name, - "slug": project.slug, - "description": "", - "visibility": "private", - "users": {"leads": 1, "contributors": 0, "subscribers": 0}, - } in response.json() + + data = response.json() + + assert len(data) == 2 + assert data[0]["slug"] == project.slug + assert data[0]["visibility"] == "private" def test_get_projects_as_admin( client: testclient.TestClient, db: orm.Session, executor_name: str ): + project = projects_crud.create_project( + db, "test project", visibility=projects_models.Visibility.PRIVATE + ) users_crud.create_user(db, executor_name, users_models.Role.ADMIN) response = client.get("/api/v1/projects") assert response.status_code == 200 - assert { - "name": "default", - "slug": "default", - "description": "", - "visibility": "internal", - "users": {"leads": 0, "contributors": 0, "subscribers": 0}, - } in response.json() + + data = response.json() + + assert len(data) == 2 + assert data[1]["slug"] == project.slug + assert data[1]["visibility"] == "private" def test_get_internal_projects_as_user( client: testclient.TestClient, db: orm.Session, executor_name: str ): + project = projects_crud.create_project( + db, "test project", visibility=projects_models.Visibility.INTERNAL + ) users_crud.create_user(db, executor_name, users_models.Role.USER) response = client.get("/api/v1/projects") assert response.status_code == 200 - assert { - "name": "default", - "slug": "default", - "description": "", - "visibility": "internal", - "users": {"leads": 0, "contributors": 0, "subscribers": 0}, - } in response.json() + + data = response.json() + + assert len(data) == 2 + assert data[1]["slug"] == project.slug + assert data[1]["visibility"] == "internal" def test_get_internal_projects_as_user_without_duplicates( @@ -105,38 +125,18 @@ def test_get_internal_projects_as_user_without_duplicates( response = client.get("/api/v1/projects") assert response.status_code == 200 - assert { - "name": "default", - "slug": "default", - "description": "", - "visibility": "internal", - "users": {"leads": 0, "contributors": 0, "subscribers": 0}, - } in response.json() - assert { - "name": "test project", - "slug": "test-project", - "description": "", - "visibility": "internal", - "users": {"leads": 0, "contributors": 1, "subscribers": 0}, - } in response.json() - assert len(response.json()) == 2 + data = response.json() -def test_get_internal_default_project_as_user( - client: testclient.TestClient, db: orm.Session, executor_name: str -): - users_crud.create_user(db, executor_name, users_models.Role.USER) + assert len(data) == 2 - response = client.get("/api/v1/projects/default") + assert data[0]["slug"] == "default" + assert data[0]["visibility"] == "internal" + assert data[0]["users"]["contributors"] == 0 - assert response.status_code == 200 - assert { - "name": "default", - "slug": "default", - "description": "", - "visibility": "internal", - "users": {"leads": 0, "contributors": 0, "subscribers": 0}, - } == response.json() + assert data[1]["slug"] == project.slug + assert data[1]["visibility"] == "internal" + assert data[1]["users"]["contributors"] == 1 def test_create_private_project_as_admin( @@ -153,13 +153,11 @@ def test_create_private_project_as_admin( ) assert response.status_code == 200 - assert { - "name": "test project", - "slug": "test-project", - "description": "", - "visibility": "private", - "users": {"leads": 0, "contributors": 0, "subscribers": 0}, - } == response.json() + + data = response.json() + + assert data["slug"] == "test-project" + assert data["visibility"] == "private" def test_create_internal_project_as_admin( @@ -177,20 +175,22 @@ def test_create_internal_project_as_admin( ) assert response.status_code == 200 - assert { - "name": "test project", - "slug": "test-project", - "description": "", - "visibility": "internal", - "users": {"leads": 0, "contributors": 0, "subscribers": 0}, - } == response.json() + + data = response.json() + + assert data["slug"] == "test-project" + assert data["visibility"] == "internal" def test_update_project_as_admin( client: testclient.TestClient, db: orm.Session, executor_name: str ): users_crud.create_user(db, executor_name, users_models.Role.ADMIN) - projects_crud.create_project(db, "new project") + project = projects_crud.create_project(db, "new project") + + assert project.slug == "new-project" + assert project.visibility == projects_models.Visibility.PRIVATE + assert project.is_archived == False response = client.patch( "/api/v1/projects/new-project", @@ -198,14 +198,15 @@ def test_update_project_as_admin( "name": "test project", "description": "", "visibility": "internal", + "is_archived": "true", }, ) assert response.status_code == 200 - assert { - "name": "test project", - "slug": "test-project", - "description": "", - "visibility": "internal", - "users": {"leads": 0, "contributors": 0, "subscribers": 0}, - } == response.json() + + data = response.json() + + assert data["name"] == "test project" + assert data["slug"] == "test-project" + assert data["visibility"] == "internal" + assert data["is_archived"] diff --git a/frontend/src/app/projects/create-project/create-project.component.spec.ts b/frontend/src/app/projects/create-project/create-project.component.spec.ts index af718d434b..cc66232565 100644 --- a/frontend/src/app/projects/create-project/create-project.component.spec.ts +++ b/frontend/src/app/projects/create-project/create-project.component.spec.ts @@ -49,6 +49,7 @@ const mockProjects: Project[] = [ contributors: 0, subscribers: 0, }, + is_archived: false, }, ]; @@ -98,6 +99,7 @@ describe('CreateProjectComponent', () => { slug: project.name!, visibility: project.visibility!, users: { leads: 1, contributors: 0, subscribers: 0 }, + is_archived: false, }; this._project.next(projectToCreate); return of(projectToCreate);