diff --git a/test/sanity-check/api/organization-test.js b/test/sanity-check/api/organization-test.js index 80fac458..96ce9852 100644 --- a/test/sanity-check/api/organization-test.js +++ b/test/sanity-check/api/organization-test.js @@ -43,7 +43,7 @@ describe('Organization api test', () => { it('should fetch organization', done => { organization.fetch() .then((organizations) => { - expect(organizations.name).to.be.equal('CLI Dev and Automation', 'Organization name dose not match') + expect(organizations.name).to.be.equal('CLI Branches', 'Organization name dose not match') done() }) .catch(done) diff --git a/test/sanity-check/api/taxonomy-test.js b/test/sanity-check/api/taxonomy-test.js new file mode 100644 index 00000000..3deb99aa --- /dev/null +++ b/test/sanity-check/api/taxonomy-test.js @@ -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) +} diff --git a/test/sanity-check/api/terms-test.js b/test/sanity-check/api/terms-test.js new file mode 100644 index 00000000..ee2b83d2 --- /dev/null +++ b/test/sanity-check/api/terms-test.js @@ -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) +} diff --git a/test/sanity-check/sanity.js b/test/sanity-check/sanity.js index 26273528..7e3581a6 100644 --- a/test/sanity-check/sanity.js +++ b/test/sanity-check/sanity.js @@ -5,3 +5,5 @@ require('./api/contentType-test') require('./api/asset-test') require('./api/entry-test') require('./api/contentType-delete-test') +require('./api/taxonomy-test') +require('./api/terms-test')