adding delays to test scenarios

This commit is contained in:
Silvio Montanari 2013-07-16 19:04:25 +10:00
parent d19d5b43e1
commit 2f3d64d1a6
3 changed files with 20 additions and 25 deletions

View File

@ -42,27 +42,29 @@ define([], function() {
var username = match[1];
var password = match[2];
if (users[username] && password === 'password') {
return {content: authenticationSuccess(username, users[username])};
return {content: authenticationSuccess(username, users[username]), delay: 2};
}
return {returnCode: 401, content: authenticationFailure()};
return {returnCode: 401, content: authenticationFailure(), delay: 3};
});
fakeServer.get(/\/users\/(\w+)/, function(match) {
return {content: {
id: match[1],
username: "mifos",
officeId: 1,
officeName: "Head Office",
firstname: "App",
lastname: "Administrator",
email: "demomfi@mifos.org",
availableRoles: [],
roles: [{
id: 1,
name: "Super user",
description: "This role provides all application permissions."
}]
}};
return {
content: {
id: match[1],
username: "mifos",
officeId: 1,
officeName: "Head Office",
firstname: "App",
lastname: "Administrator",
email: "demomfi@mifos.org",
availableRoles: [],
roles: [{
id: 1,
name: "Super user",
description: "This role provides all application permissions."
}]
}
};
});
}
};

View File

@ -1,10 +1,4 @@
define(["test/scenarios/user_authentication_scenario"], function(authenticationScenario) {
var all_roles = [
{id: 1, name: "Super User", description: "This guy is the suuuper user"},
{id: 2, name: "Branch Manager", description: "This guy is the branch manager"},
{id: 3, name: "Simple User", description: "This guy is just a random joe"},
];
var createUsers = function(number) {
var users = [];
for (var i = 1 ; i <= number; i++) {
@ -24,7 +18,6 @@ define(["test/scenarios/user_authentication_scenario"], function(authenticationS
return {
stubServer: function(fakeServer) {
authenticationScenario.stubServer(fakeServer);
fakeServer.get(/\/roles\/(\w+)/, { content: all_roles });
fakeServer.get(/\/users?.*/, { content: createUsers(25), delay: 3 });
}
};

View File

@ -18,7 +18,7 @@ define(['underscore'], {
httpBackend["when" + method.toUpperCase()](urlRegex).respond(function(method, url, data, headers) {
var responseOptions = getResponseOptions(url.match(urlRegex), data, headers, response);
if (_.isNumber(responseOptions.delay) && responseOptions.delay > 0) {
// a bit of a hack, but this is the only way I figured how to pass delay information
// a bit of a hack, but this is the only way I figured out to pass delay information
// to the $httpBackend decorator (see scenarioTest.js)
responseOptions.headers['MifosX-Scenario-Delay'] = responseOptions.delay * 1000;
}