diff --git a/colin-api/src/colin_api/models/filing.py b/colin-api/src/colin_api/models/filing.py index f331822f23..b95b455fb4 100644 --- a/colin-api/src/colin_api/models/filing.py +++ b/colin-api/src/colin_api/models/filing.py @@ -925,6 +925,56 @@ def get_historic_filings(cls, business: Business) -> List: # pass through exception to caller raise err + @classmethod + def get_future_effective_filings(cls, business: Business) -> List: + """Get the list of all future effective filings for a business.""" + try: + future_effective_filings = [] + current_date = datetime.datetime.utcnow().strftime('%Y-%m-%d') + cursor = DB.connection.cursor() + cursor.execute( + """ + select event.event_id, event_timestmp, filing_typ_cd, effective_dt, period_end_dt, agm_date + from event join filing on event.event_id = filing.event_id + where corp_num=:identifier + and filing.effective_dt > TO_DATE(:current_date, 'YYYY-mm-dd') + order by event_timestmp + """, + identifier=business.corp_num, + current_date=current_date + ) + filings_info_list = [] + + for filing_info in cursor: + filings_info_list.append(dict(zip([x[0].lower() for x in cursor.description], filing_info))) + for filing_info in filings_info_list: + filing_info['filing_type'] = cls._get_filing_type(filing_info['filing_typ_cd']) + date = convert_to_json_date(filing_info['event_timestmp']) + filing = Filing() + filing.business = business + filing.header = { + 'date': date, + 'name': filing_info['filing_type'], + 'effectiveDate': convert_to_json_date(filing_info['effective_dt']), + 'availableOnPaperOnly': True, + 'colinIds': [filing_info['event_id']] + } + filing.body = { + filing_info['filing_type']: { + } + } + future_effective_filings.append(filing.as_dict()) + return future_effective_filings + + except InvalidFilingTypeException as err: + current_app.logger.error('Unknown filing type found when getting future effective filings for ' + f'{business.get_corp_num()}.') + raise err + + except Exception as err: + current_app.logger.error(err.with_traceback(None)) + raise err + @classmethod def add_administrative_dissolution_event(cls, con, corp_num) -> int: """Add administrative dissolution event.""" diff --git a/colin-api/src/colin_api/resources/filing.py b/colin-api/src/colin_api/resources/filing.py index 838723cbb1..76bdb1c36a 100644 --- a/colin-api/src/colin_api/resources/filing.py +++ b/colin-api/src/colin_api/resources/filing.py @@ -58,6 +58,11 @@ def get(legal_type, identifier, filing_type, filing_sub_type=None): corp_types = Business.CORP_TYPE_CONVERSION[legal_type] business = Business.find_by_identifier(identifier, corp_types) + # get future effective filings + if filing_type == 'future': + future_effective_filings_info = Filing.get_future_effective_filings(business=business) + return jsonify(future_effective_filings_info) + # get filings history from before bob-date if filing_type == 'historic': historic_filings_info = Filing.get_historic_filings(business=business) diff --git a/colin-api/tests/postman/colin-api.postman_collection.json b/colin-api/tests/postman/colin-api.postman_collection.json index a80b967867..e4d514b200 100644 --- a/colin-api/tests/postman/colin-api.postman_collection.json +++ b/colin-api/tests/postman/colin-api.postman_collection.json @@ -1,11 +1,10 @@ { "info": { - "_postman_id": "4c9af778-f52b-420f-b381-38632538ce00", + "_postman_id": "567fd008-1708-46f2-b7d6-babefc7b1da3", "name": "colin-api", "description": "version=0.108 - This is a Colin API description", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", - "_exporter_id": "6835935", - "_collection_link": "https://warped-escape-616276.postman.co/workspace/bc-registries~8ef8e652-492a-4d19-b978-d4f0da255b2c/collection/6835935-4c9af778-f52b-420f-b381-38632538ce00?action=share&creator=6835935&source=collection_link" + "_exporter_id": "31792407" }, "item": [ { @@ -4495,6 +4494,62 @@ ] } ] + }, + { + "name": "Future Effective Filings", + "item": [ + { + "name": "GET FE CP0002098", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Response time is less than 20000ms\", function () {", + " pm.expect(pm.response.responseTime).to.be.below(20000);", + "});", + "", + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.have.status(200);", + "});", + "", + "pm.test('should return JSON', function () {", + " pm.response.to.have.header('Content-Type', 'application/json');", + "});" + ], + "type": "text/javascript", + "packages": {} + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + } + ], + "url": { + "raw": "{{url}}/api/v1/businesses/CP/CP0002098/filings/future", + "host": [ + "{{url}}" + ], + "path": [ + "api", + "v1", + "businesses", + "CP", + "CP0002098", + "filings", + "future" + ] + } + }, + "response": [] + } + ] } ] }, diff --git a/colin-api/tests/unit/api/test_future_effective_filings.py b/colin-api/tests/unit/api/test_future_effective_filings.py new file mode 100644 index 0000000000..0d9527b9b0 --- /dev/null +++ b/colin-api/tests/unit/api/test_future_effective_filings.py @@ -0,0 +1,51 @@ +# Copyright © 2024 Province of British Columbia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Tests to assure the future effective filings end-point. + +Test-Suite to ensure that the future effective filings endpoint is working as expected. +""" +import json +from datetime import datetime + +from dateutil.relativedelta import relativedelta +from registry_schemas.example_data import ANNUAL_REPORT + +from tests import oracle_integration + + +@oracle_integration +def test_get_future_effective_filings(client): + """Assert that the future effective filings are successfully returned.""" + identifier = 'CP0001965' + effective_date = datetime.utcnow() + relativedelta(months=5) + + headers = {'content-type': 'application/json'} + fake_filing = ANNUAL_REPORT + fake_filing['filing']['header']['learEffectiveDate'] = \ + f"{effective_date.strftime('%Y-%m-%d')}T15:22:39.868757+00:00" + fake_filing['filing']['business']['identifier'] = 'CP0001965' + fake_filing['filing']['annualReport']['annualGeneralMeetingDate'] = '2018-04-08' + fake_filing['filing']['annualReport']['annualReportDate'] = '2018-04-08' + + rv = client.post('/api/v1/businesses/CP/CP0001965/filings/annualReport', + data=json.dumps(fake_filing), headers=headers) + + assert 201 == rv.status_code + + rv = client.get(f'/api/v1/businesses/CP/{identifier}/filings/future') + + assert 200 == rv.status_code + future_effective_filings = rv.json + assert len(future_effective_filings) > 0