I am testing restful api's using restler and jasmine nodejs modules . I have created test files to test a single api call and test group of api calls that need input from each other . How can I provide the feedback / output from one such api call to another api call using proper jasmine describe - it - expect block format . If I try put verifyOtp function in another it-block after getPhoneOtp then it don't execute after success of getting the OTP and thus fails . Right now I am reading the outputs in the console only and not able to use jasmine expect function since I am not able to include verifyOtp function in a it-block . Any suggestions would be appreciated . Here is the code .
var restler = require('restler');
var fs = require('fs');
var colors = require('colors');
var util = require('util');
var config = require('./config.js') ;
var baseUrl = config.baseUrl ;
describe("LEC phone api's tests", function () {
var _token;
var phone = Math.round(Math.random() * 1000000000);
var otp;
console.log("Test started on "+baseUrl) ;
function verifyOtp(otpPassed) {
var success = 0 ;
restler.post(baseUrl + "phone/verifyotp", {
data: {
_token: _token,
phoneNumber: phone,
otp: otpPassed
},
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
}).on("success", function (data) {
success = 1 ;
console.log(colors.blue("Success of verify otp")) ;
console.log(data);
var userInfo = {
firstName: "John",
lastName: "Doe",
description: "I'm a getting used for testing .",
zipCode: "71151",
street: "Testing avenue",
city: "San Fransisco",
state: "California",
email: "john@doe.com",
image: ""
};
}).on("complete", function (data) {
if(!success)
console.log(colors.red(util.inspect(data))) ;
});
};
it("should get the token", function () {
var success = 0 ;
restler.get(baseUrl + "/basic/token")
.on("success", function (data) {
success = 1;
console.log(colors.blue("Success of get the Token")) ;
console.log(data);
_token = data.token;
}).on("complete", function (data) {
if(!success)
console.log(colors.red(util.inspect(data))) ;
});
});
it("should get the OTP", function () {
var success = 0 ;
restler.post(baseUrl + "phone/getphoneotp", {
data: {
_token: _token,
phoneNumber: phone
},
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
}).on("success", function (data) {
success = 1;
console.log(colors.blue("Success of get the OTP")) ;
console.log(data);
otp = data.otp;
verifyOtp(otp);
}).on("complete", function (data) {
if(!success)
console.log(colors.red(util.inspect(data))) ; });
});
});