From 195e8aef2fba4116bc4b86530ffc0de52b5e7db5 Mon Sep 17 00:00:00 2001 From: Travis Semple Date: Tue, 6 Dec 2022 10:57:27 -0800 Subject: [PATCH] 14066 - Provide certifiedBy, id, created on true affiliation response (#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. --- auth-api/src/auth_api/schemas/entity.py | 1 + .../auth_api/schemas/schemas/business.json | 59 ++++++++++++++++--- auth-api/src/auth_api/services/affiliation.py | 2 +- auth-api/tests/docker/docker-compose.yml | 2 +- auth-api/tests/unit/api/test_org.py | 11 +++- 5 files changed, 64 insertions(+), 11 deletions(-) diff --git a/auth-api/src/auth_api/schemas/entity.py b/auth-api/src/auth_api/schemas/entity.py index be8439437..1cdb6ce45 100644 --- a/auth-api/src/auth_api/schemas/entity.py +++ b/auth-api/src/auth_api/schemas/entity.py @@ -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')) diff --git a/auth-api/src/auth_api/schemas/schemas/business.json b/auth-api/src/auth_api/schemas/schemas/business.json index 61384c130..81c9ae273 100644 --- a/auth-api/src/auth_api/schemas/schemas/business.json +++ b/auth-api/src/auth_api/schemas/schemas/business.json @@ -8,7 +8,11 @@ "examples": [ { "affiliations": [ - 1 + { + "id": 1, + "certifiedByName": "Leonard, Rodney", + "created": "2022-01-01" + } ], "businessIdentifier": "CP0002103", "businessNumber": "791861078BC0001", @@ -43,7 +47,11 @@ "default": [], "examples": [ [ - 1 + { + "id": 1, + "certifiedByName": "Leonard, Rodney", + "created": "2022-01-01" + } ] ], "additionalItems": true, @@ -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" + ] + } + } } ] } @@ -174,4 +219,4 @@ } }, "additionalProperties": true -} \ No newline at end of file +} diff --git a/auth-api/src/auth_api/services/affiliation.py b/auth-api/src/auth_api/services/affiliation.py index 78ff80499..87db3543f 100644 --- a/auth-api/src/auth_api/services/affiliation.py +++ b/auth-api/src/auth_api/services/affiliation.py @@ -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() diff --git a/auth-api/tests/docker/docker-compose.yml b/auth-api/tests/docker/docker-compose.yml index bcd76f0af..da669cedc 100755 --- a/auth-api/tests/docker/docker-compose.yml +++ b/auth-api/tests/docker/docker-compose.yml @@ -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' diff --git a/auth-api/tests/unit/api/test_org.py b/auth-api/tests/unit/api/test_org.py index 855120b94..da594b0ef 100644 --- a/auth-api/tests/unit/api/test_org.py +++ b/auth-api/tests/unit/api/test_org.py @@ -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