-
Notifications
You must be signed in to change notification settings - Fork 9
basic sanity tests for user and contenttype #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.