-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added sanity tests for user and contenttype
- Loading branch information
1 parent
53d7458
commit 701bc1e
Showing
9 changed files
with
494 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |
Oops, something went wrong.