-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdelete-test.js
More file actions
192 lines (176 loc) · 5.42 KB
/
delete-test.js
File metadata and controls
192 lines (176 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import { expect } from 'chai'
import { describe, it, setup } from 'mocha'
import { jsonReader } from '../utility/fileOperations/readwrite'
import { contentstackClient } from '../utility/ContentstackClient.js'
import { environmentCreate, environmentProdCreate } from '../mock/environment.js'
import { stageBranch } from '../mock/branch.js'
import { createDeliveryToken } from '../mock/deliveryToken.js'
import dotenv from 'dotenv'
dotenv.config()
let client = {}
describe('Delete Environment api Test', () => {
setup(() => {
const user = jsonReader('loggedinuser.json')
client = contentstackClient(user.authtoken)
})
it('should delete an environment', done => {
makeEnvironment(environmentCreate.environment.name)
.delete()
.then((data) => {
expect(data.notice).to.be.equal('Environment deleted successfully.')
done()
})
.catch((error) => {
// Environment might not exist, which is acceptable
if (error.status === 422 || error.status === 404) {
done() // Test passes if environment doesn't exist
} else {
done(error)
}
})
})
it('should delete the prod environment', done => {
makeEnvironment(environmentProdCreate.environment.name)
.delete()
.then((data) => {
expect(data.notice).to.be.equal('Environment deleted successfully.')
done()
})
.catch((error) => {
// Environment might not exist, which is acceptable
if (error.status === 422 || error.status === 404) {
done() // Test passes if environment doesn't exist
} else {
done(error)
}
})
})
})
describe('Delete Locale api Test', () => {
setup(() => {
const user = jsonReader('loggedinuser.json')
client = contentstackClient(user.authtoken)
})
it('should delete language: Hindi - India', done => {
makeLocale('hi-in')
.delete()
.then((data) => {
expect(data.notice).to.be.equal('Language removed successfully.')
done()
})
.catch(done)
})
it('should delete language: English - Austria', done => {
makeLocale('en-at')
.delete()
.then((data) => {
expect(data.notice).to.be.equal('Language removed successfully.')
done()
})
.catch(done)
})
})
describe('Delivery Token delete api Test', () => {
let tokenUID = ''
setup(() => {
const user = jsonReader('loggedinuser.json')
client = contentstackClient(user.authtoken)
})
it('should get token uid by name for deleting that token', done => {
makeDeliveryToken()
.query({ query: { name: createDeliveryToken.token.name } })
.find()
.then((tokens) => {
tokens.items.forEach((token) => {
tokenUID = token.uid
})
done()
})
.catch(done)
})
it('should delete Delivery token from uid', done => {
if (tokenUID) {
makeDeliveryToken(tokenUID)
.delete()
.then((data) => {
expect(data.notice).to.be.equal('Delivery Token deleted successfully.')
done()
})
.catch(done)
} else {
// No token to delete, skip test
done()
}
})
})
describe('Branch Alias delete api Test', () => {
setup(() => {
const user = jsonReader('loggedinuser.json')
client = contentstackClient(user.authtoken)
})
it('Should delete Branch Alias', done => {
makeBranchAlias(`${stageBranch.uid}_alias`)
.delete()
.then((response) => {
expect(response.notice).to.be.equal('Branch alias deleted successfully.')
done()
})
.catch((error) => {
// Branch alias might not exist, which is acceptable
if (error.status === 422 || error.status === 404) {
done() // Test passes if branch alias doesn't exist
} else {
done(error)
}
})
})
it('Should delete stage branch from uid', done => {
client.stack({ api_key: process.env.API_KEY }).branch(stageBranch.uid)
.delete()
.then((response) => {
expect(response.notice).to.be.equal('Your branch deletion is in progress. Please refresh in a while.')
done()
})
.catch(done)
})
})
describe('Delete Asset Folder api Test', () => {
let folderUid = ''
setup(() => {
const user = jsonReader('loggedinuser.json')
const folder = jsonReader('folder.json')
folderUid = folder.uid
client = contentstackClient(user.authtoken)
})
it('should delete an asset folder', done => {
makeAssetFolder(folderUid)
.delete()
.then((data) => {
expect(data.notice).to.be.equal('Folder deleted successfully.')
done()
})
.catch((error) => {
// Folder might not exist, which is acceptable
if (error.status === 404 || error.status === 145) {
done() // Test passes if folder doesn't exist
} else {
done(error)
}
})
})
})
function makeEnvironment (uid = null) {
return client.stack({ api_key: process.env.API_KEY }).environment(uid)
}
function makeLocale (uid = null) {
return client.stack({ api_key: process.env.API_KEY }).locale(uid)
}
function makeDeliveryToken (uid = null) {
return client.stack({ api_key: process.env.API_KEY }).deliveryToken(uid)
}
function makeBranchAlias (uid = null) {
return client.stack({ api_key: process.env.API_KEY }).branchAlias(uid)
}
function makeAssetFolder (uid = null) {
return client.stack({ api_key: process.env.API_KEY }).asset().folder(uid)
}