diff --git a/test/sanity-check/api/contentType-delete-test.js b/test/sanity-check/api/contentType-delete-test.js index 148a48ce..2802afb9 100644 --- a/test/sanity-check/api/contentType-delete-test.js +++ b/test/sanity-check/api/contentType-delete-test.js @@ -21,6 +21,16 @@ describe('Content Type delete api Test', () => { makeContentType(singlepageCT.content_type.uid).delete() .catch(done) }) + + it('should delete ContentTypes', done => { + makeContentType('multi_page_from_json') + .delete() + .then((contentType) => { + expect(contentType.notice).to.be.equal('Content Type deleted successfully.') + done() + }) + .catch(done) + }) }) function makeContentType (uid = null) { diff --git a/test/sanity-check/api/contentType-test.js b/test/sanity-check/api/contentType-test.js index fbb99a0a..7de179bd 100644 --- a/test/sanity-check/api/contentType-test.js +++ b/test/sanity-check/api/contentType-test.js @@ -7,7 +7,6 @@ import { contentstackClient } from '../utility/ContentstackClient.js' let client = {} let multiPageCTUid = '' -let importCTUid = '' describe('Content Type api Test', () => { setup(() => { @@ -100,22 +99,11 @@ describe('Content Type api Test', () => { 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('should 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) { diff --git a/test/sanity-check/api/delete-test.js b/test/sanity-check/api/delete-test.js index 6775266d..6764a85f 100644 --- a/test/sanity-check/api/delete-test.js +++ b/test/sanity-check/api/delete-test.js @@ -138,4 +138,3 @@ function makeDeliveryToken (uid = null) { function makeBranchAlias (uid = null) { return client.stack({ api_key: process.env.API_KEY }).branchAlias(uid) } - diff --git a/test/sanity-check/api/label-test.js b/test/sanity-check/api/label-test.js new file mode 100644 index 00000000..6e2412eb --- /dev/null +++ b/test/sanity-check/api/label-test.js @@ -0,0 +1,137 @@ +import { expect } from 'chai' +import { describe, it, setup } from 'mocha' +import { jsonReader } from '../utility/fileOperations/readwrite.js' +import { singlepageCT } from '../mock/content-type.js' +import { contentstackClient } from '../utility/ContentstackClient.js' +import dotenv from 'dotenv' + +dotenv.config() +let client = {} + +const label = { + name: 'First label', + content_types: [singlepageCT.content_type.uid] +} + +let labelUID = '' +let deleteLabelUID = '' +describe('Label api Test', () => { + setup(() => { + const user = jsonReader('loggedinuser.json') + client = contentstackClient(user.authtoken) + }) + + it('should create a Label', done => { + makeLabel() + .create({ label }) + .then((labelResponse) => { + labelUID = labelResponse.uid + expect(labelResponse.uid).to.be.not.equal(null) + expect(labelResponse.name).to.be.equal(label.name) + expect(labelResponse.content_types[0]).to.be.equal(label.content_types[0]) + done() + }) + .catch(done) + }) + + it('should create Label with parent uid', done => { + const label = { + name: 'With Parent label', + parent: [labelUID], + content_types: [singlepageCT.content_type.uid] + } + makeLabel() + .create({ label }) + .then((labelResponse) => { + deleteLabelUID = labelResponse.uid + expect(labelResponse.uid).to.be.not.equal(null) + expect(labelResponse.name).to.be.equal(label.name) + expect(labelResponse.parent[0]).to.be.equal(label.parent[0]) + expect(labelResponse.content_types[0]).to.be.equal(label.content_types[0]) + done() + }) + .catch(done) + }) + + it('should fetch label from uid', done => { + makeLabel(labelUID) + .fetch() + .then((labelResponse) => { + expect(labelResponse.uid).to.be.equal(labelUID) + expect(labelResponse.name).to.be.equal(label.name) + expect(labelResponse.content_types[0]).to.be.equal(label.content_types[0]) + done() + }) + .catch(done) + }) + + it('should query to get all labels', done => { + makeLabel() + .query({ query: { name: label.name } }) + .find() + .then((response) => { + response.items.forEach((labelResponse) => { + expect(labelResponse.uid).to.be.not.equal(null) + expect(labelResponse.name).to.be.not.equal(null) + expect(labelResponse.content_types).to.be.not.equal(null) + }) + done() + }) + .catch(done) + }) + + it('should query label with name', done => { + makeLabel() + .query({ query: { name: label.name } }) + .find() + .then((response) => { + response.items.forEach((labelResponse) => { + expect(labelResponse.uid).to.be.equal(labelUID) + expect(labelResponse.name).to.be.equal(label.name) + expect(labelResponse.content_types[0]).to.be.equal(label.content_types[0]) + }) + done() + }) + .catch(done) + }) + + it('should fetch and update label from uid', done => { + makeLabel(labelUID) + .fetch() + .then((labelResponse) => { + labelResponse.name = 'Update Name' + return labelResponse.update() + }) + .then((labelResponse) => { + expect(labelResponse.uid).to.be.equal(labelUID) + expect(labelResponse.name).to.be.equal('Update Name') + expect(labelResponse.content_types[0]).to.be.equal(label.content_types[0]) + done() + }) + .catch(done) + }) + + it('should delete parent label from uid', done => { + makeLabel(deleteLabelUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Label deleted successfully.') + done() + }) + .catch(done) + }) + + it('should delete label from uid', done => { + makeLabel(labelUID) + .delete() + .then((data) => { + expect(data.notice).to.be.equal('Label deleted successfully.') + done() + }) + .catch(done) + }) +}) + +function makeLabel (uid = null) { + return client.stack({ api_key: process.env.API_KEY }).label(uid) +} diff --git a/test/sanity-check/sanity.js b/test/sanity-check/sanity.js index cebee4d2..af0acaa7 100644 --- a/test/sanity-check/sanity.js +++ b/test/sanity-check/sanity.js @@ -5,12 +5,18 @@ require('./api/locale-test') require('./api/environment-test') require('./api/branch-test') require('./api/branchAlias-test') +// require('./api/role-test') require('./api/deliveryToken-test') +// require('./api/managementToken-test') require('./api/contentType-test') require('./api/asset-test') require('./api/extension-test') require('./api/entry-test') +// require('./api/webhook-test') +// require('./api/workflow-test') require('./api/globalfield-test') +// require('./api/release-test') +require('./api/label-test') require('./api/contentType-delete-test') require('./api/taxonomy-test') require('./api/terms-test')