From 5079d20c54809a39d8e9dd3080f1695810d18307 Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Fri, 20 Dec 2024 20:52:40 +0530 Subject: [PATCH] move items from release implementation, unit & api test cases, types support --- lib/stack/release/items/index.js | 19 ++++++++++ test/sanity-check/api/release-test.js | 51 ++++++++++++++++++++++++--- test/sanity-check/mock/release.js | 11 +++++- test/unit/release-test.js | 20 +++++++++++ types/stack/release/index.d.ts | 12 +++++++ 5 files changed, 108 insertions(+), 5 deletions(-) diff --git a/lib/stack/release/items/index.js b/lib/stack/release/items/index.js index 5c33a0b4..8556c1f2 100644 --- a/lib/stack/release/items/index.js +++ b/lib/stack/release/items/index.js @@ -180,6 +180,25 @@ export function ReleaseItem (http, data = {}) { error(err) } } + + this.move = async ({ param, release_version = '' }) => { + const headers = { + headers: { + ...cloneDeep(this.stackHeaders) + } + } || {} + if (release_version) { + headers.headers['release_version'] = release_version; + } + try { + const response = await http.put(`${this.urlPath}/move`, param, headers) + if (response.data) { + return response.data + } + } catch (err) { + throw error(err) + } + } } return this } diff --git a/test/sanity-check/api/release-test.js b/test/sanity-check/api/release-test.js index 5f46fc52..a77f6615 100644 --- a/test/sanity-check/api/release-test.js +++ b/test/sanity-check/api/release-test.js @@ -1,6 +1,6 @@ import { describe, it, setup } from 'mocha' import { jsonReader } from '../utility/fileOperations/readwrite.js' -import { releaseCreate } from '../mock/release.js' +import { releaseCreate, releaseCreate2 } from '../mock/release.js' import { expect } from 'chai' import { cloneDeep } from 'lodash' import { contentstackClient } from '../utility/ContentstackClient.js' @@ -11,6 +11,7 @@ dotenv.config() let client = {} let releaseUID = '' let releaseUID2 = '' +let releaseUID3 = '' let entries = {} const itemToDelete = {} const jobId = '' @@ -35,6 +36,19 @@ describe('Relases api Test', () => { .catch(done) }) + it('should create a Release 2', done => { + makeRelease() + .create(releaseCreate2) + .then((release) => { + releaseUID2 = release.uid + expect(release.name).to.be.equal(releaseCreate2.release.name) + expect(release.description).to.be.equal(releaseCreate2.release.description) + expect(release.uid).to.be.not.equal(null) + done() + }) + .catch(done) + }) + it('should fetch a Release from Uid', done => { makeRelease(releaseUID) .fetch() @@ -115,6 +129,26 @@ describe('Relases api Test', () => { .catch(done) }) + it('should move release items from release1 to release2', done => { + const data = { + release_uid: releaseUID2, + items: [ + { + uid: entries[1].uid, + locale: 'en-us' + } + ] + } + makeRelease(releaseUID) + .item() + .move({ param: data, release_version: '2.0' }) + .then((release) => { + expect(release.notice).to.be.equal('Release items moved successfully!') + done() + }) + .catch(done) + }) + it('should delete specific item', done => { makeRelease(releaseUID) .item() @@ -205,7 +239,7 @@ describe('Relases api Test', () => { makeRelease(releaseUID) .clone({ name: 'New Clone Name', description: 'New Desc' }) .then((release) => { - releaseUID2 = release.uid + releaseUID3 = release.uid expect(release.name).to.be.equal('New Clone Name') expect(release.description).to.be.equal('New Desc') expect(release.uid).to.be.not.equal(null) @@ -257,7 +291,6 @@ describe('Relases api Test', () => { .catch(done) }) - it('Bulk Operation: should update items to a release', done => { const items = { release: releaseUID, @@ -287,7 +320,7 @@ describe('Relases api Test', () => { .catch(done) }) - it('should delete cloned Release with Uid', done => { + it('should delete specific Releases with Uid 2', done => { makeRelease(releaseUID2) .delete() .then((data) => { @@ -296,6 +329,16 @@ describe('Relases api Test', () => { }) .catch(done) }) + + it('should delete cloned Release with Uid', done => { + makeRelease(releaseUID3) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Release deleted successfully.') + done() + }) + .catch(done) + }) }) function makeRelease (uid = null) { diff --git a/test/sanity-check/mock/release.js b/test/sanity-check/mock/release.js index 9bb45e77..58ed92b8 100644 --- a/test/sanity-check/mock/release.js +++ b/test/sanity-check/mock/release.js @@ -7,4 +7,13 @@ const releaseCreate = { } } -export { releaseCreate } +const releaseCreate2 = { + release: { + name: 'Second release', + description: 'Adding release date 2020-21-07', + locked: false, + archived: false + } +} + +export { releaseCreate, releaseCreate2 } diff --git a/test/unit/release-test.js b/test/unit/release-test.js index 4cc3d6b8..06f17f67 100644 --- a/test/unit/release-test.js +++ b/test/unit/release-test.js @@ -221,6 +221,26 @@ describe('Contentstack Release test', () => { }) .catch(done) }) + + it('Release move test', done => { + var mock = new MockAdapter(Axios) + mock.onPut('/releases/UID/items/move').reply(200, { + ...noticeMock + }) + makeRelease({ + release: { + ...systemUidMock + }, + stackHeaders: stackHeadersMock + }) + .item() + .move({ data: { release_uid: 'UID2', items: ['$all'] }, release_version: '2.0' }) + .then((response) => { + expect(response.notice).to.be.equal(noticeMock.notice) + done() + }) + .catch(done) + }) }) function makeRelease (data) { diff --git a/types/stack/release/index.d.ts b/types/stack/release/index.d.ts index 0982c189..00516a58 100644 --- a/types/stack/release/index.d.ts +++ b/types/stack/release/index.d.ts @@ -32,6 +32,7 @@ export interface ReleaseDeploy extends AnyProperty { export interface ReleaseItem extends SystemFields, Creatable }> { delete(param?: { items: Array }): Promise; // Changed return type to Promise findAll(param?: AnyProperty): Promise>; + move(param: { param: MoveReleaseItems, release_version?: string }): Promise; } // Data structure for Release item properties @@ -42,3 +43,14 @@ export interface ReleaseItemData extends AnyProperty { content_type_uid: string; action: 'publish' | 'unpublish'; } + +export interface MoveReleaseItems extends AnyProperty { + release_uid: string; + items: Array; +} + +export interface MoveItemData extends AnyProperty { + uid: string; + locale: string; + variant_id?: string; +}