Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jspm_packages/
mochawesome-report/
coverage/
test/utility/dataFiles/
test/sanity-check/utility/dataFiles/
report.json

# TypeScript v1 declaration files
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"buildnativescript": "webpack --config webpack/webpack.nativescript.js --mode production",
"buildweb": "webpack --config webpack/webpack.web.js --mode production",
"test": "npm run test:api && npm run test:unit",
"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",
"test:api": "BABEL_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/register ./test/test.js -t 30000 --reporter mochawesome --require babel-polyfill",
"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",
"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",
Expand Down
28 changes: 28 additions & 0 deletions test/sanity-check/api/contentType-delete-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { expect } from 'chai'
import { describe, it, setup } from 'mocha'
import { jsonReader } from '../utility/fileOperations/readwrite'
import { multiPageCT, singlepageCT } from '../mock/content-type'
import { contentstackClient } from '../utility/ContentstackClient'

var client = {}

describe('Content Type delete api Test', () => {
setup(() => {
const user = jsonReader('loggedinuser.json')
client = contentstackClient(user.authtoken)
})

it('Content Type delete', done => {
makeContentType(multiPageCT.content_type.uid)
.delete().then((data) => {
expect(data.notice).to.be.equal('Content Type deleted successfully.')
done()
})
makeContentType(singlepageCT.content_type.uid).delete()
.catch(done)
})
})

function makeContentType (uid = null) {
return client.stack({ api_key: process.env.API_KEY }).contentType(uid)
}
123 changes: 123 additions & 0 deletions test/sanity-check/api/contentType-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import path from 'path'
import { expect } from 'chai'
import { describe, it, setup } from 'mocha'
import { jsonReader } from '../utility/fileOperations/readwrite.js'
import { singlepageCT, multiPageCT, schema } from '../mock/content-type.js'
import { contentstackClient } from '../utility/ContentstackClient.js'

let client = {}
let multiPageCTUid = ''
let importCTUid = ''

describe('Content Type api Test', () => {
setup(() => {
const user = jsonReader('loggedinuser.json')
client = contentstackClient(user.authtoken)
})

it('Create Single page ContentType Schema', done => {
makeContentType()
.create(singlepageCT)
.then((contentType) => {
expect(contentType.uid).to.be.equal(singlepageCT.content_type.uid)
expect(contentType.title).to.be.equal(singlepageCT.content_type.title)
done()
})
.catch(done)
})

it('Create Multi page ContentType Schema', done => {
makeContentType()
.create(multiPageCT)
.then((contentType) => {
multiPageCTUid = contentType.uid
expect(contentType.uid).to.be.equal(multiPageCT.content_type.uid)
expect(contentType.title).to.be.equal(multiPageCT.content_type.title)
done()
})
.catch(done)
})

it('Get all ContentType', done => {
makeContentType()
.query()
.find()
.then((response) => {
response.items.forEach(contentType => {
expect(contentType.uid).to.be.not.equal(null)
expect(contentType.title).to.be.not.equal(null)
expect(contentType.schema).to.be.not.equal(null)
})
done()
})
.catch(done)
})

it('Query ContentType title', done => {
makeContentType()
.query({ query: { title: singlepageCT.content_type.title } })
.find()
.then((response) => {
response.items.forEach(contentType => {
expect(contentType.uid).to.be.not.equal(null)
expect(contentType.title).to.be.not.equal(null)
expect(contentType.schema).to.be.not.equal(null)
expect(contentType.uid).to.be.equal(singlepageCT.content_type.uid, 'UID not mathcing')
expect(contentType.title).to.be.equal(singlepageCT.content_type.title, 'Title not mathcing')
})
done()
})
.catch(done)
})

it('Fetch ContentType from uid', done => {
makeContentType(multiPageCT.content_type.uid)
.fetch()
.then((contentType) => {
expect(contentType.uid).to.be.equal(multiPageCT.content_type.uid)
expect(contentType.title).to.be.equal(multiPageCT.content_type.title)
done()
})
.catch(done)
})

it('Fetch and Update ContentType schema', done => {
makeContentType(multiPageCTUid)
.fetch()
.then((contentType) => {
contentType.schema = schema
return contentType.update()
})
.then((contentType) => {
expect(contentType.schema.length).to.be.equal(6)
done()
})
.catch(done)
})

it('Import content type', done => {
makeContentType().import({
content_type: path.join(__dirname, '../mock/contentType.json')
})
.then((response) => {
importCTUid = response.uid
expect(response.uid).to.be.not.equal(null)
done()
})
.catch(done)
})

it('Delete ContentTypes', done => {
makeContentType(importCTUid)
.delete()
.then((contentType) => {
expect(contentType.notice).to.be.equal('Content Type deleted successfully.')
done()
})
.catch(done)
})
})

function makeContentType (uid = null) {
return client.stack({ api_key: process.env.API_KEY }).contentType(uid)
}
77 changes: 77 additions & 0 deletions test/sanity-check/api/user-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { expect } from 'chai'
import { describe, it } from 'mocha'
import { contentstackClient } from '../../utility/ContentstackClient'
import { jsonWrite } from '../../utility/fileOperations/readwrite'
import axios from 'axios'
import dotenv from 'dotenv'

dotenv.config()
var authtoken = ''
var loggedinUserID = ''
var client = contentstackClient()
describe('Contentstack User Session api Test', () => {
it('User login wrong credentials', done => {
contentstackClient().login({ email: process.env.EMAIL, password: process.env.PASSWORD })
.then((response) => {
done()
}).catch((error) => {
const jsonMessage = JSON.parse(error.message)
const payload = JSON.parse(jsonMessage.request.data)
expect(jsonMessage.status).to.be.equal(422, 'Status code does not match')
expect(jsonMessage.errorMessage).to.not.equal(null, 'Error message not proper')
expect(jsonMessage.errorCode).to.be.equal(104, 'Error code does not match')
expect(payload.user.email).to.be.equal(process.env.EMAIL, 'Email id does not match')
expect(payload.user.password).to.be.equal('contentstack', 'Password does not match')
done()
})
})

it('User Login test', done => {
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) => {
jsonWrite(response.user, 'loggedinuser.json')
expect(response.notice).to.be.equal('Login Successful.', 'Login success messsage does not match.')
done()
})
.catch(done)
})

it('User logout test', done => {
client.logout()
.then((response) => {
expect(axios.defaults.headers.common.authtoken).to.be.equal(undefined)
expect(response.notice).to.be.equal('You\'ve logged out successfully.')
done()
})
.catch(done)
})

it('User login with credentials', done => {
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) => {
loggedinUserID = response.user.uid
jsonWrite(response.user, 'loggedinuser.json')
expect(response.notice).to.be.equal('Login Successful.', 'Login success messsage does not match.')
done()
})
.catch(done)
})

it('Get Current user info test', done => {
client.getUser().then((user) => {
authtoken = user.authtoken
expect(user.uid).to.be.equal(loggedinUserID)
done()
})
.catch(done)
})

it('Get user info from authtoken', done => {
contentstackClient(authtoken)
.getUser()
.then((user) => {
expect(user.uid).to.be.equal(loggedinUserID)
expect(true).to.be.equal(true)
done()
})
.catch(done)
})
})
Loading