Skip to content
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

sanity test for label #121

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions test/sanity-check/api/contentType-delete-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 0 additions & 12 deletions test/sanity-check/api/contentType-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { contentstackClient } from '../utility/ContentstackClient.js'

let client = {}
let multiPageCTUid = ''
let importCTUid = ''

describe('Content Type api Test', () => {
setup(() => {
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion test/sanity-check/api/delete-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,3 @@ function makeDeliveryToken (uid = null) {
function makeBranchAlias (uid = null) {
return client.stack({ api_key: process.env.API_KEY }).branchAlias(uid)
}

137 changes: 137 additions & 0 deletions test/sanity-check/api/label-test.js
Original file line number Diff line number Diff line change
@@ -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)
}
6 changes: 6 additions & 0 deletions test/sanity-check/sanity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Loading