From 612bc91ae4c95e4e881385ef134ffb3fdb7d6f07 Mon Sep 17 00:00:00 2001 From: pkupczyk <pkupczyk> Date: Tue, 28 Jul 2015 12:09:58 +0000 Subject: [PATCH] SSDM-2130 : V3 AS API - finish up js tests - loginAs SVN: 34377 --- .../openbis-v3-api-test/html/test/common.js | 21 ++++++++++----- .../openbis-v3-api-test/html/test/login.js | 27 +++++++++++++++++++ .../openbis-v3-api-test/html/test/main.js | 2 +- .../public/resources/api/v3/openbis.js | 2 +- 4 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/login.js diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/common.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/common.js index 11eb5717273..d4502c1254e 100644 --- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/common.js +++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/common.js @@ -42,15 +42,16 @@ define([ 'jquery', 'openbis' ], function($, openbis) { return object; }; - this.createFacade = function(action) { - var facade = new openbis(testApiUrl); - action(facade); + this.createFacade = function() { + var dfd = $.Deferred(); + dfd.resolve(new openbis(testApiUrl)); + return dfd.promise(); }; this.createFacadeAndLogin = function() { var dfd = $.Deferred(); - this.createFacade(function(facade) { + this.createFacade().then(function(facade) { facade.login(testUserId, testUserPassword).done(function() { dfd.resolve(facade); }).fail(function() { @@ -217,11 +218,19 @@ define([ 'jquery', 'openbis' ], function($, openbis) { }; this.assertNull = function(actual, msg) { - this.assert.equal(actual, null, msg); + this.assertEqual(actual, null, msg) }; this.assertNotNull = function(actual, msg) { - this.assert.notEqual(actual, null, msg); + this.assertNotEqual(actual, null, msg); + }; + + this.assertTrue = function(actual, msg) { + this.assertEqual(actual, true, msg); + }; + + this.assertFalse = function(actual, msg) { + this.assertEqual(actual, false, msg); }; this.assertEqual = function(actual, expected, msg) { diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/login.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/login.js new file mode 100644 index 00000000000..03a0e9d2266 --- /dev/null +++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/login.js @@ -0,0 +1,27 @@ +define([ 'jquery', 'underscore', 'openbis', 'test/common' ], function($, _, openbis, common) { + return function() { + QUnit.module("Login tests"); + + QUnit.test("loginAs()", function(assert) { + var c = new common(assert); + var done = assert.async(); + + $.when(c.createFacade(), c.createSpaceSearchCriterion(), c.createSpaceFetchOptions()).then(function(facade, criterion, fetchOptions) { + return facade.login("openbis_test_js", "password").then(function() { + return facade.searchSpaces(criterion, fetchOptions).then(function(spacesForInstanceAdmin) { + return facade.loginAs("openbis_test_js", "password", "test_space_admin").then(function() { + return facade.searchSpaces(criterion, fetchOptions).then(function(spacesForSpaceAdmin) { + c.assertTrue(spacesForInstanceAdmin.length > spacesForSpaceAdmin.length); + c.assertObjectsWithValues(spacesForSpaceAdmin, "code", [ "TEST" ]); + done(); + }); + }); + }); + }); + }).fail(function(error) { + c.fail(error.message); + done(); + }); + }); + } +}); diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/main.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/main.js index d32eca6dc95..891fa56676f 100644 --- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/main.js +++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/main.js @@ -1,4 +1,4 @@ -define([ 'test/space', 'test/project', 'test/experiment', 'test/sample', 'test/dataset', 'test/material', 'test/deletion', 'test/dto' ], function() { +define([ 'test/login', 'test/space', 'test/project', 'test/experiment', 'test/sample', 'test/dataset', 'test/material', 'test/deletion', 'test/dto' ], function() { var testSuites = arguments; return function() { for (var i = 0; i < testSuites.length; i++) { diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/openbis.js b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/openbis.js index d61ca8d32e5..099afefc949 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/openbis.js +++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/resources/api/v3/openbis.js @@ -93,7 +93,7 @@ define([ 'jquery', 'util/Json' ], function($, stjsUtil) { this.loginAs = function(user, password, asUserId) { var thisFacade = this; - return thisFacade._private.loginCommon(user, thisFacade._private.ajaxRequest({ + return thisFacade._private.loginCommon(asUserId, thisFacade._private.ajaxRequest({ url : openbisUrl, data : { "method" : "loginAs", -- GitLab