Skip to content

User Endpoints Tests #1

gumityolcu edited this page Nov 23, 2018 · 6 revisions

User Endpoints Tests #1

ATTENTION.

There was an inconsistency between the current User model and endpoints. The current user model has the field "details" whereas the endpoints expect the field "userDetails". I have changed the endpoints according to the data model before testing. These changes are available on the branch fix/backend/user-fix and I worked in this branch throughout the tests.

Tables below show summaries of tests on endpoints. Details are available further below tables for each endpoint.

POST /api/auth/signup:

Test No. Request Response Status Comments
1 Complete request Correct response Test passed. This test is passed by the changes explained in the beginning of the report.
2 Existing e-mail in request Error Test passed.
3 Basic request Correct response Test passed.
4 Empty password in request Error Test passed.

Test1:

Request:

{

"name" : "Test User 1",

"email" : "[email protected]",

"password" : "pass1",

"userDetails" : {

"birth": "1996-11-03T00:00:00.000Z",

"nationality": "Turkish",

"city": "Istanbul"

    }

}

Response:

{

"err": {

    "errors": {

        "name": {

            "message": "Path `name` is required.",

            "name": "ValidatorError",

            "properties": {

                "message": "Path `name` is required.",

                "type": "required",

                "path": "name"

            },

            "kind": "required",

            "path": "name"

        }

    },

    "\_message": "User validation failed",

    "message": "User validation failed: name: Path `name` is required.",

    "name": "ValidationError"

}

}

The current POST /api/auth/signup endpoint doesn't register the name field -which is required- to the object to be saved, database complains.

The endpoint works after handling this issue.

Test2:

Request:

{

"name" : "Test User 1",

"email" : "[email protected]",

"password" : "pass1"

}

Response:

{

"err": {

    "driver": true,

    "name": "MongoError",

    "index": 0,

    "code": 11000,

    "errmsg": "E11000 duplicate key error index: actopus2018.users.$email\_1 dup key: { : \"[email protected]\" }"

}

}

Duplicate email field is tested. Test passed.

Test3:

Request:

{

"name" : "Test User 2",

"email" : "[email protected]",

"password" : "pass1"

}

Response:

{

"followers": [],

"following": [],

"interests": [],

"\_id": "5bf80468be2e9f5045c7d48c",

"name": "Test User 2",

"email": "[email protected]",

"password": "$2b$10$UZixvenkBT5E/HyIQ/dviuJXNM0vhyfIDvC1jQx89ix4T2xQrZssK",

"\_\_v": 0

}

Test passed.

Test4:

Request:

{

"name" : "Test User 2",

"email" : "[email protected]",

"password" : ""

}

Response:

{

"err": {

    "errors": {

        "password": {

            "message": "Path `password` is required.",

            "name": "ValidatorError",

            "properties": {

                "message": "Path `password` is required.",

                "type": "required",

                "path": "password",

                "value": ""

            },

            "kind": "required",

            "path": "password",

            "value": ""

        }

    },

    "\_message": "User validation failed",

    "message": "User validation failed: password: Path `password` is required.",

    "name": "ValidationError"

}

}

Test passed. This test is passed also for empty name and email fields.

GET /users/

Test No. Request Response Status Comments
1 GET /api/users/ Correct response Passed test but needs pagination We need to serve the user object by page using mongoose paginate

The endpoint currently returns all users, we need to use mongoose paginate and add skip and count arguments.

GET /users/:id

Test No. Request Response Status Comments
1 Existing :id details field missing Test failed details fields is missing in response. Counting this as test failed.
2 Nonexisting :id Error Test passed

Test1:

Request: Tested for existing user ID.

Response: Test passed but details field is missing. Not sure if this is intended for some reason or an error

Test2:

Request: Tested for non existing user ID.

Response : Test passed.

POST /users/:id/follow

Test No. Request Response Status Comments
1 Existing id in body Correct response Test passed
2 Already existing id in body Incorrect response Test failed Right now, a user can follow the same user twice.
3 Empty id Error Test passed
4 Empty body Incorrect response Test failed Null value added to followed list
5 Nonexisting :id Error Test passed
6 Nonexisting id in body Error Test passed

Test1:

Request:

{

"id": "5bf80468be2e9f5045c7d48c"

}

Response:

{

"following": [

    "5bf80468be2e9f5045c7d48c"

]

}

Test passed.

Test2:

Request: Same as Test1

Response:

{

"following": [

    "5bf80468be2e9f5045c7d48c",

    "5bf80468be2e9f5045c7d48c"

]

}

Test failed. In this test, a user follows a user that she already follows. I am not sure if we trust frontend that this case is impossible.

Test3:

Request:

{

"id": ""

}

Response: Test passed.

Test4:

Request:

{

}

Response:

{

"following": [

    "5bf80468be2e9f5045c7d48c",

    "5bf80468be2e9f5045c7d48c",

    null

]

}

