bunq / postman

Postman collection and environments
45 stars 19 forks source link

Fixed 'Add a session' for 'UserCompany' #15

Closed ricardobalk closed 1 year ago

ricardobalk commented 3 years ago

When adding a session for a company user, the user_id and session_token environment variables were not updated due to failed tests.

This small change fixes it by first determining if we are dealing with a regular user or a company user, before doing tests and updating Postman's env vars.


Steps to reproduce the issue


Steps I've taken to fix it

I changed the following code (in the Tests section of 'Add a session'):

pm.test("Response has Id, Token and UserPerson. We are setting user_id and session_token in environment variables.", () => {
    var all_response = parse_all_response();
    pm.expect(all_response.Id).to.have.lengthOf(1);
    pm.expect(all_response.Token).to.have.lengthOf(1);
    pm.expect(all_response.UserPerson).to.have.lengthOf(1);

    var user_id = all_response.UserPerson[0].id;
    var session_token = all_response.Token[0].token;
    pm.expect(user_id).to.be.a('number');
    pm.expect(session_token).to.be.a('string');

    pm.environment.set("user_id", user_id);
    pm.environment.set("session_token", session_token);
});

To this:

pm.test("Response has Id, Token and UserPerson. We are setting user_id and session_token in environment variables.", () => {
    var all_response = parse_all_response();
    pm.expect(all_response.Id).to.have.lengthOf(1);
    pm.expect(all_response.Token).to.have.lengthOf(1);
    all_response.UserPerson != null && pm.expect(all_response.UserPerson).to.have.lengthOf(1) || pm.expect(all_response.UserCompany).to.have.lengthOf(1);

    var user_id = (all_response.UserPerson != null ? all_response.UserPerson[0].id : all_response.UserCompany[0].id)
    var session_token = all_response.Token[0].token;
    pm.expect(user_id).to.be.a('number');
    pm.expect(session_token).to.be.a('string');

    pm.environment.set("user_id", user_id);
    pm.environment.set("session_token", session_token);
});

Now it works again! 🌈 👍🏼

ricardobalk commented 3 years ago

Maybe I should also update the line:

Response has Id, Token and UserPerson. (...)

to

Response has Id, Token and UserPerson or UserCompany. (...)

Give me a sec, I'll add a new commit to my repository. Will show up here as well.

ricardobalk commented 3 years ago

Done. 👍🏼