Skip to content

Commit

Permalink
EZP-29501: Expose refreshSession method in JS REST Client (ezsystems#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunpietro authored and Łukasz Serwatka committed Sep 25, 2018
1 parent c71415f commit 31bc4e5
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dist/CAPI-min.js

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions dist/CAPI.js
Expand Up @@ -8183,6 +8183,35 @@ define('CAPI',['authAgents/SessionAuthAgent', 'authAgents/HttpBasicAuthAgent', '
authenticationAgent.logOut(callback);
};

/**
* Stores session info.
*
* @method storeSessionInfo
* @param {Object} session
*/
this.storeSessionInfo = function (session) {
authenticationAgent._storeSessionInfo({
name: session.name,
href: session._href,
identifier: session.identifier,
csrfToken: session.csrfToken,
});
};

/**
* Refreshes the user session
*
* @method refreshSession
* @param {Function} callback
*/
this.refreshSession = function (callback) {
if (!userService) {
return;
}

userService.refreshSession(authenticationAgent._storage.getItem('ezpRestClient.sessionId'), callback);
};

/**
* Get instance of Content Service. Use ContentService to retrieve information and execute operations related to Content.
*
Expand Down
29 changes: 29 additions & 0 deletions src/CAPI.js
Expand Up @@ -105,6 +105,35 @@ define(['authAgents/SessionAuthAgent', 'authAgents/HttpBasicAuthAgent', 'Connect
authenticationAgent.logOut(callback);
};

/**
* Stores session info.
*
* @method storeSessionInfo
* @param {Object} session
*/
this.storeSessionInfo = function (session) {
authenticationAgent._storeSessionInfo({
name: session.name,
href: session._href,
identifier: session.identifier,
csrfToken: session.csrfToken,
});
};

/**
* Refreshes the user session
*
* @method refreshSession
* @param {Function} callback
*/
this.refreshSession = function (callback) {
if (!userService) {
return;
}

userService.refreshSession(authenticationAgent._storage.getItem('ezpRestClient.sessionId'), callback);
};

/**
* Get instance of Content Service. Use ContentService to retrieve information and execute operations related to Content.
*
Expand Down
16 changes: 16 additions & 0 deletions test/CAPI.tests.js
Expand Up @@ -26,6 +26,9 @@ define(function (require) {

MockAuthenticationAgent = function () {
this._CAPI = null;
this._storage = (function () {
this.getItem = function (key) { return 'key'; };
})();
this.setCAPI = function (capi) {
this._CAPI = capi;
};
Expand Down Expand Up @@ -167,6 +170,19 @@ define(function (require) {
});
});

describe('refreshSession', function () {
it('It should invoke the refreshSession method from the UserService', function () {
var mockCallback = function () {},
userService = capi.getUserService();

spyOn(userService, 'refreshSession');

capi.logIn(mockCallback);

expect(userService).toHaveBeenCalledWith(mockCallback);
});
});

describe("getConnectionManager", function () {
it("should provide ConnectionManager", function () {
var connectionManager = capi.getConnectionManager();
Expand Down

0 comments on commit 31bc4e5

Please sign in to comment.