A null value is added to the array. Test failed.

Test5:

Request: In this test, :id is non existing.

Response: Test passed.

Test6:

Request: Non existing id in request body.

Response: Error. Test passed.

POST /users/:id/unfollow

Test No. Request Response Status Comments
1 Existing id in body {} Test passed Database is correctly updated. For empty response bug, see Test2.
2 Already existing id in body {} Test failed When a user that follows 2 users unfollows one of them, the last version of the following array should be returned.
3 Empty id Error Test passed
4 Empty body {} Test failed Actually nothing happens but we should return an error response.
5 Nonexisting :id Error Test passed
6 Nonexisting id in body Error Test passed

Test1:

Request:

{

"id": "5bf80468be2e9f5045c7d48c"

}

Response:

{

}

Test passed. (Because database is correctly updated. For empty response body error see Test2.)

Test2:

Request: In this case, a user that follows 2 users unfollows one user.

Response:

{

}

Test failed. Response should contain the last version of following field.

Test3:

Request:

{

"id": ""

}

Response: Test passed.

Test4:

Request:

{

}

Response:

{

}

Test failed. Actually nothing changes but we should return an error response.

Test5:

Request: In this test, :id is non existing.

Response: Test passed.

Test6:

Request: Non existing id in request body.

Response: Error. Test passed.

I am assuming addFollower and removeFollower will be used to update the user object being followed.

POST /api/users/:id/addFollower

Test No. Request Response Status Comments
1 Existing id in body {} Test failed Nothing is changed, no error returned.

Test1:

Request:

{

"id": "5bf802ecbe2e9f5045c7d48a"

}

Response:

{

}

Test failed. Nothing is changed, no error returned.

POST /api/users/:id/removeFollower

Test No. Request Response Status Comments
1 Existing id in body {} Test failed Nothing is changed, no error returned.

Test1:

Request:

{

"id": "5bf802ecbe2e9f5045c7d48a"

}

Response:

{

}

Test failed. Nothing is changed, no error returned.

PUT /users/:id

Test No. Request Response Status Comments
1 Full body request Correct response Test passed
2 Try to change id Error Test passed
3 Try to pass invalid id to following array Weird response Test failed

Test1:

Request:

{

"user":{

  "followers": [],

  "following": [

      "5bf80468be2e9f5045c7d48c"

  ],

  "interests": [],

  "\_id": "5bf802ecbe2e9f5045c7d48a",

  "name": "User 1",

  "email": "[email protected]",

  "password": "$2b$10$sqQ2jDSwDf.URvUtR79d..T5Id0yQdvwmOQMs87aG/uWnB8yZoIze",

  "\_\_v": 0

    }

}

Response:

{

"updatedUser": {

    "followers": [],

    "following": [

        "5bf80468be2e9f5045c7d48c"

    ],

    "interests": [],

    "\_id": "5bf802ecbe2e9f5045c7d48a",

    "name": "User 1",

    "email": "[email protected]",

    "password": "$2b$10$sqQ2jDSwDf.URvUtR79d..T5Id0yQdvwmOQMs87aG/uWnB8yZoIze",

    "\_\_v": 0

}

}

Test passed.

Test2:

Request:

{

"user":{

"\_id": "5bf802ecbe2e9f5045c7d48aa"

}

}

Response:

Error. Test passed.

Test3:

Request:

{

"user":{

  "following": [

      "5bf80468be2e9f5045c7d48c","randomstring"

  ]

    }

}

Response:

{

"updatedUser": {

    "followers": [],

    "following": [

        "5bf80468be2e9f5045c7d48c",

        "72616e646f6d737472696e67"

    ],

    "interests": [],

    "\_id": "5bf802ecbe2e9f5045c7d48a",

    "name": "User 1",

    "email": "[email protected]",

    "password": "$2b$10$sqQ2jDSwDf.URvUtR79d..T5Id0yQdvwmOQMs87aG/uWnB8yZoIze",

    "\_\_v": 0

}

}

Test failed. This is just weird.

DELETE /users/:id

Test No. Request Response Status Comments
1 Existing :id Correct Response Test passed
2 Already deleted :id { "deletedUser": null} Test failed We should return error response

Test1:

Request: DELETE /api/users/5bf802ecbe2e9f5045c7d48a

Response :

{

"deletedUser": {

    "followers": [],

    "following": [

        "5bf80468be2e9f5045c7d48c",

        "72616e646f6d737472696e67"

    ],

    "interests": [],

    "\_id": "5bf802ecbe2e9f5045c7d48a",

    "name": "User 1",

    "email": "[email protected]",

    "password": "$2b$10$sqQ2jDSwDf.URvUtR79d..T5Id0yQdvwmOQMs87aG/uWnB8yZoIze",

    "\_\_v": 0

}

}

Test passed.

Test2:

Request: Same as Test1.

Response:

{

"deletedUser": null

}

Test failed.

Clone this wiki locally