diff --git a/notificationapi_python_server_sdk/notificationapi.py b/notificationapi_python_server_sdk/notificationapi.py index 20f1f4b..e058be5 100644 --- a/notificationapi_python_server_sdk/notificationapi.py +++ b/notificationapi_python_server_sdk/notificationapi.py @@ -112,10 +112,11 @@ async def query_logs(params): response = await request("POST", "logs/query", params) return response + async def update_in_app_notification(user_id, params): - + hashed_user_id = hashlib.sha256((__client_secret + user_id).encode()).digest() hashed_user_id_base64 = base64.b64encode(hashed_user_id).decode() custom_auth = 'Basic ' + base64.b64encode(f'{__client_id}:{user_id}:{hashed_user_id_base64}'.encode()).decode() - + return await request('PATCH', f'users/{user_id}/notifications/INAPP_WEB', params, custom_auth) diff --git a/tests/test_notificationapi_update_in_app_notification.py b/tests/test_notificationapi_update_in_app_notification.py index 4692eb3..20a38bb 100644 --- a/tests/test_notificationapi_update_in_app_notification.py +++ b/tests/test_notificationapi_update_in_app_notification.py @@ -14,7 +14,6 @@ client_secret = "client_secret" user_id = "userId" - api_paths = { "update_in_app_notification": f"https://api.notificationapi.com/{client_id}/users/{urllib.parse.quote(user_id)}/notifications/INAPP_WEB", } @@ -26,16 +25,17 @@ [ ( "update_in_app_notification", - (user_id, - { - "trackingIds": ["sampleTrackingId"], - "opened": "1970-01-01T00:00:00.000Z", - "clicked": "1970-01-01T00:00:00.000Z", - "archived": "1970-01-01T00:00:00.000Z", - "actioned1": "1970-01-01T00:00:00.000Z", - "actioned2": "1970-01-01T00:00:00.000Z", - "reply": {"date": "1970-01-01T00:00:00.000Z", "message": "nice!"} - } + ( + user_id, + { + "trackingIds": ["sampleTrackingId"], + "opened": "1970-01-01T00:00:00.000Z", + "clicked": "1970-01-01T00:00:00.000Z", + "archived": "1970-01-01T00:00:00.000Z", + "actioned1": "1970-01-01T00:00:00.000Z", + "actioned2": "1970-01-01T00:00:00.000Z", + "reply": {"date": "1970-01-01T00:00:00.000Z", "message": "nice!"} + } ), ), ], @@ -52,16 +52,17 @@ async def test_makes_one_patch_api_call(respx_mock, func, params): [ ( "update_in_app_notification", - (user_id, - { - "trackingIds": ["sampleTrackingId"], - "opened": "1970-01-01T00:00:00.000Z", - "clicked": "1970-01-01T00:00:00.000Z", - "archived": "1970-01-01T00:00:00.000Z", - "actioned1": "1970-01-01T00:00:00.000Z", - "actioned2": "1970-01-01T00:00:00.000Z", - "reply": {"date": "1970-01-01T00:00:00.000Z", "message": "nice!"} - } + ( + user_id, + { + "trackingIds": ["sampleTrackingId"], + "opened": "1970-01-01T00:00:00.000Z", + "clicked": "1970-01-01T00:00:00.000Z", + "archived": "1970-01-01T00:00:00.000Z", + "actioned1": "1970-01-01T00:00:00.000Z", + "actioned2": "1970-01-01T00:00:00.000Z", + "reply": {"date": "1970-01-01T00:00:00.000Z", "message": "nice!"} + } ), ), ], @@ -84,16 +85,17 @@ async def test_uses_custom_authorization(respx_mock, func, params): [ ( "update_in_app_notification", - (user_id, - { - "trackingIds": ["sampleTrackingId"], - "opened": "1970-01-01T00:00:00.000Z", - "clicked": "1970-01-01T00:00:00.000Z", - "archived": "1970-01-01T00:00:00.000Z", - "actioned1": "1970-01-01T00:00:00.000Z", - "actioned2": "1970-01-01T00:00:00.000Z", - "reply": {"date": "1970-01-01T00:00:00.000Z", "message": "nice!"} - } + ( + user_id, + { + "trackingIds": ["sampleTrackingId"], + "opened": "1970-01-01T00:00:00.000Z", + "clicked": "1970-01-01T00:00:00.000Z", + "archived": "1970-01-01T00:00:00.000Z", + "actioned1": "1970-01-01T00:00:00.000Z", + "actioned2": "1970-01-01T00:00:00.000Z", + "reply": {"date": "1970-01-01T00:00:00.000Z", "message": "nice!"} + } ), ), ], @@ -104,15 +106,14 @@ async def test_passes_data_as_json_body(respx_mock, func, params): await getattr(notificationapi, func)(*params) sent_data = json.loads(route.calls.last.request.content) assert sent_data == { - "trackingIds": ["sampleTrackingId"], - "opened": "1970-01-01T00:00:00.000Z", - "clicked": "1970-01-01T00:00:00.000Z", - "archived": "1970-01-01T00:00:00.000Z", - "actioned1": "1970-01-01T00:00:00.000Z", - "actioned2": "1970-01-01T00:00:00.000Z", - "reply": {"date": "1970-01-01T00:00:00.000Z", "message": "nice!"} - - } + "trackingIds": ["sampleTrackingId"], + "opened": "1970-01-01T00:00:00.000Z", + "clicked": "1970-01-01T00:00:00.000Z", + "archived": "1970-01-01T00:00:00.000Z", + "actioned1": "1970-01-01T00:00:00.000Z", + "actioned2": "1970-01-01T00:00:00.000Z", + "reply": {"date": "1970-01-01T00:00:00.000Z", "message": "nice!"} + } @pytest.mark.parametrize( @@ -120,16 +121,17 @@ async def test_passes_data_as_json_body(respx_mock, func, params): [ ( "update_in_app_notification", - (user_id, - { - "trackingIds": ["sampleTrackingId"], - "opened": "1970-01-01T00:00:00.000Z", - "clicked": "1970-01-01T00:00:00.000Z", - "archived": "1970-01-01T00:00:00.000Z", - "actioned1": "1970-01-01T00:00:00.000Z", - "actioned2": "1970-01-01T00:00:00.000Z", - "reply": {"date": "1970-01-01T00:00:00.000Z", "message": "nice!"} - } + ( + user_id, + { + "trackingIds": ["sampleTrackingId"], + "opened": "1970-01-01T00:00:00.000Z", + "clicked": "1970-01-01T00:00:00.000Z", + "archived": "1970-01-01T00:00:00.000Z", + "actioned1": "1970-01-01T00:00:00.000Z", + "actioned2": "1970-01-01T00:00:00.000Z", + "reply": {"date": "1970-01-01T00:00:00.000Z", "message": "nice!"} + } ), ), ],