Skip to content

Commit ca2e176

Browse files
Merge pull request #137 from contentstack/fix/cs-44541-stack-delete-function
Fix/cs 44541 stack delete function
2 parents f20cf58 + eb98fd6 commit ca2e176

File tree

7 files changed

+84
-56
lines changed

7 files changed

+84
-56
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [v1.15.5](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.4) (2024-04-02)
4+
- Enhancement
5+
- delete stack implemetation and test cases
6+
37
## [v1.15.4](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.4) (2024-03-26)
48
- Fixes
59
- sanity test and dependency upgrades

lib/stack/index.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import cloneDeep from 'lodash/cloneDeep'
22
import error from '../core/contentstackError'
33
import { UserCollection } from '../user/index'
44
import { Role } from './roles/index'
5-
import { create, query, update, fetch } from '../entity'
5+
import { create, query, update, fetch, deleteEntity } from '../entity'
66
import { ContentType } from './contentType/index'
77
import { GlobalField } from './globalField/index'
88
import { DeliveryToken } from './deliveryToken/index'
@@ -259,7 +259,7 @@ export function Stack (http, data) {
259259
}
260260

261261
/**
262-
* @description Management Tokens are tokens that provide you with read-write access to the content of your stack.
262+
* @description Management Tokens are tokens that provide you with read-write access to the content of your stack.
263263
* @param {String} managementTokenUid The UID of the Management Token field you want to get details.
264264
* @returns {ManagementToken} Instance of ManagementToken.
265265
* @example
@@ -730,6 +730,21 @@ export function Stack (http, data) {
730730
}
731731
return new Taxonomy(http, data)
732732
}
733+
734+
/**
735+
* @description The delete stack call lets you delete the stack.
736+
* @memberof Stack
737+
* @func delete
738+
* @returns {Promise<Stack.Stack>} Promise for Stack instance
739+
* @example
740+
* import * as contentstack from '@contentstack/management'
741+
* const client = contentstack.client()
742+
*
743+
* client.stack({ api_key: 'api_key'}).delete()
744+
* .then((stack) => console.log(stack))
745+
*
746+
*/
747+
this.delete = deleteEntity(http)
733748
} else {
734749
/**
735750
* @description The Create stack call creates a new stack in your Contentstack account.

package-lock.json

Lines changed: 28 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/management",
3-
"version": "1.15.4",
3+
"version": "1.15.5",
44
"description": "The Content Management API is used to manage the content of your Contentstack account",
55
"main": "./dist/node/contentstack-management.js",
66
"browser": "./dist/web/contentstack-management.js",

test/sanity-check/api/asset-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ describe('Assets api Test', () => {
5959
makeAsset().folder().create({ asset: { name: 'Sample Folder' } })
6060
.then((asset) => {
6161
folderUID = asset.uid
62+
jsonWrite(asset, 'folder.json')
6263
expect(asset.uid).to.be.not.equal(null)
6364
expect(asset.name).to.be.equal('Sample Folder')
6465
expect(asset.is_dir).to.be.equal(true)

test/sanity-check/api/delete-test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,25 @@ describe('Branch Alias delete api Test', () => {
123123
})
124124
})
125125

126+
describe('Delete Asset Folder api Test', () => {
127+
let folderUid = ''
128+
setup(() => {
129+
const user = jsonReader('loggedinuser.json')
130+
const folder = jsonReader('folder.json')
131+
folderUid = folder.uid
132+
client = contentstackClient(user.authtoken)
133+
})
134+
it('should delete an environment', done => {
135+
makeAssetFolder(folderUid)
136+
.delete()
137+
.then((data) => {
138+
expect(data.notice).to.be.equal('Folder deleted successfully.')
139+
done()
140+
})
141+
.catch(done)
142+
})
143+
})
144+
126145
function makeEnvironment (uid = null) {
127146
return client.stack({ api_key: process.env.API_KEY }).environment(uid)
128147
}
@@ -138,3 +157,7 @@ function makeDeliveryToken (uid = null) {
138157
function makeBranchAlias (uid = null) {
139158
return client.stack({ api_key: process.env.API_KEY }).branchAlias(uid)
140159
}
160+
161+
function makeAssetFolder (uid = null) {
162+
return client.stack({ api_key: process.env.API_KEY }).asset().folder(uid)
163+
}

test/sanity-check/api/stack-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ describe('Stack api Test', () => {
157157
})
158158
.catch(done)
159159
})
160+
161+
it('should delete stack', done => {
162+
client.stack({ api_key: stacks.api_key })
163+
.delete()
164+
.then((stack) => {
165+
expect(stack.notice).to.be.equal('Stack deleted successfully!')
166+
done()
167+
})
168+
.catch(done)
169+
})
160170
})
161171

162172
describe('Branch creation api Test', () => {

0 commit comments

Comments
 (0)