Samagra-Development / user-service

Additional Services related to user management in eSamwad
MIT License
5 stars 22 forks source link

fix: exception handling for fusion auth http requests #21

Closed radhay-samagra closed 2 years ago

radhay-samagra commented 2 years ago

Description

Exception Handling for http req within service and Code refactoring

Changes

How to test

Expected response:

{
    "statusCode": 400,
    "exception": {
        "fieldErrors": {
            "user.email": [
                {
                    "code": "[duplicate]user.email",
                    "message": "A User with email [hekk@gmail.com] already exists."
                }
            ]
        }
    }
}

Sample Request - Update User:

curl --location --request PATCH '{{host-url}}/admin/updateUser/d8308009-37c0-41ad-a60c-7542ec48e73f' \
--header 'Authorization: Bearer  {{token}}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "data": {
        "roleData": {
            "block": "block"
        }
    }
}'

Expected Response:

{
    "responseCode": "OK",
    "params": {
        "responseMsgId": "7665009b-3744-4090-a5ca-fa5f582a3490",
        "msgId": "27f2229b-64e3-45fc-9e52-1466a2eff240",
        "err": "",
        "status": "Success",
        "errMsg": ""
    },
    "ts": "2022-05-12T04:55:12.951Z",
    "id": "44c6599d-34ed-4223-9368-282098d8c2b0",
    "result": {
        "active": true,
        "connectorId": "e3306678-a53a-4964-9040-1c96f36dda72",
        "data": {
            "roleData": {
                "block": "block"
            }
        },
        "id": "d8308009-37c0-41ad-a60c-7542ec48e73f",
        "insertInstant": 1650636317539,
        "lastLoginInstant": 1650636317631,
        "lastUpdateInstant": 1652331313026,
        "passwordChangeRequired": false,
        "passwordLastUpdateInstant": 1650636317616,
        "preferredLanguages": [
            "en"
        ],
        "registrations": [
            {
                "applicationId": "f0ddb3f6-091b-45e4-8c0f-889f89d4f5da",
                "id": "f44b487d-8df8-4105-b706-e63e63183bd6",
                "insertInstant": 1650636317629,
                "lastLoginInstant": 1650636317631,
                "lastUpdateInstant": 1650636317629,
                "preferredLanguages": [
                    "en"
                ],
                "timezone": "Asia/Kolkata",
                "username": "test1234",
                "usernameStatus": "ACTIVE",
                "verified": true
            }
        ],
        "tenantId": "064458d0-dd05-e293-3709-a06cc6ca5ed7",
        "timezone": "Asia/Kolkata",
        "twoFactorDelivery": "None",
        "twoFactorEnabled": false,
        "username": "test1234",
        "usernameStatus": "ACTIVE",
        "verified": true
    }
}

Please consider using the closing keyword if the pull request is proposed to fix an issue already created in the repository (https://help.github.com/articles/closing-issues-using-keywords/)

coveralls commented 2 years ago

Pull Request Test Coverage Report for Build 2311282475


Changes Missing Coverage Covered Lines Changed/Added Lines %
src/admin/admin.controller.ts 3 6 50.0%
src/admin/fusionauth/fusionauth.service.ts 4 19 21.05%
src/admin/admin.service.ts 5 41 12.2%
<!-- Total: 12 66 18.18% -->
Files with Coverage Reduction New Missed Lines %
src/admin/admin.controller.ts 3 48.0%
src/admin/fusionauth/fusionauth.service.ts 3 10.66%
<!-- Total: 6 -->
Totals Coverage Status
Change from base Build 2302572545: -0.3%
Covered Lines: 339
Relevant Lines: 1300

💛 - Coveralls
github-actions[bot] commented 2 years ago

Coverage report

❌ The test suite failed. Please, check the console output for more details.

Report generated by 🧪jest coverage report action from 50f7ee0383c9400d77814590925e021e3c5acff5