Skip to content

Commit 716151b

Browse files
sunpietroandrerom
authored andcommitted
EZP-25753: Load user drafts using JS REST Client (#77)
Contains two commits from #77: * EZP-25753: Load user drafts using JS REST Client * Moved the loadUserDrafts method from UserService to ContentService
1 parent 04fdf25 commit 716151b

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3676,6 +3676,24 @@ define('services/ContentService',["structures/ContentCreateStruct", "structures/
36763676
// Versions management
36773677
// ******************************
36783678

3679+
/**
3680+
* Loads user drafts
3681+
*
3682+
* @method loadUserDrafts
3683+
* @param userId {String} target user identifier (e.g. "/api/ezp/v2/user/users/14")
3684+
* @param callback {Function} callback executed after performing the request (see
3685+
* {{#crossLink "ContentService"}} Note on the callbacks usage{{/crossLink}} for more info)
3686+
*/
3687+
ContentService.prototype.loadUserDrafts = function (userId, callback) {
3688+
this._connectionManager.request(
3689+
"GET",
3690+
userId + "/drafts",
3691+
"",
3692+
{"Accept": "application/vnd.ez.api.VersionList+json"},
3693+
callback
3694+
);
3695+
};
3696+
36793697
/**
36803698
* Load current version for target content
36813699
*

src/services/ContentService.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,24 @@ define(["structures/ContentCreateStruct", "structures/ContentUpdateStruct", "str
560560
// Versions management
561561
// ******************************
562562

563+
/**
564+
* Loads user drafts
565+
*
566+
* @method loadUserDrafts
567+
* @param userId {String} target user identifier (e.g. "/api/ezp/v2/user/users/14")
568+
* @param callback {Function} callback executed after performing the request (see
569+
* {{#crossLink "ContentService"}} Note on the callbacks usage{{/crossLink}} for more info)
570+
*/
571+
ContentService.prototype.loadUserDrafts = function (userId, callback) {
572+
this._connectionManager.request(
573+
"GET",
574+
userId + "/drafts",
575+
"",
576+
{"Accept": "application/vnd.ez.api.VersionList+json"},
577+
callback
578+
);
579+
};
580+
563581
/**
564582
* Load current version for target content
565583
*

test/ContentService.tests.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ define(function (require) {
5353
testSections = '/api/ezp/v2/content/sections',
5454
testSection = '/api/ezp/v2/content/sections/1',
5555
trash = '/api/ezp/v2/content/trash',
56+
testUserId = "/api/ezp/v2/user/users/144",
5657
testOffset = 2,
5758
testLimit = 5,
5859
defaultOffset = 0,
@@ -439,6 +440,21 @@ define(function (require) {
439440
// ******************************
440441
describe("Versions management request:", function () {
441442

443+
it("loadUserDrafts", function () {
444+
contentService.loadUserDrafts(
445+
testUserId,
446+
mockCallback
447+
);
448+
449+
expect(mockConnectionManager.request).toHaveBeenCalledWith(
450+
"GET",
451+
testUserId + "/drafts",
452+
"",
453+
{"Accept": "application/vnd.ez.api.VersionList+json"},
454+
mockCallback
455+
);
456+
});
457+
442458
it("loadCurrentVersion", function () {
443459

444460
spyOn(contentService, 'loadContentInfo').andCallFake(fakedLoadContentInfo);

0 commit comments

Comments
 (0)