How do I get the right JSON body for Frisby.js tests when I connect to a play framework API?
For example, normally I call jquery ajax with dataType, contentType and JSON.stringify on my json object:
this.doAjax('/addsignature', success, error, JSON.stringify({ name: "app3", modulus: "mymodulus", exponent: "myexp"}), 'POST', 'json', 'application/json');
My play request().body() is:
DefaultRequestBody(None,None,None,Some({"name":"app3","modulus":"mymodulus","exponent":"myexp"}),None,None,false)
Then I can get it asJson().
In frisby I can't seem to do this combination of things:
frisby.create('AddSig')
.post(addSigURL(),
JSON.stringify({
name: 'app3',
modulus: 'mymodulus',
exponent: 'myexp'}),
{json: true},
{ headers: { 'Content-Type': 'application/json' }}
)
.addHeader(utils.AUTH_HEADER, utils.getAuth(userId, userEmail, userCommonName))
.inspectBody()
.expectStatus(200)
.afterJSON(function(jsonResponse) {
checkSignature();
})
.toss()
I get:
DefaultRequestBody(Some(Map()),None,None,None,None,None,false)
If I remove JSON.stringify I get an invalid JSON:
DefaultRequestBody(None,None,None,Some("{\"name\":\"app3\",\"modulus\":\"mymodulus\",\"exponent\":\"myexp\"}"),None,None,false)
Which .asJson() doesn't work for.
Aucun commentaire:
Enregistrer un commentaire