diff --git a/legal-api/src/legal_api/resources/v2/business/business_filings/business_filings.py b/legal-api/src/legal_api/resources/v2/business/business_filings/business_filings.py index 357941a56b..2a9a9821d9 100644 --- a/legal-api/src/legal_api/resources/v2/business/business_filings/business_filings.py +++ b/legal-api/src/legal_api/resources/v2/business/business_filings/business_filings.py @@ -265,6 +265,24 @@ def patch_filings(identifier, filing_id=None): return jsonify(filing.json), HTTPStatus.ACCEPTED +@bp.route('/filings/search/', methods=['GET']) +@cross_origin(origin='*') +@jwt.has_one_of_roles([UserRoles.staff]) +def get_single_filing_by_filing_id(filing_id): + """Return a single filing by filing ID.""" + try: + filing_query = Filing.find_by_id(filing_id) + + if not filing_query: + return {'message': f'Filing with ID {filing_id} not found.'}, HTTPStatus.NOT_FOUND + + return jsonify(filing_query.json), HTTPStatus.OK + + except Exception as err: + current_app.logger.error('Error retrieving filing data for ID %s: %s', filing_id, err) + return {'error': 'Unable to retrieve filing data.'}, HTTPStatus.INTERNAL_SERVER_ERROR + + class ListFilingResource(): # pylint: disable=too-many-public-methods """Business Filings service.""" diff --git a/legal-api/tests/unit/resources/v2/test_business_filings/test_filings.py b/legal-api/tests/unit/resources/v2/test_business_filings/test_filings.py index 5c73c93a43..08c2c9bea8 100644 --- a/legal-api/tests/unit/resources/v2/test_business_filings/test_filings.py +++ b/legal-api/tests/unit/resources/v2/test_business_filings/test_filings.py @@ -116,6 +116,33 @@ def test_get_temp_business_filing(session, client, jwt, legal_type, filing_type, assert rv.json['filing'][filing_type] == filing_json +def test_get_filing_not_found(session, client, jwt): + """Assert that the request fails if the filing ID doesn't match an existing filing.""" + rv = client.get('/api/v2/businesses/filings/search/99999', + headers=create_header(jwt, [STAFF_ROLE])) + + assert rv.status_code == HTTPStatus.NOT_FOUND + assert rv.json == {'message': 'Filing with ID 99999 not found.'} + + +def test_get_filing_valid_filing_id(session, client, jwt): + """Assert that a valid filing ID returns the correct filing.""" + + identifier = 'CP7654321' + b = factory_business(identifier) + + filing_data = copy.deepcopy(ANNUAL_REPORT) + filing = factory_filing(b, filing_data) + + rv = client.get(f'/api/v2/businesses/filings/search/{filing.id}', + headers=create_header(jwt, [STAFF_ROLE])) + + assert rv.status_code == HTTPStatus.OK + assert 'filing' in rv.json + assert rv.json['filing']['annualReport'] == ANNUAL_REPORT['filing']['annualReport'] + assert rv.json['filing']['business'] == ANNUAL_REPORT['filing']['business'] + + def test_get_one_business_filing_by_id(session, client, jwt): """Assert that the business info cannot be received in a valid JSONSchema format.""" identifier = 'CP7654321'