Skip to content

Chai-http [POST] does not allow to send an Array on bodyParameters (API Testing & Javascript) #290

Open
@rtfx-glob

Description

@rtfx-glob

Chai-http version: "4.3.0"

I have found this kind of weird behavior in my test case.

Let's recreate the scenario

I do have 2 classes:

API.ts -> which refers to the class where I'm creating the requests.

API-op.ts -> which refers to the class where I'm validating through asserts, expects etc.

Context: There are some dependencies between the methods. I mean, If I want to publish I need first an ID, that ID becomes from a method called postCreateId. Once I have the response body, I'm using that ID to be passed on my postPublishArt method

So.

I have this method on API.ts

public postPublishArt(token: any, Id: any) {
    return chai.request(URLBASE)
        .post(URI)
        .set({ Authorization: "Bearer " + token })
        .send({
            id: Id
        })
}

So, I'm calling that method on API-op.ts like this:

public async postPublish() {
        var accessToken = undefined;
        return this.chaiClass.generateToken()
            .then(async (response) => {
                accessToken = response.body.AccessToken;
                return this.chaiArt.postCreateId(accessToken)
                    .then(async (response) => {
                        let id = response.body.id;
                        let array: Array<string> = [id];
                        return this.chaiArt.postPublishArt(accessToken, array)
                            .then(async (response) => {
                                expect(response).to.have.status(201);
                                return response;
                            }).catch(err => {
                                return console.log('Failure', err);
                            });
                    });
            });
    }

on Postman the bodyparameter needs to be like this:

{
      "ids": 
          [
"d2164919-730a-5fe2-924d-5c14cf36e38c"
]
      
}

Pay attention at square brackets because the body parameter requires that ids keys MUST BE array.

What is the error: Like I need just ONE id passed as an array, once I convert that variable and it is sent to the POST method. the POST method is showing up this error:

text:'{"errors":[{"code":"unexpected-exception","details":{"statusCode":500,"error":"invalid input syntax for type timestamp: \\"0NaN-NaN-NaNTNaN:NaN:NaN.NaN+NaN:NaN\\""}}]}'

I think that issue is about chai-http when you send a POST with ARRAY but just passing one parameter.

Let me know if I'm wrong

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions