Closed moses-gangipogu closed 10 years ago
Your Frisby test should look like this:
frisby.create('testAddUser')
.post('http://root:123456@localhost/payCard/Api/User', {
userName : 'newApi',
Password : '123456',
installationId : 1,
cityId : 2,
}), { json: true })
.inspectJSON()
.inspectBody()
.toss()
As for your PHP code, it's best to build an array
and then run the whole array though json_encode
, like this:
$jsonData = array();
// blah blah
$jsonData['status'] = array('StatusMSG' => 'Invalid JSON', 'Code' => 20);
// something else
$jsonData['foo'] = 'bar';
// then ONCE at the end of the script
echo json_encode($jsonData);
thank you sir it has helped me alot
hello sir try this its giving me the 406 HTTP error status
/******this delete rquest works perfectly
/
* Tests -> DELETE delete an existing user based on user User_Id
/
frisby.create('testDeleteUser')
.delete('http://localhost/payCard/Api/User/22')
.expectStatus(200)
.expectHeaderContains('content-type', 'application/json')
.expectJSON('status',{
StatusMSG: "SUCCESS",
Code: '1'
})
.toss();
/**but the request with json data into it is not working and giving 406 error
/**
* Tests -> POST add a new user
*/
frisby.create('testAddUser')
.post('http://localhost/payCard/Api/User', {
userName : 'newApi',
Password : '123456',
installationId : 1,
cityId : 2,
}, { json: true })
.inspectJSON()
.inspectBody()
.expectStatus(200)
.expectHeaderContains('content-type', 'application/json')
.expectJSON('status',{
StatusMSG: "SUCCESS",
Code: '1'
})
.toss();
/***output
2) Frisby Test: testAddUser
[ POST http://localhost/payCard/Api/User ]
Message:
Expected 406 to equal 200.
Stacktrace:
Error: Expected 406 to equal 200.
at null.
3) Frisby Test: testAddUser
[ POST http://localhost/payCard/Api/User ]
Message:
Expected 'text/html; charset=iso-8859-1' to contain 'application/json'.
Stacktrace:
Error: Expected 'text/html; charset=iso-8859-1' to contain 'application/json'.
at null.
4) Frisby Test: testAddUser [ POST http://localhost/payCard/Api/User ] Message: Error: Error parsing JSON string: Unexpected '<' Given: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
An appropriate representation of the requested resource /payCard/Api/User could not be found on this server.
Available variants:Stacktrace: Error: Error parsing JSON string: Unexpected '<' Given: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
An appropriate representation of the requested resource /payCard/Api/User could not be found on this server.
Available variants:at _jsonParse (/var/www/frisby/lib/frisby.js:1150:11)
at null.<anonymous> (/var/www/frisby/lib/frisby.js:606:20)
at null.<anonymous> (/var/www/frisby/lib/frisby.js:1026:43)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
5) Frisby Test: testAddUser [ POST http://localhost/payCard/Api/User ] Message: Error: Error parsing JSON string: Unexpected '<' Given: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
An appropriate representation of the requested resource /payCard/Api/User could not be found on this server.
Available variants:Stacktrace: Error: Error parsing JSON string: Unexpected '<' Given: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
An appropriate representation of the requested resource /payCard/Api/User could not be found on this server.
Available variants:at _jsonParse (/var/www/frisby/lib/frisby.js:1150:11)
at Frisby.<anonymous> (/var/www/frisby/lib/frisby.js:862:30)
at Frisby.<anonymous> (/var/www/frisby/lib/frisby.js:892:8)
at null.<anonymous> (/var/www/frisby/lib/frisby.js:1057:18)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
Finished in 0.141 seconds 5 tests, 19 assertions, 5 failures, 0 skipped
THANK YOU
is there any thing in this line below
frisby.globalSetup({ request: { / //adding this line to the code also give me an 406 HTTP error even in delete request headers:{'Accept': 'application/json'} },/ timeout: (30 * 1000) });
request: { headers:{'Accept': 'application/json, application/x-httpd-php'} },
its run perfect just by adding this line in the globalSetup can u please explain why this problem came and how its solved??????????????
thank you and happy new year
OS = Ubuntu 12.04 LTS i am using .. is this because of this , i tried this same code in windows 7 it runs successfully in it without /**
headers:{'Accept': 'application/json, application/x-httpd-php'}
**/
this line ..but in Ubuntu 12.04 LTS .. its giving 406 error as given in my previous comment without this line's
.. thank you and sorry for my mistakes in English
HTTP 406 means the server can't accept or process the format that you're sending. Try sending the POST request without {json: true}
so it gets transmitted as form-data:
frisby.create('testAddUser')
.post('http://root:123456@localhost/payCard/Api/User', {
userName : 'newApi',
Password : '123456',
installationId : 1,
cityId : 2,
})
.inspectJSON()
.inspectBody()
.toss()
thanks
Why { json: true }
argument hasn't been mentioned in documentation?
Hello I am facing 500 error during delete request into frisby. The code is below please correct me if I have done any wrong..!
var frisby = require('frisby');
//get the current UTC time from this URL: (https://currentmillis.com/) var now = new Date(); var now_utc = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds()) var currentUTCTime = now_utc.getTime() - (now_utc.getTimezoneOffset() * 60000);
frisby.create('Authentication for Delete Request Valid User Name and Password')
.delete('http://example.com',
{
headers:
{
'Accept':'application/json',
'Auth-Username':'abcd',
'X-Application-Key':'xyzzzz',
'Content-Type':'application/json',
'x-locale':'en_US',
'x-microtime':currentUTCTime, //get the current UTC time
'auth-signature': 'example', // Added new auth-signature for new responses
}
}
)
.expectStatus(200)
.toss()
/* * Tests -> POST add a new user / frisby.create('testAddUser') .post('http://localhost/payCard/Api/User', JSON.stringify({ userName : 'newApi', Password : '123456', installationId : 1, cityId : 2, }),{ json: true },{METHOD: 'POST'}) .inspectJSON() .inspectBody()
.expectStatus(200) .expectHeaderContains('content-type', 'application/json') .expectJSON('status',{ StatusMSG: "SUCCESS", Code: '1' })
.toss();
console.log(frisby.create('testAddUser')); console.log(JSON.stringify({ userName : 'newApi', Password : '123456', installationId : 1, cityId : 2, })); // is this code right and how can i check what and how the json data is going to the api
//api code
//output is INVALID JSON