mirror of
https://github.com/openMF/community-app.git
synced 2026-02-06 13:51:55 +00:00
created end2end user authentication test scenario
This commit is contained in:
parent
f2809108de
commit
bca092a385
22
js/loader.js
22
js/loader.js
@ -1,28 +1,24 @@
|
||||
(function() {
|
||||
require.config({
|
||||
paths: {
|
||||
angular: '../lib/angular/angular',
|
||||
underscore: '../lib/underscore/underscore',
|
||||
test: '../test/functional'
|
||||
'angular': '../lib/angular/angular',
|
||||
'angular-mocks': '../lib/angular/angular-mocks',
|
||||
'underscore': '../lib/underscore/underscore',
|
||||
'sinon': '../lib/sinon/sinon-1.7.1',
|
||||
'test': '../test/functional'
|
||||
},
|
||||
shim: {
|
||||
angular: {
|
||||
'angular': {
|
||||
exports: 'angular'
|
||||
},
|
||||
underscore: {
|
||||
exports: '_'
|
||||
},
|
||||
mifosX: {
|
||||
'mifosX': {
|
||||
deps: ['angular']
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
require(['mifosXComponents', 'underscore', 'mifosX'], function(components) {
|
||||
var dependencies = [
|
||||
'routes',
|
||||
'test/test_scenario_loader'
|
||||
];
|
||||
require(['mifosXComponents', 'mifosX', 'underscore'], function(components) {
|
||||
var dependencies = ['routes', 'test/test_scenario_loader'];
|
||||
dependencies = _.reduce(_.keys(components), function(list, group) {
|
||||
return list.concat(_.map(components[group], function(name) { return group + "/" + name; }));
|
||||
}, dependencies);
|
||||
|
||||
@ -1,42 +1,18 @@
|
||||
(function(module) {
|
||||
mifosX.services = _.extend(module, {
|
||||
AuthenticationService: function(scope, http) {
|
||||
var onSuccess = function(response) {
|
||||
scope.$broadcast("UserAuthenticationSuccessEvent", response.data);
|
||||
var onSuccess = function(data) {
|
||||
scope.$broadcast("UserAuthenticationSuccessEvent", data);
|
||||
};
|
||||
|
||||
var onFailure = function(response) {
|
||||
scope.$broadcast("UserAuthenticationFailureEvent", response.data);
|
||||
var onFailure = function(data) {
|
||||
scope.$broadcast("UserAuthenticationFailureEvent", data);
|
||||
};
|
||||
|
||||
this.authenticateWithUsernamePassword = function(credentials) {
|
||||
//temporary stub authentication
|
||||
var roles = {
|
||||
mifos: [{id: 1, name: "Super User"}],
|
||||
joe: [{id: 2, name: "Branch Manager"}],
|
||||
jack: [{id: 3, name: "Funder"}]
|
||||
};
|
||||
if (credentials.password === 'password') {
|
||||
var role = roles[credentials.username];
|
||||
if (role) {
|
||||
onSuccess({
|
||||
data: {
|
||||
username: credentials.username,
|
||||
userId: 1,
|
||||
base64EncodedAuthenticationKey: "bWlmb3M6cGFzc3dvcmQ=",
|
||||
authenticated: true,
|
||||
roles: role,
|
||||
permissions: [ "ALL_FUNCTIONS" ]
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
onFailure({});
|
||||
}
|
||||
|
||||
// http.post("/authentication?username=" + credentials.username + "&password=" + credentials.password)
|
||||
// .success(onSuccess)
|
||||
// .error(onFailure);
|
||||
http.post("/authentication?username=" + credentials.username + "&password=" + credentials.password)
|
||||
.success(onSuccess)
|
||||
.error(onFailure);
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
1788
lib/angular/angular-mocks.js
vendored
Normal file
1788
lib/angular/angular-mocks.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,14 +0,0 @@
|
||||
(function(testModule) {
|
||||
var _fakeServer;
|
||||
mifosX.test = _.extend(testModule, {
|
||||
SinonFakeServer: function() {
|
||||
|
||||
},
|
||||
getFakeServer: function() {
|
||||
if (!_fakeServer) {
|
||||
_fakeServer = new mifosX.test.SinonFakeServer();
|
||||
}
|
||||
return _fakeServer;
|
||||
}
|
||||
});
|
||||
}(mifosX.test || {}));
|
||||
53
test/functional/scenarios/user_authentication_scenario.js
Normal file
53
test/functional/scenarios/user_authentication_scenario.js
Normal file
@ -0,0 +1,53 @@
|
||||
define([], function() {
|
||||
var users = {
|
||||
mifos: {userId: 1, roles: [{id: 1, name: "Super User"}]},
|
||||
joe: {userId: 2, roles: [{id: 2, name: "Branch Manager"}]},
|
||||
jack: {userId: 3, roles: [{id: 3, name: "Funder"}]}
|
||||
};
|
||||
|
||||
var authenticationSuccess = function(username, userDetails) {
|
||||
return {
|
||||
username: username,
|
||||
userId: userDetails.userId,
|
||||
base64EncodedAuthenticationKey: "bWlmb3M6cGFzc3dvcmQ=",
|
||||
authenticated: true,
|
||||
staffId: 1,
|
||||
staffDisplayName: "Director, Program",
|
||||
organisationalRole: {
|
||||
id: 100,
|
||||
code: "staffOrganisationalRoleType.programDirector",
|
||||
value: "Program Director"
|
||||
},
|
||||
roles: userDetails.roles,
|
||||
permissions: [
|
||||
"ALL_FUNCTIONS"
|
||||
]
|
||||
};
|
||||
};
|
||||
|
||||
var authenticationFailure = function() {
|
||||
return {
|
||||
developerMessage: "Invalid authentication details were passed in api request.",
|
||||
developerDocLink: "https://github.com/openMF/mifosx/wiki/HTTP-API-Error-codes",
|
||||
httpStatusCode: "401",
|
||||
defaultUserMessage: "Unauthenticated. Please login.",
|
||||
userMessageGlobalisationCode: "error.msg.not.authenticated",
|
||||
errors: []
|
||||
};
|
||||
};
|
||||
|
||||
return {
|
||||
stubServer: function(httpBackend) {
|
||||
var URL_REGEX = /\/authentication\?username=(\w+)&password=(.+)/;
|
||||
httpBackend.whenPOST(URL_REGEX).respond(function(method, url, data) {
|
||||
var match = url.match(URL_REGEX);
|
||||
var username = match[1];
|
||||
var password = match[2];
|
||||
if (users[username] && password === 'password') {
|
||||
return [200, authenticationSuccess(username, users[username]), {}];
|
||||
}
|
||||
return [401, authenticationFailure(), {}];
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
@ -1,11 +1,16 @@
|
||||
(function() {
|
||||
define(['angular-mocks'], function() {
|
||||
var regexp = /\?test_scenario=(\w+)/
|
||||
var match = regexp.exec(window.location.search);
|
||||
if (match) {
|
||||
var scenarioName = match[1];
|
||||
console.log("Loading test scenario: " + scenarioName);
|
||||
require(['../lib/sinon/sinon-1.7.1', 'test/SinonFakeServer'], function() {
|
||||
require(["test/scenarios/" + scenarioName + "_scenario"])
|
||||
mifosX.ng.application.config(function($provide) {
|
||||
$provide.decorator('$httpBackend', angular.mock.e2e.$httpBackendDecorator);
|
||||
}).run(function($httpBackend, $log) {
|
||||
$httpBackend.when("GET", /\.html$/).passThrough();
|
||||
$log.warn("Loading test scenario: " + scenarioName);
|
||||
require(["test/scenarios/" + scenarioName + "_scenario"], function(scenario) {
|
||||
scenario.stubServer($httpBackend);
|
||||
});
|
||||
});
|
||||
}
|
||||
}());
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user