From c20464a90b8d407439c77fb48ea5b15d59d68765 Mon Sep 17 00:00:00 2001 From: Damien Pobel Date: Tue, 17 Mar 2015 09:48:35 +0100 Subject: [PATCH] EZP-24065: added a setSection method to ContentMetadataUpdateStruct --- src/structures/ContentMetadataUpdateStruct.js | 10 +++++ test/ContentMetadataUpdateStruct.tests.js | 37 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 test/ContentMetadataUpdateStruct.tests.js diff --git a/src/structures/ContentMetadataUpdateStruct.js b/src/structures/ContentMetadataUpdateStruct.js index ad927dd..b29307f 100644 --- a/src/structures/ContentMetadataUpdateStruct.js +++ b/src/structures/ContentMetadataUpdateStruct.js @@ -18,5 +18,15 @@ define(function () { }; }; + /** + * 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; }); diff --git a/test/ContentMetadataUpdateStruct.tests.js b/test/ContentMetadataUpdateStruct.tests.js new file mode 100644 index 0000000..4823f7b --- /dev/null +++ b/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, + }); + }); + }); + }); +});