vendredi 20 mai 2016

Verifying data being posted from frisby test in Node backend

I'd like to check if the data is actually posting to my backend successfully via my Frisby test. I can see in the console the URL calls successfully and the response code is 201. However, when I print req.body, it's empty.

Jasmine/Frisby Tests

describe("POST /createSecret", function() {

  it('returns a status code of 201', function(done) {

    //Send a POST req. to create secret data
    frisby.create('GET JSON data from an endpoint')
      .post('http://localhost:3000/createSecret', {

            'secret_name'       : barbicanRequestData.secret_name,
            'expiration'        : barbicanRequestData.expiration,
            'algorithm'         : barbicanRequestData.algorithm,
            'bit_length'        : barbicanRequestData.bit_length,
            'mode'              : barbicanRequestData.mode,
            'payload'           : barbicanRequestData.payload,
            'content_type'      : barbicanRequestData.content_type,
            'content_encoding'  : barbicanRequestData.content_encoding,
            'secret_type'       : barbicanRequestData.secret_type
      })
      .expectStatus(201)
      .expectHeader('Content-Type', 'application/json; charset=utf-8')
      .expectJSON({ 'secret_ref': 'Secret was successfully created!' })
    .toss();
    done();
  });
});

Backend

  else if (req.method == "POST") {

    console.log("Request is POST");

    console.log(res.body);

    //Test a POST response for creating a secret using the Barbican API
    res.status(201).send({
      'secret_ref': "Secret was successfully created!",
      'Content-Type': 'application/json; charset=utf-8'
    });
  }

Aucun commentaire:

Enregistrer un commentaire