Skip to content

Commit

Permalink
add more tests. Fix some bugs that were making things fail
Browse files Browse the repository at this point in the history
  • Loading branch information
taraepp committed Feb 9, 2024
1 parent 512b782 commit d10cabd
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 30 deletions.
5 changes: 4 additions & 1 deletion services/common/src/constants/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ export const MINE_REPORT = (mineGuid, mineReportGuid) =>
export const MINE_REPORT_SUBMISSIONS = (
params: { mine_report_guid?: string },
latest_submission = true
) => `/mines/reports/submissions?${queryString.stringify({ latest_submission, ...params })}`;
) => {
const queryParams = latest_submission ? { latest_submission, ...params } : params;
return `/mines/reports/submissions?${queryString.stringify(queryParams)}`;
};
export const MINE_REPORT_DOCUMENT = (mineGuid) => `/mines/${mineGuid}/reports/documents`;
export const MINE_REPORT_COMMENTS = (mineGuid, reportGuid) =>
`/mines/${mineGuid}/reports/${reportGuid}/comments`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def json(self):
return {
'mine_report_contact_id': self.mine_report_contact_id,
'mine_report_id': self.mine_report_id,
'mine_report_submission_id': mine_report_submission_id,
'mine_report_submission_id': self.mine_report_submission_id,
'name': str(self.name),
'email': str(self.email)
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,15 @@ def get(self):

data = self.parser.parse_args()
mine_report_guid = data.get('mine_report_guid', None)
latest_submission = data.get('latest_submission', True)
latest_submission = data.get('latest_submission', None)

if mine_report_guid is None:
# TODO: not actually required per se, more like Not Implemented-
# will want to be able to query a list of mine report submissions
# from different mines and different reports
raise BadRequest('Error: mine report guid is required')

if (latest_submission):
if (latest_submission == True):
submission = MineReportSubmission.find_latest_by_mine_report_guid(mine_report_guid)
return submission

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,86 @@
import json
import uuid
import pytest
from datetime import datetime

from app.api.mines.mine.models.mine import Mine
from app.api.mines.reports.models.mine_report import MineReport
from app.api.mines.reports.models.mine_report_submission import MineReportSubmission
from app.api.mines.reports.models.mine_report_definition import MineReportDefinition
from app.api.mines.reports.models.mine_report_submission_status_code import MineReportSubmissionStatusCode
from app.api.constants import MINE_REPORT_TYPE

from tests.factories import MineFactory, MineDocumentFactory, MineReportFactory, MineReportSubmissionFactory, PermitFactory, PermitAmendmentFactory, PartyFactory
THREE_REPORTS = 3
ONE_REPORT = 1
GUID = str(uuid.uuid4)

# GET
def test_get_all_mine_report_submissions_for_report(test_client, db_session, auth_headers):
mine_report = MineReportFactory()

params = f'?mine_report_guid={mine_report.mine_report_guid}'
get_resp = test_client.get(
f'mines/reports/submissions{params}', headers=auth_headers['full_auth_header'])
get_data = json.loads(get_resp.data.decode())

assert len(mine_report.mine_report_submissions) == len(get_data)
assert str(mine_report.mine_report_guid) == get_data[0]['mine_report_guid']
assert get_resp.status_code == 200

def test_get_latest_mine_report_submission_for_report(test_client, db_session, auth_headers):
mine_report = MineReportFactory()

params = f'?latest_submission=true&mine_report_guid={mine_report.mine_report_guid}'
get_resp = test_client.get(
f'mines/reports/submissions{params}', headers=auth_headers['full_auth_header'])
get_data = json.loads(get_resp.data.decode())

assert get_data['mine_report_guid'] == str(mine_report.mine_report_guid)
assert get_resp.status_code == 200


def test_get_latest_report_submission_without_mine_report_guid(test_client, db_session, auth_headers):
# TODO: in the end this is not desired behaviour,
# this is just a reminder to write a real test when implementing
params = '?latest_submission=true'
get_resp = test_client.get(
f'mines/reports/submissions{params}', headers=auth_headers['full_auth_header'])

assert get_resp.status_code == 400

# # POST
def test_post_initial_crr_mine_report_submission(test_client, db_session, auth_headers):
mine = MineFactory(minimal=True)

new_document_data = MineDocumentFactory()
new_document = {
'document_name': new_document_data.document_name,
'document_manager_guid': new_document_data.document_manager_guid
}
mine_report_definition = MineReportDefinition.get_all()[0]

submission_data = {
'description_comment': "description comment",
'documents': [new_document],
'due_date': "2024-02-11",
'mine_guid': mine.mine_guid,
'mine_report_definition_guid': str(mine_report_definition.mine_report_definition_guid),
'received_date': "2024-02-09",
'submission_year': "2024",
'submitter_email': "[email protected]",
'submitter_name': "Submitter Name",
}

# post from Minespace
post_resp = test_client.post(
f'mines/reports/submissions', headers=auth_headers['proponent_only_auth_header'], json=submission_data)
post_data = json.loads(post_resp.data.decode())

mine_report = MineReport.find_by_mine_report_guid(str(post_data['mine_report_guid']))
latest_submission = MineReportSubmission.find_latest_by_mine_report_guid(str(mine_report.mine_report_guid)).json()

num_submissions = len(mine_report.mine_report_submissions)

assert num_submissions == 1
assert latest_submission['mine_report_submission_status_code'] == "INI"

def test_post_additional_mine_report_submission(test_client, db_session, auth_headers):
mine_report = MineReportFactory(mine_report_submissions=1)
Expand All @@ -20,6 +89,7 @@ def test_post_additional_mine_report_submission(test_client, db_session, auth_he
num_submissions = len(mine_report.mine_report_submissions)

# modify original submission
previous_submission = first_submission.json()
submission_data = first_submission.json()

# add a document
Expand All @@ -30,15 +100,15 @@ def test_post_additional_mine_report_submission(test_client, db_session, auth_he
}
submission_data['documents'].append(new_document)

# TODO add a mine report contact

# change report definition
mine_report_definition = MineReportDefinition.get_all()
new_report_definition = [
x for x in mine_report_definition
if x.mine_report_definition_guid != first_submission.mine_report_definition_guid
][0]
submission_data['mine_report_definition_guid'] = new_report_definition.mine_report_definition_guid
# add a mine report contact
new_contact = {
'name': "New Contact",
'email': "[email protected]"
}
submission_data['mine_report_contacts'].append(new_contact)

mine_report_definition = MineReportDefinition.get_all()[0]
submission_data['mine_report_definition_guid'] = str(mine_report_definition.mine_report_definition_guid)

# change status code
mine_report_status_code = MineReportSubmissionStatusCode.get_all()
Expand All @@ -55,11 +125,22 @@ def test_post_additional_mine_report_submission(test_client, db_session, auth_he
post_data = json.loads(post_resp.data.decode())

updated_report = MineReport.find_by_mine_report_guid(str(mine_report.mine_report_guid))
latest_submission = MineReportSubmission.find_latest_by_mine_report_guid(str(mine_report.mine_report_guid)).json()
submissions = updated_report.mine_report_submissions

assert post_resp.data == {}
assert post_resp.status_code == 201
assert len(submissions) == num_submissions + 1

assert len(previous_submission['documents']) + 1 == len(latest_submission['documents'])
assert len(previous_submission['mine_report_contacts']) + 1 == len(latest_submission['mine_report_contacts'])

# fields that should be changed
assert previous_submission['update_timestamp'][:19] == latest_submission['update_timestamp'][:19]
assert previous_submission['update_timestamp'] != latest_submission['update_timestamp']
assert previous_submission['submission_date'] != latest_submission['submission_date']
assert previous_submission['mine_report_submission_status_code'] != latest_submission['mine_report_submission_status_code']
assert previous_submission['description_comment'] != latest_submission['description_comment']

# fields that should not change
assert previous_submission['received_date'] == latest_submission['received_date']
assert previous_submission['create_timestamp'] + '+00:00' == latest_submission['create_timestamp']

Original file line number Diff line number Diff line change
Expand Up @@ -901,20 +901,20 @@ exports[`ReportPage renders view mode properly 1`] = `
</div>
</div>
</div>
<div
class="ant-row ant-row-end"
>
<button
class="ant-btn ant-btn-primary"
type="button"
>
<span>
Edit Report
</span>
</button>
</div>
</form>
</div>
<div
class="ant-row ant-row-end"
>
<button
class="ant-btn ant-btn-primary"
type="button"
>
<span>
Edit Report
</span>
</button>
</div>
</div>
</div>
`;

0 comments on commit d10cabd

Please sign in to comment.