Skip to content

Commit

Permalink
Merge pull request ezsystems#54 from ezsystems/ezp-24065_section_assign
Browse files Browse the repository at this point in the history
EZP-24065: ContentMetadataUpdateStruct improvements
  • Loading branch information
dpobel committed Mar 20, 2015
2 parents 4db767b + c20464a commit fd0f4aa
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 27 deletions.
36 changes: 16 additions & 20 deletions src/structures/ContentMetadataUpdateStruct.js
Expand Up @@ -3,34 +3,30 @@ define(function () {
"use strict";

/**
* Returns a structure used to update a Content's metadata. See
* {{#crossLink "ContentService/updateContentMetadata"}}ContentService.updateContentMetadata{{/crossLink}}
* The Content Update structure that can be used with {{#crossLink
* "ContentService/updateContentMetadata"}}ContentService.updateContentMetadata{{/crossLink}}
*
* @class ContentMetadataUpdateStruct
* @constructor
* @param languageCode {String} The language code (eng-GB, fre-FR, ...)
*/
var ContentMetadataUpdateStruct = function (languageCode) {
var now = JSON.parse(JSON.stringify(new Date()));
var ContentMetadataUpdateStruct = function () {
this.body = {'ContentUpdate': {}};

this.body = {};
this.body.ContentUpdate = {};

this.body.ContentUpdate.MainLanguageCode = languageCode;
this.body.ContentUpdate.Section = null;
this.body.ContentUpdate.alwaysAvailable = "true";
this.body.ContentUpdate.remoteId = null;
this.body.ContentUpdate.modificationDate = now;
this.body.ContentUpdate.publishDate = null;

this.headers = {
"Accept": "application/vnd.ez.api.ContentInfo+json",
"Content-Type": "application/vnd.ez.api.ContentUpdate+json"
this.headers = {
"Accept": "application/vnd.ez.api.ContentInfo+json",
"Content-Type": "application/vnd.ez.api.ContentUpdate+json"
};
};

return this;
/**
* Sets the section id
*
* @method setSection
* @param {String} sectionId the Section REST id
*/
ContentMetadataUpdateStruct.prototype.setSection = function (sectionId) {
this.body.ContentUpdate.Section = {_href: sectionId};
};

return ContentMetadataUpdateStruct;

});
37 changes: 37 additions & 0 deletions test/ContentMetadataUpdateStruct.tests.js
@@ -0,0 +1,37 @@
/* global define, describe, it, expect, beforeEach */
define(function (require) {
var ContentMetadataUpdateStruct = require('structures/ContentMetadataUpdateStruct');

describe('ContentMetadataUpdateStruct', function () {
var contentMetadataUpdateStruct;

beforeEach(function () {
contentMetadataUpdateStruct = new ContentMetadataUpdateStruct();
});

describe('constructor', function () {
it('should initialize the body', function () {
expect(contentMetadataUpdateStruct.body).toEqual({'ContentUpdate': {}});
});

it('should set the headers', function () {
expect(contentMetadataUpdateStruct.headers).toEqual({
"Accept": "application/vnd.ez.api.ContentInfo+json",
"Content-Type": "application/vnd.ez.api.ContentUpdate+json"
});
});
});

describe('setSection', function () {
it('should set the Section property', function () {
var sectionId = 'section-id';

contentMetadataUpdateStruct.setSection(sectionId);

expect(contentMetadataUpdateStruct.body.ContentUpdate.Section).toEqual({
_href: sectionId,
});
});
});
});
});
10 changes: 3 additions & 7 deletions test/ContentService.tests.js
Expand Up @@ -304,9 +304,7 @@ define(function (require) {

it("updateContentMetadata", function () {

var updateStruct = contentService.newContentMetadataUpdateStruct(
"eng-US"
);
var updateStruct = contentService.newContentMetadataUpdateStruct();

updateStruct.body.ContentUpdate.Section = "/api/ezp/v2/content/sections/2";
updateStruct.body.ContentUpdate.remoteId = "random-id-";
Expand Down Expand Up @@ -1690,12 +1688,10 @@ define(function (require) {

it("newContentMetadataUpdateStruct", function (){

testStructure = contentService.newContentMetadataUpdateStruct(
testLanguage
);
testStructure = contentService.newContentMetadataUpdateStruct();

expect(testStructure).toEqual(jasmine.any(ContentMetadataUpdateStruct));
expect(testStructure.body.ContentUpdate.MainLanguageCode).toEqual(testLanguage);
expect(testStructure.body).toEqual({ContentUpdate: {}});
});

it("newContentCreateStruct", function (){
Expand Down

0 comments on commit fd0f4aa

Please sign in to comment.