Skip to content

Commit 3005eed

Browse files
fix: added delete stack method
and test case
1 parent f20cf58 commit 3005eed

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

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.

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)