Skip to content

Commit 52c8786

Browse files
Merge pull request #100 from contentstack/test/cs-43014-cms-sanity-readiness
basic sanity tests for user and contenttype
2 parents 9ed7a91 + 508aa7a commit 52c8786

File tree

10 files changed

+495
-0
lines changed

10 files changed

+495
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jspm_packages/
3939
mochawesome-report/
4040
coverage/
4141
test/utility/dataFiles/
42+
test/sanity-check/utility/dataFiles/
4243
report.json
4344

4445
# TypeScript v1 declaration files

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"buildnativescript": "webpack --config webpack/webpack.nativescript.js --mode production",
3131
"buildweb": "webpack --config webpack/webpack.web.js --mode production",
3232
"test": "npm run test:api && npm run test:unit",
33+
"test:sanity": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/sanity-check/sanity.js -t 30000 --reporter mochawesome --require babel-polyfill",
3334
"test:api": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/test.js -t 30000 --reporter mochawesome --require babel-polyfill",
3435
"test:unit": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/unit/index.js -t 30000 --reporter mochawesome --require babel-polyfill",
3536
"test:unit:report:json": "BABEL_ENV=test nyc --reporter=clover --reporter=text mocha --require @babel/register ./test/unit/index.js -t 30000 --reporter json --reporter-options output=report.json --require babel-polyfill",
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { expect } from 'chai'
2+
import { describe, it, setup } from 'mocha'
3+
import { jsonReader } from '../utility/fileOperations/readwrite'
4+
import { multiPageCT, singlepageCT } from '../mock/content-type'
5+
import { contentstackClient } from '../utility/ContentstackClient'
6+
7+
var client = {}
8+
9+
describe('Content Type delete api Test', () => {
10+
setup(() => {
11+
const user = jsonReader('loggedinuser.json')
12+
client = contentstackClient(user.authtoken)
13+
})
14+
15+
it('Content Type delete', done => {
16+
makeContentType(multiPageCT.content_type.uid)
17+
.delete().then((data) => {
18+
expect(data.notice).to.be.equal('Content Type deleted successfully.')
19+
done()
20+
})
21+
makeContentType(singlepageCT.content_type.uid).delete()
22+
.catch(done)
23+
})
24+
})
25+
26+
function makeContentType (uid = null) {
27+
return client.stack({ api_key: process.env.API_KEY }).contentType(uid)
28+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import path from 'path'
2+
import { expect } from 'chai'
3+
import { describe, it, setup } from 'mocha'
4+
import { jsonReader } from '../utility/fileOperations/readwrite.js'
5+
import { singlepageCT, multiPageCT, schema } from '../mock/content-type.js'
6+
import { contentstackClient } from '../utility/ContentstackClient.js'
7+
8+
let client = {}
9+
let multiPageCTUid = ''
10+
let importCTUid = ''
11+
12+
describe('Content Type api Test', () => {
13+
setup(() => {
14+
const user = jsonReader('loggedinuser.json')
15+
client = contentstackClient(user.authtoken)
16+
})
17+
18+
it('Create Single page ContentType Schema', done => {
19+
makeContentType()
20+
.create(singlepageCT)
21+
.then((contentType) => {
22+
expect(contentType.uid).to.be.equal(singlepageCT.content_type.uid)
23+
expect(contentType.title).to.be.equal(singlepageCT.content_type.title)
24+
done()
25+
})
26+
.catch(done)
27+
})
28+
29+
it('Create Multi page ContentType Schema', done => {
30+
makeContentType()
31+
.create(multiPageCT)
32+
.then((contentType) => {
33+
multiPageCTUid = contentType.uid
34+
expect(contentType.uid).to.be.equal(multiPageCT.content_type.uid)
35+
expect(contentType.title).to.be.equal(multiPageCT.content_type.title)
36+
done()
37+
})
38+
.catch(done)
39+
})
40+
41+
it('Get all ContentType', done => {
42+
makeContentType()
43+
.query()
44+
.find()
45+
.then((response) => {
46+
response.items.forEach(contentType => {
47+
expect(contentType.uid).to.be.not.equal(null)
48+
expect(contentType.title).to.be.not.equal(null)
49+
expect(contentType.schema).to.be.not.equal(null)
50+
})
51+
done()
52+
})
53+
.catch(done)
54+
})
55+
56+
it('Query ContentType title', done => {
57+
makeContentType()
58+
.query({ query: { title: singlepageCT.content_type.title } })
59+
.find()
60+
.then((response) => {
61+
response.items.forEach(contentType => {
62+
expect(contentType.uid).to.be.not.equal(null)
63+
expect(contentType.title).to.be.not.equal(null)
64+
expect(contentType.schema).to.be.not.equal(null)
65+
expect(contentType.uid).to.be.equal(singlepageCT.content_type.uid, 'UID not mathcing')
66+
expect(contentType.title).to.be.equal(singlepageCT.content_type.title, 'Title not mathcing')
67+
})
68+
done()
69+
})
70+
.catch(done)
71+
})
72+
73+
it('Fetch ContentType from uid', done => {
74+
makeContentType(multiPageCT.content_type.uid)
75+
.fetch()
76+
.then((contentType) => {
77+
expect(contentType.uid).to.be.equal(multiPageCT.content_type.uid)
78+
expect(contentType.title).to.be.equal(multiPageCT.content_type.title)
79+
done()
80+
})
81+
.catch(done)
82+
})
83+
84+
it('Fetch and Update ContentType schema', done => {
85+
makeContentType(multiPageCTUid)
86+
.fetch()
87+
.then((contentType) => {
88+
contentType.schema = schema
89+
return contentType.update()
90+
})
91+
.then((contentType) => {
92+
expect(contentType.schema.length).to.be.equal(6)
93+
done()
94+
})
95+
.catch(done)
96+
})
97+
98+
it('Import content type', done => {
99+
makeContentType().import({
100+
content_type: path.join(__dirname, '../mock/contentType.json')
101+
})
102+
.then((response) => {
103+
importCTUid = response.uid
104+
expect(response.uid).to.be.not.equal(null)
105+
done()
106+
})
107+
.catch(done)
108+
})
109+
110+
it('Delete ContentTypes', done => {
111+
makeContentType(importCTUid)
112+
.delete()
113+
.then((contentType) => {
114+
expect(contentType.notice).to.be.equal('Content Type deleted successfully.')
115+
done()
116+
})
117+
.catch(done)
118+
})
119+
})
120+
121+
function makeContentType (uid = null) {
122+
return client.stack({ api_key: process.env.API_KEY }).contentType(uid)
123+
}

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

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { expect } from 'chai'
2+
import { describe, it } from 'mocha'
3+
import { contentstackClient } from '../../utility/ContentstackClient'
4+
import { jsonWrite } from '../../utility/fileOperations/readwrite'
5+
import axios from 'axios'
6+
import dotenv from 'dotenv'
7+
8+
dotenv.config()
9+
var authtoken = ''
10+
var loggedinUserID = ''
11+
var client = contentstackClient()
12+
describe('Contentstack User Session api Test', () => {
13+
it('User login wrong credentials', done => {
14+
contentstackClient().login({ email: process.env.EMAIL, password: process.env.PASSWORD })
15+
.then((response) => {
16+
done()
17+
}).catch((error) => {
18+
const jsonMessage = JSON.parse(error.message)
19+
const payload = JSON.parse(jsonMessage.request.data)
20+
expect(jsonMessage.status).to.be.equal(422, 'Status code does not match')
21+
expect(jsonMessage.errorMessage).to.not.equal(null, 'Error message not proper')
22+
expect(jsonMessage.errorCode).to.be.equal(104, 'Error code does not match')
23+
expect(payload.user.email).to.be.equal(process.env.EMAIL, 'Email id does not match')
24+
expect(payload.user.password).to.be.equal('contentstack', 'Password does not match')
25+
done()
26+
})
27+
})
28+
29+
it('User Login test', done => {
30+
client.login({ email: process.env.EMAIL, password: process.env.PASSWORD }, { include_orgs: true, include_orgs_roles: true, include_stack_roles: true, include_user_settings: true }).then((response) => {
31+
jsonWrite(response.user, 'loggedinuser.json')
32+
expect(response.notice).to.be.equal('Login Successful.', 'Login success messsage does not match.')
33+
done()
34+
})
35+
.catch(done)
36+
})
37+
38+
it('User logout test', done => {
39+
client.logout()
40+
.then((response) => {
41+
expect(axios.defaults.headers.common.authtoken).to.be.equal(undefined)
42+
expect(response.notice).to.be.equal('You\'ve logged out successfully.')
43+
done()
44+
})
45+
.catch(done)
46+
})
47+
48+
it('User login with credentials', done => {
49+
client.login({ email: process.env.EMAIL, password: process.env.PASSWORD }, { include_orgs: true, include_orgs_roles: true, include_stack_roles: true, include_user_settings: true }).then((response) => {
50+
loggedinUserID = response.user.uid
51+
jsonWrite(response.user, 'loggedinuser.json')
52+
expect(response.notice).to.be.equal('Login Successful.', 'Login success messsage does not match.')
53+
done()
54+
})
55+
.catch(done)
56+
})
57+
58+
it('Get Current user info test', done => {
59+
client.getUser().then((user) => {
60+
authtoken = user.authtoken
61+
expect(user.uid).to.be.equal(loggedinUserID)
62+
done()
63+
})
64+
.catch(done)
65+
})
66+
67+
it('Get user info from authtoken', done => {
68+
contentstackClient(authtoken)
69+
.getUser()
70+
.then((user) => {
71+
expect(user.uid).to.be.equal(loggedinUserID)
72+
expect(true).to.be.equal(true)
73+
done()
74+
})
75+
.catch(done)
76+
})
77+
})

0 commit comments

Comments
 (0)