diff --git a/src/routers/institutions.py b/src/routers/institutions.py index 78b5d5b..2ef1297 100644 --- a/src/routers/institutions.py +++ b/src/routers/institutions.py @@ -53,6 +53,8 @@ async def create_institution( async def get_associated_institutions(request: Request): user: AuthenticatedUser = request.user email_domain = get_email_domain(user.email) + if not user.institutions: + return [] associated_institutions = await repo.get_institutions(request.state.db_session, user.institutions) return [ FinanicialInstitutionAssociationDto( diff --git a/tests/api/routers/test_institutions_api.py b/tests/api/routers/test_institutions_api.py index 3af621f..3fe1bcd 100644 --- a/tests/api/routers/test_institutions_api.py +++ b/tests/api/routers/test_institutions_api.py @@ -172,3 +172,24 @@ def test_get_associated_institutions( inst2 = next(filter(lambda inst: inst["lei"] == "TESTBANK234", data)) assert inst1["approved"] is False assert inst2["approved"] is True + + def test_get_associated_institutions_with_no_institutions( + self, app_fixture: FastAPI, auth_mock: Mock, get_institutions_mock: Mock + ): + get_institutions_mock.return_value = None + claims = { + "name": "test", + "preferred_username": "test_user", + "email": "test@test234.bank", + "sub": "testuser123", + "institutions": [], + } + auth_mock.return_value = ( + AuthCredentials(["authenticated"]), + AuthenticatedUser.from_claim(claims), + ) + client = TestClient(app_fixture) + res = client.get("/v1/institutions/associated") + assert res.status_code == 200 + get_institutions_mock.assert_not_called() + assert res.json() == []