Created
August 2, 2016 14:45
-
-
Save pedroadaodev/e4fbbb1e952924042e1a7e761c5d332d to your computer and use it in GitHub Desktop.
Use this script if you use qUnit v2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
//name of the Unit Test Module | |
QUnit.module('Participations'); | |
var indexOn = 0; | |
//object array with the webservices to call | |
var apiCalls = [ | |
{ | |
name: "POST User", | |
numberOfTests: 1, | |
url: '/api/PastimeApi/', | |
type: 'POST', | |
data: { | |
'FacebookId': '12345678901231', | |
'Name': 'dummy', | |
'Age': '12', | |
'Beach': 'dummy', | |
'Email': 'dummy', | |
'MobilePhone': 'dummy', | |
'Sub12': 'false', | |
'Aux1': '', | |
'Aux2': '', | |
'Aux3': '', | |
}, | |
callbackSucess: function (assert, result) { | |
assert.ok(true, 'OK - user saved'); //my assert | |
}, | |
callbackError: function (assert, result) { | |
assert.ok(false, 'error'); //my assert | |
} | |
} | |
, | |
{ | |
name: "POST video", | |
numberOfTests: 1, | |
url: '/api/PastimeVideoApi/', | |
type: 'POST', | |
data: { | |
'FacebookId': '1234567890123', | |
'VideoUrl': 'v4v5b5n76', | |
'Aux1': '', | |
'Aux2': '', | |
'Aux3': '', | |
}, | |
callbackSucess: function (assert, result) { | |
assert.ok(true, 'OK - user saved'); | |
}, | |
callbackError: function (assert, result) { | |
assert.ok(false, 'error'); //my assert | |
} | |
} | |
]; | |
//Call all webservices | |
var next = function () { | |
if (indexOn < apiCalls.length) { | |
var apiCall = apiCalls[indexOn]; | |
QUnit.test('call: ' + apiCall.name, function (assert) { | |
assert.expect(apiCall.numberOfTests); | |
var thenable = new Promise(function (resolve, reject) { | |
var dataStringify = apiCall.data; | |
if (apiCall.type != 'GET' && !$.isEmptyObject(apiCall.data)) { | |
dataStringify = JSON.stringify(apiCall.data); | |
} | |
$.ajax({ | |
url: apiCall.url, | |
dataType: 'json', | |
contentType: 'application/json', | |
data: dataStringify, | |
type: apiCall.type, | |
success: function (result) { | |
resolve("result"); | |
apiCall.callbackSucess(assert, result); | |
next(); //call next webservice | |
}, | |
error: function (result) { | |
resolve("result"); | |
apiCall.callbackError(assert, result); | |
next(); //call next webservice | |
} | |
}); | |
}); | |
return thenable; | |
}); | |
indexOn++; | |
} | |
}; | |
next(); //start the webservice calls | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment