-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathpreviewToken-test.js
More file actions
91 lines (83 loc) · 2.71 KB
/
previewToken-test.js
File metadata and controls
91 lines (83 loc) · 2.71 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
import { expect } from 'chai'
import { describe, it, setup } from 'mocha'
import { jsonReader } from '../utility/fileOperations/readwrite'
import { createDeliveryToken3 } from '../mock/deliveryToken.js'
import { contentstackClient } from '../utility/ContentstackClient.js'
import dotenv from 'dotenv'
dotenv.config()
let client = {}
let tokenUID = ''
describe('Preview Token api Test', () => {
setup(() => {
const user = jsonReader('loggedinuser.json')
client = contentstackClient(user.authtoken)
})
it('should add a Delivery Token for development', (done) => {
makeDeliveryToken()
.create(createDeliveryToken3)
.then((token) => {
tokenUID = token.uid
expect(token.name).to.be.equal(createDeliveryToken3.token.name)
expect(token.description).to.be.equal(
createDeliveryToken3.token.description
)
expect(token.scope[0].environments[0].name).to.be.equal(
createDeliveryToken3.token.scope[0].environments[0]
)
expect(token.scope[0].module).to.be.equal(
createDeliveryToken3.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 Preview Token', (done) => {
makePreviewToken(tokenUID)
.create()
.then((token) => {
expect(token.name).to.be.equal(createDeliveryToken3.token.name)
expect(token.description).to.be.equal(
createDeliveryToken3.token.description
)
expect(token.scope[0].environments[0].name).to.be.equal(
createDeliveryToken3.token.scope[0].environments[0]
)
expect(token.scope[0].module).to.be.equal(
createDeliveryToken3.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 delete a Preview Token from uid', (done) => {
makePreviewToken(tokenUID)
.delete()
.then((data) => {
expect(data.notice).to.be.equal('Preview token deleted successfully.')
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 makePreviewToken (uid = null) {
return client
.stack({ api_key: process.env.API_KEY })
.deliveryToken(uid)
.previewToken()
}
function makeDeliveryToken (uid = null) {
return client.stack({ api_key: process.env.API_KEY }).deliveryToken(uid)
}