Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a way to load the Content Types instead of the Content Type Infos in ContentTypeService#loadContentTypes #78

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/services/ContentTypeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,25 @@ define(["structures/ContentTypeGroupInputStruct", "structures/ContentTypeCreateS
};

/**
* List content for a content type group
* Loads Content Types Info or Content Types in a given Content Type Group.
*
* @method loadContentTypes
* @param contentTypeGroupId {String} target content type group identifier (e.g. "/api/ezp/v2/content/typegroups/1")
* @param [acceptHeader] {String} Optional accept header value. Set it to
* `application/vnd.ez.api.ContentTypeList+json` to load the Content Types
* otherwise the default accept is used and this methods loads the Content
* Types Info instead.
* @param callback {Function} callback executed after performing the request (see
* {{#crossLink "ContentTypeService"}}Note on the callbacks usage{{/crossLink}} for more info)
*/
ContentTypeService.prototype.loadContentTypes = function (contentTypeGroupId, callback) {
ContentTypeService.prototype.loadContentTypes = function (contentTypeGroupId, acceptHeader, callback) {
var that = this;

if ( !callback ) {
callback = acceptHeader;
acceptHeader = null;
}

this.loadContentTypeGroup(
contentTypeGroupId,
function (error, contentTypeGroupResponse) {
Expand All @@ -254,7 +263,7 @@ define(["structures/ContentTypeGroupInputStruct", "structures/ContentTypeCreateS
"GET",
contentTypeGroup.ContentTypes._href,
"",
{"Accept": contentTypeGroup.ContentTypes["_media-type"]},
{"Accept": acceptHeader ? acceptHeader : contentTypeGroup.ContentTypes["_media-type"]},
callback
);
}
Expand Down
48 changes: 34 additions & 14 deletions test/ContentTypeService.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,24 +219,44 @@ define(function (require) {
);
});

it("loadContentTypes", function () {
describe('loadContentTypes', function () {
it("should load the Content Type Infos", function () {
spyOn(contentTypeService, 'loadContentTypeGroup').andCallFake(fakedLoadContentTypeGroup);

spyOn(contentTypeService, 'loadContentTypeGroup').andCallFake(fakedLoadContentTypeGroup);
contentTypeService.loadContentTypes(
testContentTypeGroupId,
mockCallback
);

contentTypeService.loadContentTypes(
testContentTypeGroupId,
mockCallback
);
expect(mockConnectionManager.request).toHaveBeenCalledWith(
"GET",
testContentTypeGroupTypes,
"",
{Accept: "application/vnd.ez.api.ContentTypeInfoList+json"},
mockCallback
);
});

expect(mockConnectionManager.request).toHaveBeenCalledWith(
"GET",
testContentTypeGroupTypes,
"",
{Accept: "application/vnd.ez.api.ContentTypeInfoList+json"},
mockCallback
);
});
it("should load the Content Types", function () {
var typeHeader = "application/vnd.ez.api.ContentTypeList+json";

spyOn(contentTypeService, 'loadContentTypeGroup').andCallFake(fakedLoadContentTypeGroup);

contentTypeService.loadContentTypes(
testContentTypeGroupId,
typeHeader,
mockCallback
);

expect(mockConnectionManager.request).toHaveBeenCalledWith(
"GET",
testContentTypeGroupTypes,
"",
{Accept: typeHeader},
mockCallback
);
});
});

// ******************************
// Content Type Management
Expand Down