-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdeliveryToken-test.js
More file actions
145 lines (134 loc) · 5.48 KB
/
deliveryToken-test.js
File metadata and controls
145 lines (134 loc) · 5.48 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
import { expect } from 'chai'
import { describe, it, setup } from 'mocha'
import { jsonReader } from '../utility/fileOperations/readwrite'
import { createDeliveryToken, createDeliveryToken2 } from '../mock/deliveryToken.js'
import { contentstackClient } from '../utility/ContentstackClient.js'
import dotenv from 'dotenv'
dotenv.config()
let client = {}
let tokenUID = ''
describe('Delivery Token api Test', () => {
setup(() => {
const user = jsonReader('loggedinuser.json')
client = contentstackClient(user.authtoken)
})
it('should add a Delivery Token for development', done => {
makeDeliveryToken()
.create(createDeliveryToken)
.then((token) => {
expect(token.name).to.be.equal(createDeliveryToken.token.name)
expect(token.description).to.be.equal(createDeliveryToken.token.description)
expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken.token.scope[0].environments[0])
expect(token.scope[0].module).to.be.equal(createDeliveryToken.token.scope[0].module)
expect(token.uid).to.be.not.equal(null)
expect(token.preview_token).to.be.not.equal(null)
done()
})
.catch(done)
})
it('should add a Delivery Token for production', done => {
makeDeliveryToken()
.create(createDeliveryToken2)
.then((token) => {
tokenUID = token.uid
expect(token.name).to.be.equal(createDeliveryToken2.token.name)
expect(token.description).to.be.equal(createDeliveryToken2.token.description)
expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken2.token.scope[0].environments[0])
expect(token.scope[0].module).to.be.equal(createDeliveryToken2.token.scope[0].module)
expect(token.uid).to.be.not.equal(null)
expect(token.preview_token).to.be.not.equal(null)
done()
})
.catch(done)
})
it('should get a Delivery Token from uid', done => {
makeDeliveryToken(tokenUID)
.fetch()
.then((token) => {
expect(token.name).to.be.equal(createDeliveryToken2.token.name)
expect(token.description).to.be.equal(createDeliveryToken2.token.description)
expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken2.token.scope[0].environments[0])
expect(token.scope[0].module).to.be.equal(createDeliveryToken2.token.scope[0].module)
expect(token.uid).to.be.not.equal(null)
done()
})
.catch(done)
})
it('should query to get all Delivery Token', done => {
makeDeliveryToken()
.query()
.find()
.then((tokens) => {
tokens.items.forEach((token) => {
expect(token.name).to.be.not.equal(null)
expect(token.description).to.be.not.equal(null)
expect(token.scope[0].environments[0].name).to.be.not.equal(null)
expect(token.scope[0].module).to.be.not.equal(null)
expect(token.uid).to.be.not.equal(null)
})
done()
})
.catch(done)
})
it('should query to get a Delivery Token from name', done => {
makeDeliveryToken()
.query({ query: { name: createDeliveryToken.token.name } })
.find()
.then((tokens) => {
tokens.items.forEach((token) => {
expect(token.name).to.be.equal(createDeliveryToken.token.name)
expect(token.description).to.be.equal(createDeliveryToken.token.description)
expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken.token.scope[0].environments[0])
expect(token.scope[0].module).to.be.equal(createDeliveryToken.token.scope[0].module)
expect(token.uid).to.be.not.equal(null)
})
done()
})
.catch(done)
})
it('should fetch and update a Delivery Token from uid', done => {
makeDeliveryToken(tokenUID)
.fetch()
.then((token) => {
token.name = 'Update Production Name'
token.description = 'Update Production description'
token.scope = createDeliveryToken2.token.scope
return token.update()
})
.then((token) => {
expect(token.name).to.be.equal('Update Production Name')
expect(token.description).to.be.equal('Update Production description')
expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken2.token.scope[0].environments[0])
expect(token.scope[0].module).to.be.equal(createDeliveryToken2.token.scope[0].module)
expect(token.uid).to.be.not.equal(null)
done()
})
.catch(done)
})
it('should update a Delivery Token from uid', done => {
const token = makeDeliveryToken(tokenUID)
Object.assign(token, createDeliveryToken2.token)
token.update()
.then((token) => {
expect(token.name).to.be.equal(createDeliveryToken2.token.name)
expect(token.description).to.be.equal(createDeliveryToken2.token.description)
expect(token.scope[0].environments[0].name).to.be.equal(createDeliveryToken2.token.scope[0].environments[0])
expect(token.scope[0].module).to.be.equal(createDeliveryToken2.token.scope[0].module)
expect(token.uid).to.be.not.equal(null)
done()
})
.catch(done)
})
it('should delete a Delivery Token from uid', done => {
makeDeliveryToken(tokenUID)
.delete()
.then((data) => {
expect(data.notice).to.be.equal('Delivery Token deleted successfully.')
done()
})
.catch(done)
})
})
function makeDeliveryToken (uid = null) {
return client.stack({ api_key: process.env.API_KEY }).deliveryToken(uid)
}