Skip to content

Commit

Permalink
added review endpoint testing (bcgov#2838)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulGarewal authored Jul 17, 2024
1 parent c4173d0 commit fd438a7
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions legal-api/tests/unit/resources/v2/test_reviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
)
from http import HTTPStatus

from flask import current_app

from legal_api.services.authz import BASIC_USER, STAFF_ROLE
from tests.unit.services.utils import create_header

Expand Down Expand Up @@ -83,3 +85,44 @@ def test_get_reviews_with_valid_user(app, session, client, jwt):
assert 10 == rv.json.get('limit')
assert 3 == rv.json.get('total')

def test_get_specific_review_with_valid_user(app, session, client, jwt, mocker):
"""Assert specific review object returned for STAFF role."""
review = basic_test_review()
review.save()

base_url = current_app.config.get('LEGAL_API_BASE_URL')

mock_filing = mocker.Mock()
mock_filing.temp_reg = 'BC1234567'
mock_filing.id = 1
mocker.patch('legal_api.models.Filing.find_by_id', return_value=mock_filing)

mocker.patch('legal_api.resources.v2.admin.reviews.current_app.config.get', return_value=base_url)

rv = client.get(f'/api/v2/admin/reviews/{review.id}',
headers=create_header(jwt, [STAFF_ROLE], 'user'))


assert rv.status_code == HTTPStatus.OK
assert rv.json['id'] == review.id
assert 'filingLink' in rv.json
assert rv.json['filingLink'] == f'{base_url}/{mock_filing.temp_reg}/filings/{mock_filing.id}'

def test_get_specific_review_with_invalid_user(app, session, client, jwt):
"""Assert unauthorized for BASIC_USER role when getting a specific review."""
review = basic_test_review()
review.save()

rv = client.get(f'/api/v2/admin/reviews/{review.id}',
headers=create_header(jwt, [BASIC_USER], 'user'))

assert rv.status_code == HTTPStatus.UNAUTHORIZED

def test_get_nonexistent_review(app, session, client, jwt):
"""Assert not found for non-existent review ID."""
rv = client.get('/api/v2/admin/reviews/99999',
headers=create_header(jwt, [STAFF_ROLE], 'user'))

assert rv.status_code == HTTPStatus.NOT_FOUND
assert 'message' in rv.json
assert rv.json['message'] == 'Review not found.'

0 comments on commit fd438a7

Please sign in to comment.