Skip to content

Commit 20e3fde

Browse files
Merge pull request #101 from contentstack/test/cs-43131-basic-sanity-tests
assets, entries, organization, stack tests are added to sanity
2 parents 486d835 + a214262 commit 20e3fde

File tree

13 files changed

+760
-15
lines changed

13 files changed

+760
-15
lines changed
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
import path from 'path'
2+
import { expect } from 'chai'
3+
import { describe, it, setup } from 'mocha'
4+
import { jsonReader, writeDownloadedFile } from '../utility/fileOperations/readwrite'
5+
import { contentstackClient } from '../utility/ContentstackClient.js'
6+
7+
var client = {}
8+
9+
var folderUID = ''
10+
var assetUID = ''
11+
var publishAssetUID = ''
12+
var assetURL = ''
13+
describe('Assets api Test', () => {
14+
setup(() => {
15+
const user = jsonReader('loggedinuser.json')
16+
client = contentstackClient(user.authtoken)
17+
})
18+
19+
it('should asset Upload ', done => {
20+
const asset = {
21+
upload: path.join(__dirname, '../mock/customUpload.html'),
22+
title: 'customasset',
23+
description: 'Custom Asset Desc',
24+
tags: ['Custom']
25+
}
26+
makeAsset().create(asset)
27+
.then((asset) => {
28+
assetUID = asset.uid
29+
assetURL = asset.url
30+
expect(asset.uid).to.be.not.equal(null)
31+
expect(asset.url).to.be.not.equal(null)
32+
expect(asset.filename).to.be.equal('customUpload.html')
33+
expect(asset.title).to.be.equal('customasset')
34+
expect(asset.description).to.be.equal('Custom Asset Desc')
35+
expect(asset.content_type).to.be.equal('text/html')
36+
done()
37+
})
38+
.catch(done)
39+
})
40+
41+
it('should download asset from URL.', done => {
42+
makeAsset().download({ url: assetURL, responseType: 'stream' })
43+
.then((response) => {
44+
writeDownloadedFile(response, 'asset1')
45+
done()
46+
}).catch(done)
47+
})
48+
it('should download asset from fetch details ', done => {
49+
makeAsset(assetUID).fetch()
50+
.then((asset) => asset.download({ responseType: 'stream' }))
51+
.then((response) => {
52+
writeDownloadedFile(response, 'asset2')
53+
done()
54+
}).catch(done)
55+
})
56+
57+
it('should create folder ', done => {
58+
makeAsset().folder().create({ asset: { name: 'Sample Folder' } })
59+
.then((asset) => {
60+
folderUID = asset.uid
61+
expect(asset.uid).to.be.not.equal(null)
62+
expect(asset.name).to.be.equal('Sample Folder')
63+
expect(asset.is_dir).to.be.equal(true)
64+
done()
65+
})
66+
.catch(done)
67+
})
68+
69+
it('should asset Upload in folder', done => {
70+
const asset = {
71+
upload: path.join(__dirname, '../mock/customUpload.html'),
72+
title: 'customasset in Folder',
73+
description: 'Custom Asset Desc in Folder',
74+
parent_uid: folderUID,
75+
tags: 'folder'
76+
}
77+
makeAsset().create(asset)
78+
.then((asset) => {
79+
publishAssetUID = asset.uid
80+
expect(asset.uid).to.be.not.equal(null)
81+
expect(asset.url).to.be.not.equal(null)
82+
expect(asset.filename).to.be.equal('customUpload.html')
83+
expect(asset.title).to.be.equal('customasset in Folder')
84+
expect(asset.description).to.be.equal('Custom Asset Desc in Folder')
85+
expect(asset.content_type).to.be.equal('text/html')
86+
expect(asset.parent_uid).to.be.equal(folderUID)
87+
done()
88+
})
89+
.catch(done)
90+
})
91+
92+
it('should asset Upload in folder with contenttype', done => {
93+
const asset = {
94+
upload: path.join(__dirname, '../mock/berries.jfif'),
95+
title: 'customasset2 in Folder',
96+
description: 'Custom Asset Desc in Folder',
97+
parent_uid: folderUID,
98+
tags: 'folder',
99+
content_type: 'image/jpeg'
100+
}
101+
makeAsset().create(asset)
102+
.then((asset) => {
103+
publishAssetUID = asset.uid
104+
expect(asset.uid).to.be.not.equal(null)
105+
expect(asset.url).to.be.not.equal(null)
106+
expect(asset.filename).to.be.equal('berries.jfif')
107+
expect(asset.title).to.be.equal('customasset2 in Folder')
108+
expect(asset.description).to.be.equal('Custom Asset Desc in Folder')
109+
expect(asset.content_type).to.be.equal('image/jpeg')
110+
expect(asset.parent_uid).to.be.equal(folderUID)
111+
done()
112+
})
113+
.catch(done)
114+
})
115+
it('should replace asset ', done => {
116+
const asset = {
117+
upload: path.join(__dirname, '../mock/upload.html')
118+
}
119+
makeAsset(assetUID)
120+
.replace(asset)
121+
.then((asset) => {
122+
expect(asset.uid).to.be.equal(assetUID)
123+
expect(asset.filename).to.be.equal('upload.html')
124+
expect(asset.content_type).to.be.equal('text/html')
125+
done()
126+
})
127+
.catch(done)
128+
})
129+
130+
it('should fetch and Update asset details', done => {
131+
makeAsset(assetUID)
132+
.fetch()
133+
.then((asset) => {
134+
asset.title = 'Update title'
135+
asset.description = 'Update description'
136+
delete asset.ACL
137+
return asset.update()
138+
})
139+
.then((asset) => {
140+
expect(asset.uid).to.be.equal(assetUID)
141+
expect(asset.title).to.be.equal('Update title')
142+
expect(asset.description).to.be.equal('Update description')
143+
done()
144+
})
145+
.catch(done)
146+
})
147+
148+
it('should publish Asset', done => {
149+
makeAsset(publishAssetUID)
150+
.publish({ publishDetails: {
151+
locales: ['hi-in', 'en-us'],
152+
environments: ['development']
153+
} })
154+
.then((data) => {
155+
expect(data.notice).to.be.equal('Asset sent for publishing.')
156+
done()
157+
})
158+
.catch(done)
159+
})
160+
161+
it('should unpublish Asset', done => {
162+
makeAsset(publishAssetUID)
163+
.unpublish({ publishDetails: {
164+
locales: ['hi-in', 'en-us'],
165+
environments: ['development']
166+
} })
167+
.then((data) => {
168+
expect(data.notice).to.be.equal('Asset sent for unpublishing.')
169+
done()
170+
})
171+
.catch(done)
172+
})
173+
174+
it('should delete asset', done => {
175+
makeAsset(assetUID)
176+
.delete()
177+
.then((data) => {
178+
expect(data.notice).to.be.equal('Asset deleted successfully.')
179+
done()
180+
})
181+
.catch(done)
182+
})
183+
184+
it('should query to fetch all asset', done => {
185+
makeAsset()
186+
.query()
187+
.find()
188+
.then((collection) => {
189+
collection.items.forEach((asset) => {
190+
expect(asset.uid).to.be.not.equal(null)
191+
expect(asset.title).to.be.not.equal(null)
192+
expect(asset.description).to.be.not.equal(null)
193+
})
194+
done()
195+
})
196+
.catch(done)
197+
})
198+
199+
it('should query to fetch title match asset', done => {
200+
makeAsset()
201+
.query({ query: { title: 'Update title' } })
202+
.find()
203+
.then((collection) => {
204+
collection.items.forEach((asset) => {
205+
expect(asset.uid).to.be.not.equal(null)
206+
expect(asset.title).to.be.equal('Update title')
207+
expect(asset.description).to.be.equal('Update description')
208+
})
209+
done()
210+
})
211+
.catch(done)
212+
})
213+
})
214+
215+
function makeAsset (uid = null) {
216+
return client.stack({ api_key: process.env.API_KEY }).asset(uid)
217+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('Content Type delete api Test', () => {
1212
client = contentstackClient(user.authtoken)
1313
})
1414

15-
it('Content Type delete', done => {
15+
it('should content Type delete', done => {
1616
makeContentType(multiPageCT.content_type.uid)
1717
.delete().then((data) => {
1818
expect(data.notice).to.be.equal('Content Type deleted successfully.')

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('Content Type api Test', () => {
1515
client = contentstackClient(user.authtoken)
1616
})
1717

18-
it('Create Single page ContentType Schema', done => {
18+
it('should create Single page ContentType Schema', done => {
1919
makeContentType()
2020
.create(singlepageCT)
2121
.then((contentType) => {
@@ -26,7 +26,7 @@ describe('Content Type api Test', () => {
2626
.catch(done)
2727
})
2828

29-
it('Create Multi page ContentType Schema', done => {
29+
it('should create Multi page ContentType Schema', done => {
3030
makeContentType()
3131
.create(multiPageCT)
3232
.then((contentType) => {
@@ -38,7 +38,7 @@ describe('Content Type api Test', () => {
3838
.catch(done)
3939
})
4040

41-
it('Get all ContentType', done => {
41+
it('should get all ContentType', done => {
4242
makeContentType()
4343
.query()
4444
.find()
@@ -53,7 +53,7 @@ describe('Content Type api Test', () => {
5353
.catch(done)
5454
})
5555

56-
it('Query ContentType title', done => {
56+
it('should query ContentType title', done => {
5757
makeContentType()
5858
.query({ query: { title: singlepageCT.content_type.title } })
5959
.find()
@@ -70,7 +70,7 @@ describe('Content Type api Test', () => {
7070
.catch(done)
7171
})
7272

73-
it('Fetch ContentType from uid', done => {
73+
it('should fetch ContentType from uid', done => {
7474
makeContentType(multiPageCT.content_type.uid)
7575
.fetch()
7676
.then((contentType) => {
@@ -81,7 +81,7 @@ describe('Content Type api Test', () => {
8181
.catch(done)
8282
})
8383

84-
it('Fetch and Update ContentType schema', done => {
84+
it('should fetch and Update ContentType schema', done => {
8585
makeContentType(multiPageCTUid)
8686
.fetch()
8787
.then((contentType) => {
@@ -95,7 +95,7 @@ describe('Content Type api Test', () => {
9595
.catch(done)
9696
})
9797

98-
it('Import content type', done => {
98+
it('should import content type', done => {
9999
makeContentType().import({
100100
content_type: path.join(__dirname, '../mock/contentType.json')
101101
})
@@ -107,7 +107,7 @@ describe('Content Type api Test', () => {
107107
.catch(done)
108108
})
109109

110-
it('Delete ContentTypes', done => {
110+
it('should delete ContentTypes', done => {
111111
makeContentType(importCTUid)
112112
.delete()
113113
.then((contentType) => {

0 commit comments

Comments
 (0)