-
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.
Merge pull request #102 from contentstack/test/cs-43154-sanity-test-t…
…axonomy-terms sanity test for taxonomy and terms
- Loading branch information
Showing
4 changed files
with
263 additions
and
1 deletion.
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,86 @@ | ||
import { expect } from 'chai' | ||
import { describe, it, setup } from 'mocha' | ||
import { jsonReader } from '../utility/fileOperations/readwrite' | ||
import { contentstackClient } from '../utility/ContentstackClient.js' | ||
|
||
var client = {} | ||
var stack = {} | ||
|
||
const taxonomy = { | ||
uid: 'taxonomy_testing', | ||
name: 'taxonomy testing', | ||
description: 'Description for Taxonomy testing' | ||
} | ||
|
||
var taxonomyUID = '' | ||
|
||
describe('taxonomy api Test', () => { | ||
setup(() => { | ||
const user = jsonReader('loggedinuser.json') | ||
stack = jsonReader('stack.json') | ||
client = contentstackClient(user.authtoken) | ||
}) | ||
|
||
it('should create taxonomy', done => { | ||
makeTaxonomy() | ||
.create({ taxonomy }) | ||
.then((taxonomyResponse) => { | ||
taxonomyUID = taxonomyResponse.uid | ||
expect(taxonomyResponse.name).to.be.equal(taxonomy.name) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('should fetch taxonomy of the uid passe', done => { | ||
makeTaxonomy(taxonomyUID) | ||
.fetch() | ||
.then((taxonomyResponse) => { | ||
expect(taxonomyResponse.uid).to.be.equal(taxonomyUID) | ||
expect(taxonomyResponse.name).to.be.not.equal(null) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('should update taxonomy of the uid passed', done => { | ||
makeTaxonomy(taxonomyUID) | ||
.fetch() | ||
.then((taxonomyResponse) => { | ||
taxonomyResponse.name = 'Updated Name' | ||
return taxonomyResponse.update() | ||
}) | ||
.then((taxonomyResponse) => { | ||
expect(taxonomyResponse.uid).to.be.equal(taxonomyUID) | ||
expect(taxonomyResponse.name).to.be.equal('Updated Name') | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('should get all taxonomies', async () => { | ||
makeTaxonomy() | ||
.query() | ||
.find() | ||
.then((response) => { | ||
response.items.forEach((taxonomyResponse) => { | ||
expect(taxonomyResponse.uid).to.be.not.equal(null) | ||
expect(taxonomyResponse.name).to.be.not.equal(null) | ||
}) | ||
}) | ||
}) | ||
|
||
it('should delete taxonomy from uid', done => { | ||
makeTaxonomy(taxonomyUID) | ||
.delete() | ||
.then((taxonomyResponse) => { | ||
expect(taxonomyResponse.status).to.be.equal(204) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
}) | ||
|
||
function makeTaxonomy (uid = null) { | ||
return client.stack({ api_key: stack.api_key }).taxonomy(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,174 @@ | ||
import { describe, it, beforeEach } from 'mocha' | ||
import { expect } from 'chai' | ||
import { jsonReader } from '../utility/fileOperations/readwrite' | ||
import { contentstackClient } from '../utility/ContentstackClient.js' | ||
|
||
var client = {} | ||
|
||
const taxonomy = { | ||
uid: 'taxonomy_testing', | ||
name: 'taxonomy testing', | ||
description: 'Description for Taxonomy testing' | ||
} | ||
const termString = 'term' | ||
const term = { | ||
term: { | ||
uid: 'term_test', | ||
name: 'Term test', | ||
parent_uid: null | ||
} | ||
} | ||
const childTerm1 = { | ||
term: { | ||
uid: 'term_test_child1', | ||
name: 'Term test1', | ||
parent_uid: 'term_test' | ||
} | ||
} | ||
const childTerm2 = { | ||
term: { | ||
uid: 'term_test_child2', | ||
name: 'Term test2', | ||
parent_uid: 'term_test_child1' | ||
} | ||
} | ||
var termUid = term.term.uid | ||
|
||
describe('Terms API Test', () => { | ||
beforeEach(() => { | ||
const user = jsonReader('loggedinuser.json') | ||
client = contentstackClient(user.authtoken) | ||
}) | ||
it('should create taxonomy', async () => { | ||
await client.stack({ api_key: process.env.API_KEY }).taxonomy().create({ taxonomy }) | ||
}) | ||
|
||
it('should create term', done => { | ||
makeTerms(taxonomy.uid).create(term) | ||
.then((response) => { | ||
expect(response.uid).to.be.equal(term.term.uid) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('should create child term 1', done => { | ||
makeTerms(taxonomy.uid).create(childTerm1) | ||
.then((response) => { | ||
expect(response.uid).to.be.equal(childTerm1.term.uid) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('should create child term 2', done => { | ||
makeTerms(taxonomy.uid).create(childTerm2) | ||
.then((response) => { | ||
expect(response.uid).to.be.equal(childTerm2.term.uid) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('should query and get all terms', done => { | ||
makeTerms(taxonomy.uid).query().find() | ||
.then((response) => { | ||
expect(response.items).to.be.an('array') | ||
expect(response.items[0].uid).not.to.be.equal(null) | ||
expect(response.items[0].name).not.to.be.equal(null) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('should fetch term of the term uid passed', done => { | ||
makeTerms(taxonomy.uid, term.term.uid).fetch() | ||
.then((response) => { | ||
expect(response.uid).to.be.equal(termUid) | ||
expect(response.name).not.to.be.equal(null) | ||
expect(response.created_by).not.to.be.equal(null) | ||
expect(response.updated_by).not.to.be.equal(null) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('should update term of the term uid passed', done => { | ||
makeTerms(taxonomy.uid, termUid).fetch() | ||
.then((term) => { | ||
term.name = 'update name' | ||
return term.update() | ||
}) | ||
.then((response) => { | ||
expect(response.uid).to.be.equal(termUid) | ||
expect(response.name).to.be.equal('update name') | ||
expect(response.created_by).not.to.be.equal(null) | ||
expect(response.updated_by).not.to.be.equal(null) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('should get the ancestors of the term uid passed', done => { | ||
makeTerms(taxonomy.uid, childTerm1.term.uid).ancestors() | ||
.then((response) => { | ||
expect(response.terms[0].uid).not.to.be.equal(null) | ||
expect(response.terms[0].name).not.to.be.equal(null) | ||
expect(response.terms[0].created_by).not.to.be.equal(null) | ||
expect(response.terms[0].updated_by).not.to.be.equal(null) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('should get the descendants of the term uid passed', done => { | ||
makeTerms(taxonomy.uid, childTerm1.term.uid).descendants() | ||
.then((response) => { | ||
expect(response.terms.uid).not.to.be.equal(null) | ||
expect(response.terms.name).not.to.be.equal(null) | ||
expect(response.terms.created_by).not.to.be.equal(null) | ||
expect(response.terms.updated_by).not.to.be.equal(null) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('should search the term with the string passed', done => { | ||
makeTerms(taxonomy.uid).search(termString) | ||
.then((response) => { | ||
expect(response.terms).to.be.an('array') | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('should move the term to parent uid passed', done => { | ||
makeTerms(taxonomy.uid, childTerm2.term.uid).move({ force: true }) | ||
.then(async (term) => { | ||
term.parent_uid = null | ||
const moveTerm = await term.move({ force: true }) | ||
expect(moveTerm.parent_uid).to.be.equal(null) | ||
done() | ||
return moveTerm | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('should delete of the term uid passed', done => { | ||
makeTerms(taxonomy.uid, term.term.uid).delete({ force: true }) | ||
.then((response) => { | ||
expect(response.status).to.be.equal(204) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('should delete taxonomy', async () => { | ||
const taxonomyResponse = await client.stack({ api_key: process.env.API_KEY }).taxonomy(taxonomy.uid).delete({ force: true }) | ||
expect(taxonomyResponse.status).to.be.equal(204) | ||
}) | ||
}) | ||
|
||
function makeTerms (taxonomyUid, termUid = null) { | ||
return client.stack({ api_key: process.env.API_KEY }).taxonomy(taxonomyUid).terms(termUid) | ||
} |
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