Skip to content

Commit

Permalink
14066 - Provide certifiedBy, id, created on true affiliation response (
Browse files Browse the repository at this point in the history
…#2170)

* Draft for adding a certified_by_name field for affiliations.

* Unit test and changes for certified_by_name.

* Typo fixes.

* Fix broken linters.

* Add certifiedByName, id, created to true Affiliation response.

* Fix example

* Make unit test a bit better.
  • Loading branch information
seeker25 authored Dec 6, 2022
1 parent ce74321 commit 195e8ae
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 11 deletions.
1 change: 1 addition & 0 deletions auth-api/src/auth_api/schemas/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ class Meta(BaseSchema.Meta): # pylint: disable=too-few-public-methods
contacts = fields.Pluck('ContactLinkSchema', 'contact', many=True)
corp_type = fields.Nested(CorpTypeSchema, many=False)
corp_sub_type = fields.Nested(CorpTypeSchema, many=False)
affiliations = fields.Nested('AffiliationSchema', many=True, only=('id', 'created', 'certified_by_name'))
59 changes: 52 additions & 7 deletions auth-api/src/auth_api/schemas/schemas/business.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
"examples": [
{
"affiliations": [
1
{
"id": 1,
"certifiedByName": "Leonard, Rodney",
"created": "2022-01-01"
}
],
"businessIdentifier": "CP0002103",
"businessNumber": "791861078BC0001",
Expand Down Expand Up @@ -43,7 +47,11 @@
"default": [],
"examples": [
[
1
{
"id": 1,
"certifiedByName": "Leonard, Rodney",
"created": "2022-01-01"
}
]
],
"additionalItems": true,
Expand All @@ -52,12 +60,49 @@
"anyOf": [
{
"$id": "#/properties/affiliations/items/anyOf/0",
"type": "integer",
"type": "object",
"title": "The first anyOf schema",
"default": 0,
"default": {},
"examples": [
1
]
{
"id": 1,
"certifiedByName": "Leonard, Rodney",
"created": "2022-01-01"
}
],
"required": [
"id",
"created"
],
"properties": {
"id": {
"$id": "#/properties/affiliations/items/anyOf/0/properties/id",
"type": "integer",
"title": "id",
"default": 0,
"examples": [
1
]
},
"certifiedByName": {
"$id": "#/properties/affiliations/items/anyOf/0/properties/certifiedByName",
"type": "string",
"title": "Certified By Name",
"default": "",
"examples": [
"Leonard, Rodney"
]
},
"created": {
"$id": "#/properties/affiliations/items/anyOf/0/properties/created",
"type": "string",
"title": "Created",
"default": "",
"examples": [
"2020-11-06T19:15:21.347010+00:00"
]
}
}
}
]
}
Expand Down Expand Up @@ -174,4 +219,4 @@
}
},
"additionalProperties": true
}
}
2 changes: 1 addition & 1 deletion auth-api/src/auth_api/services/affiliation.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def find_affiliations_by_org_id(org_id):
"""Return business affiliations for the org."""
# Accomplished in service instead of model (easier to avoid circular reference issues).
subquery = db.session.query(
AffiliationModel.entity_id, AffiliationModel.created) \
AffiliationModel.entity_id, AffiliationModel.created, AffiliationModel.certified_by_name) \
.join(Entity).filter(AffiliationModel.org_id == org_id) \
.subquery()

Expand Down
2 changes: 1 addition & 1 deletion auth-api/tests/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ services:
image: stoplight/prism:3.3.0
command: >
mock -p 4010 --host 0.0.0.0
https://raw.githubusercontent.com/bcgov/sbc-pay/main/docs/docs/api_contract/pay-api-1.0.2.yaml
https://raw.githubusercontent.com/bcgov/sbc-pay/main/docs/docs/api_contract/pay-api-1.0.3.yaml
minio:
image: 'bitnami/minio:2022.2.5'
Expand Down
11 changes: 9 additions & 2 deletions auth-api/tests/unit/api/test_org.py
Original file line number Diff line number Diff line change
Expand Up @@ -1302,12 +1302,19 @@ def test_add_new_business_affiliation_staff(client, jwt, session, keycloak_mock,
data=json.dumps(TestAffliationInfo.new_business_affiliation), content_type='application/json')
assert rv.status_code == http_status.HTTP_201_CREATED
assert schema_utils.validate(rv.json, 'affiliation_response')[0]
certified_by_name = TestAffliationInfo.new_business_affiliation['certifiedByName']

dictionary = json.loads(rv.data)
assert dictionary['organization']['id'] == org_id
assert dictionary['certifiedByName'] == TestAffliationInfo.new_business_affiliation['certifiedByName']
assert dictionary['certifiedByName'] == certified_by_name

# Future ticket, have this show up on the GET side.
rv = client.get('/api/v1/orgs/{}/affiliations'.format(org_id), headers=headers)
assert rv.status_code == http_status.HTTP_200_OK

assert schema_utils.validate(rv.json, 'affiliations_response')[0]
affiliations = json.loads(rv.data)

assert affiliations['entities'][0]['affiliations'][0]['certifiedByName'] == certified_by_name


def test_get_affiliations(client, jwt, session, keycloak_mock): # pylint:disable=unused-argument
Expand Down

0 comments on commit 195e8ae

Please sign in to comment.