Skip to content

Commit

Permalink
test: ✅ updated and added search and move api test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithad0703 committed Sep 29, 2023
1 parent 3e1a329 commit 8a1d475
Showing 1 changed file with 91 additions and 43 deletions.
134 changes: 91 additions & 43 deletions test/api/terms-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { contentstackClient } from '../utility/ContentstackClient.js'
var client = {}
var stack = {}

const taxonomy_uid = 'taxonomy_21'
const taxonomy_uid = ''
const term_uid = ''
const term = {
term: {
uid: 'term_test',
Expand All @@ -23,67 +24,114 @@ describe('Terms API Test', () => {
})

it('Create term', async () => {
const response = await makeTerms().create([{ term }])
console.log(response)
expect(response.notice).to.be.equal('Term created successfully.')
expect(response.uid).to.be.equal(term.term.uid)
try {
const response = await makeTerms(taxonomy_uid).create(term)
expect(response.notice).to.be.equal('Term created successfully.')
expect(response.uid).to.be.equal(term.term.uid)
} catch (err) {
console.log(err)
}
})

it('Query and get all terms', async () => {
const response = await makeTerms().query().find()
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)
try {
const response = await makeTerms(taxonomy_uid).query().find()
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)
} catch (err) {
console.log(err)
}
})

it('Fetch term from UID', async () => {
const termsUid = 'fashion'
const response = await makeTerms(termsUid).fetch()
expect(response.uid).to.be.equal(termsUid)
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)
try {
const response = await makeTerms(taxonomy_uid, term_uid).fetch()
expect(response.uid).to.be.equal(term_uid)
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)
} catch (err) {
console.log(err)
}
})

it('Update term', async () => {
const termsUid = 'fashion'
const response = await makeTerms(termsUid).fetch()
.then((term) => {
term.name = 'fashion'
return term.update()
})
expect(response.notice).to.be.equal('Term updated successfully.')
expect(response.uid).to.be.equal(termsUid)
expect(response.name).to.be.equal('fashion')
expect(response.created_by).not.to.be.equal(null)
expect(response.updated_by).not.to.be.equal(null)
try {
const response = await makeTerms(taxonomy_uid, term_uid).fetch()
.then((term) => {
term.name = 'fashion'
return term.update()
})
expect(response.notice).to.be.equal('Term updated successfully.')
expect(response.uid).to.be.equal(term_uid)
expect(response.name).to.be.equal('fashion')
expect(response.created_by).not.to.be.equal(null)
expect(response.updated_by).not.to.be.equal(null)
} catch (err) {
console.log(err)
}
})

it('Delete term from UID', async () => {
const termsUid = 'testing'
const response = await makeTerms(termsUid).delete()
expect(response.notice).to.be.equal('')
try {
const response = await makeTerms(term_uid).delete()
expect(response.notice).to.be.equal('')
} catch (err) {
console.log(err)
}
})

it('Ancestors of the term given', async () => {
const termsUid = 'term_3'
const response = await makeTerms(termsUid).ancestors()
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)
try {
const response = await makeTerms(taxonomy_uid, term_uid).ancestors()
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)
} catch (err) {
console.log(err)
}
})

it('Descendants of the term given', async () => {
const termsUid = 'term_3'
const response = await makeTerms(termsUid).descendants()
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)
try {
const response = await makeTerms(taxonomy_uid, term_uid).descendants()
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)
} catch (err) {
console.log(err)
}
})
it('search term', async () => {
term_string = ''
try {
const response = await makeTerms(taxonomy_uid).search(term_string)
expect(response.terms).to.be.an('array')
} catch (err) {
console.log(err)
}
})
it('move term', async () => {
try {
const term = {
parent_uid: 'parent_uid',
order: 2
}
await makeTerms(taxonomy_uid, term_uid).move({ term })
.then((term) => {
term.parent_uid = 'parent_uid'
console.log(term.move())
return term.move()
})
} catch (err) {
console.log(err)
}
})
})

function makeTerms (uid = '') {
return client.stack({ api_key: stack.api_key }).taxonomy(taxonomy_uid).terms(uid)
function makeTerms (taxonomy_uid, term_uid = null) {
return client.stack({ api_key: stack.api_key }).taxonomy(taxonomy_uid).terms(term_uid)
}

0 comments on commit 8a1d475

Please sign in to comment.