Skip to content

Instantly share code, notes, and snippets.

@codeami
Created November 30, 2016 10:14
Show Gist options
  • Save codeami/3ad59c0f98fff6414f9d35dcc7686ff5 to your computer and use it in GitHub Desktop.
Save codeami/3ad59c0f98fff6414f9d35dcc7686ff5 to your computer and use it in GitHub Desktop.
Jasmine Test needs to know when all API requests are done. (APIs are using request-promise and tj/co generators)
//Jasmine test // AUT = app under test // HCS = some resouce to be created multiple times to test pagination
// defaultData has 11 defaultHCSID in array
describe ("Test: Create 11 HCSes to test pagination", function () {
beforeAll(function (done) {
AUT.api.defaultHCS.create(defaultData).then(()=> {
done();
//setTimeout(function () {done();}, AUT.API_TIMEOUT);
});
});
..
rest of the test.
..
//appointments defaultHCS Api.js
var co = require('co');
var _ = require('lodash');
var rp = require('request-promise');
var urlLogin ={url:"<URL>", body:"<body>" method: 'POST', headers: {"Content-Type": "application/json"}, json: true}
var urlDefaultHCSSave ={url:"<URL>", body:"<body>" method: 'POST', headers: {"Content-Type": "application/json"}, json: true}
exports.create = function (customTestData) {
return co(function*() {
var response, token, testData;
testData = customTestData || defaultTestData;
response = yield rp(urlLogin);
urlDefaultHCSSave.headers["x-auth-token"] = response.token;
var size= _.size(testData.defaultHCSID);
process.stdout.write("API DEFAULT HCS Create. Size: " + size + " ");
var total = 0;
testData.defaultHCSID.forEach(function (item,i){
return co(function* () {
response = yield rp(defaultHCSSave); //parsedBody
total+=1;
if (total === size){ process.stdout.write("All Done\n"); }
}).catch(function (err) {console.error(err.stack); })
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment