Skip to content

Commit 31bc4e5

Browse files
sunpietroŁukasz Serwatka
authored andcommitted
EZP-29501: Expose refreshSession method in JS REST Client (#92)
1 parent c71415f commit 31bc4e5

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

dist/CAPI-min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/CAPI.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8183,6 +8183,35 @@ define('CAPI',['authAgents/SessionAuthAgent', 'authAgents/HttpBasicAuthAgent', '
81838183
authenticationAgent.logOut(callback);
81848184
};
81858185

8186+
/**
8187+
* Stores session info.
8188+
*
8189+
* @method storeSessionInfo
8190+
* @param {Object} session
8191+
*/
8192+
this.storeSessionInfo = function (session) {
8193+
authenticationAgent._storeSessionInfo({
8194+
name: session.name,
8195+
href: session._href,
8196+
identifier: session.identifier,
8197+
csrfToken: session.csrfToken,
8198+
});
8199+
};
8200+
8201+
/**
8202+
* Refreshes the user session
8203+
*
8204+
* @method refreshSession
8205+
* @param {Function} callback
8206+
*/
8207+
this.refreshSession = function (callback) {
8208+
if (!userService) {
8209+
return;
8210+
}
8211+
8212+
userService.refreshSession(authenticationAgent._storage.getItem('ezpRestClient.sessionId'), callback);
8213+
};
8214+
81868215
/**
81878216
* Get instance of Content Service. Use ContentService to retrieve information and execute operations related to Content.
81888217
*

src/CAPI.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,35 @@ define(['authAgents/SessionAuthAgent', 'authAgents/HttpBasicAuthAgent', 'Connect
105105
authenticationAgent.logOut(callback);
106106
};
107107

108+
/**
109+
* Stores session info.
110+
*
111+
* @method storeSessionInfo
112+
* @param {Object} session
113+
*/
114+
this.storeSessionInfo = function (session) {
115+
authenticationAgent._storeSessionInfo({
116+
name: session.name,
117+
href: session._href,
118+
identifier: session.identifier,
119+
csrfToken: session.csrfToken,
120+
});
121+
};
122+
123+
/**
124+
* Refreshes the user session
125+
*
126+
* @method refreshSession
127+
* @param {Function} callback
128+
*/
129+
this.refreshSession = function (callback) {
130+
if (!userService) {
131+
return;
132+
}
133+
134+
userService.refreshSession(authenticationAgent._storage.getItem('ezpRestClient.sessionId'), callback);
135+
};
136+
108137
/**
109138
* Get instance of Content Service. Use ContentService to retrieve information and execute operations related to Content.
110139
*

test/CAPI.tests.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ define(function (require) {
2626

2727
MockAuthenticationAgent = function () {
2828
this._CAPI = null;
29+
this._storage = (function () {
30+
this.getItem = function (key) { return 'key'; };
31+
})();
2932
this.setCAPI = function (capi) {
3033
this._CAPI = capi;
3134
};
@@ -167,6 +170,19 @@ define(function (require) {
167170
});
168171
});
169172

173+
describe('refreshSession', function () {
174+
it('It should invoke the refreshSession method from the UserService', function () {
175+
var mockCallback = function () {},
176+
userService = capi.getUserService();
177+
178+
spyOn(userService, 'refreshSession');
179+
180+
capi.logIn(mockCallback);
181+
182+
expect(userService).toHaveBeenCalledWith(mockCallback);
183+
});
184+
});
185+
170186
describe("getConnectionManager", function () {
171187
it("should provide ConnectionManager", function () {
172188
var connectionManager = capi.getConnectionManager();

0 commit comments

Comments
 (0)