From fcda1e32d84f366b83f653a1355b4f920a607e84 Mon Sep 17 00:00:00 2001 From: Wille Marcel Date: Wed, 5 Jul 2023 16:33:59 -0300 Subject: [PATCH] Add tests to OSM Teams integration --- backend/__init__.py | 2 +- backend/api/teams/resources.py | 1 + backend/models/dtos/team_dto.py | 1 + backend/models/postgis/statuses.py | 1 + .../src/components/teamsAndOrgs/management.js | 1 + .../src/components/teamsAndOrgs/members.js | 8 +- .../src/components/teamsAndOrgs/messages.js | 17 ++- .../src/components/teamsAndOrgs/teamSync.js | 19 ++- frontend/src/components/teamsAndOrgs/teams.js | 5 +- frontend/src/hooks/UseOSMTeams.js | 6 +- .../src/network/tests/mockData/osmTeams.js | 79 +++++++++++ frontend/src/network/tests/mockData/teams.js | 2 +- frontend/src/network/tests/server-handlers.js | 20 ++- frontend/src/routes.js | 3 +- frontend/src/views/teams.js | 18 +-- frontend/src/views/tests/teams.test.js | 127 +++++++++++++++++- 16 files changed, 274 insertions(+), 36 deletions(-) create mode 100644 frontend/src/network/tests/mockData/osmTeams.js diff --git a/backend/__init__.py b/backend/__init__.py index f4e631c63e..88d8848bbe 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -106,7 +106,7 @@ def create_app(env="backend.config.EnvironmentConfig"): env = "backend.config.TestEnvironmentConfig" app.config.from_object(env) # Enable logging to files - initialise_logger(app) + # initialise_logger(app) app.logger.info("Starting up a new Tasking Manager application") # Connect to database diff --git a/backend/api/teams/resources.py b/backend/api/teams/resources.py index 4643349aea..b2494d723c 100644 --- a/backend/api/teams/resources.py +++ b/backend/api/teams/resources.py @@ -366,6 +366,7 @@ def post(self): - "ANY" - "BY_REQUEST" - "BY_INVITE" + - "OSM_TEAMS" responses: 201: description: Team created successfully diff --git a/backend/models/dtos/team_dto.py b/backend/models/dtos/team_dto.py index 30cf5a16d6..d0b266ab60 100644 --- a/backend/models/dtos/team_dto.py +++ b/backend/models/dtos/team_dto.py @@ -39,6 +39,7 @@ def validate_team_join_method(value): f"{TeamJoinMethod.ANY.name}, " f"{TeamJoinMethod.BY_INVITE.name}, " f"{TeamJoinMethod.BY_REQUEST.name}" + f"{TeamJoinMethod.OSM_TEAMS.name}" ) diff --git a/backend/models/postgis/statuses.py b/backend/models/postgis/statuses.py index ef78498948..57c70b7651 100644 --- a/backend/models/postgis/statuses.py +++ b/backend/models/postgis/statuses.py @@ -130,6 +130,7 @@ class TeamJoinMethod(Enum): ANY = 0 BY_REQUEST = 1 BY_INVITE = 2 + OSM_TEAMS = 3 class TeamRoles(Enum): diff --git a/frontend/src/components/teamsAndOrgs/management.js b/frontend/src/components/teamsAndOrgs/management.js index c35dd62c44..47d073aaff 100644 --- a/frontend/src/components/teamsAndOrgs/management.js +++ b/frontend/src/components/teamsAndOrgs/management.js @@ -54,6 +54,7 @@ export function JoinMethodBox(props) { ANY: 'anyoneCanJoin', BY_REQUEST: 'byRequest', BY_INVITE: 'byInvite', + OSM_TEAMS: 'OSMTeams', }; return (
diff --git a/frontend/src/components/teamsAndOrgs/members.js b/frontend/src/components/teamsAndOrgs/members.js index e69f49b580..4a174bee1c 100644 --- a/frontend/src/components/teamsAndOrgs/members.js +++ b/frontend/src/components/teamsAndOrgs/members.js @@ -83,15 +83,13 @@ export function Members({

{title}

- {!disableEdit && - - } + {!disableEdit && }
- {disableEdit && + {disableEdit && (
- } + )}
{editMode && ( state.auth.token); const [errors, setErrors] = useState(searchParams?.get('syncUsersErrors')); const [showSelectionModal, setShowSelectionModal] = useState(false); + const [isSyncing, setIsSyncing] = useState(false); const reSyncParams = { tmTeamId, members, @@ -141,11 +142,16 @@ export const TeamSync = ({ <> - {errors?.length > 0 && ( + {errors && (
u.username).join(' ,'), + users: + typeof errors === 'object' + ? errors.map((u) => u.username).join(', ') + : [], number: errors.length, }} /> diff --git a/frontend/src/components/teamsAndOrgs/teams.js b/frontend/src/components/teamsAndOrgs/teams.js index 7906cc0b55..6732478f13 100644 --- a/frontend/src/components/teamsAndOrgs/teams.js +++ b/frontend/src/components/teamsAndOrgs/teams.js @@ -167,6 +167,7 @@ export function TeamInformation({ disableJoinMethodField }) { ANY: 'anyoneCanJoin', BY_REQUEST: 'byRequest', BY_INVITE: 'byInvite', + OSM_TEAMS: 'OSMTeams', }; return ( @@ -199,7 +200,7 @@ export function TeamInformation({ disableJoinMethodField }) { name="joinMethod" value={method} required - disabled={disableJoinMethodField} + disabled={disableJoinMethodField || method === 'OSM_TEAMS'} /> @@ -214,7 +215,7 @@ export function TeamInformation({ disableJoinMethodField }) {
))}
- {formState.values.joinMethod === 'BY_INVITE' && ( + {['BY_INVITE', 'OSM_TEAMS'].includes(formState.values.joinMethod) && (