|
| 1 | +import { expect } from "chai"; |
| 2 | +import { Stack } from "../../types/stack"; |
| 3 | +var taxonomyUID = '' |
| 4 | +var termUID = '' |
| 5 | +export function testTerm(stack: Stack) { |
| 6 | + describe('Term API test', () => { |
| 7 | + test('Create Term', done => { |
| 8 | + const term = { |
| 9 | + uid: 'term_uid', |
| 10 | + name: 'term name', |
| 11 | + parent_uid: 'parent_uid', |
| 12 | + order: 1 |
| 13 | + } |
| 14 | + stack.taxonomy(taxonomyUID).terms().create({term}) |
| 15 | + .then((termResponse) => { |
| 16 | + expect(termResponse.uid).to.be.equal(term.uid) |
| 17 | + expect(termResponse.name).to.be.equal(term.name) |
| 18 | + done() |
| 19 | + }) |
| 20 | + .catch((err) => { |
| 21 | + console.log(err) |
| 22 | + }) |
| 23 | + }) |
| 24 | + test('Fetch term from uid', done => { |
| 25 | + stack.taxonomy(taxonomyUID).terms(termUID).fetch() |
| 26 | + .then((termResponse) => { |
| 27 | + expect(termResponse.uid).to.be.equal(termUID) |
| 28 | + expect(termResponse.name).not.to.be.equal(null) |
| 29 | + done() |
| 30 | + }) |
| 31 | + .catch(done) |
| 32 | + }) |
| 33 | + test('Update term from uid', done => { |
| 34 | + stack.taxonomy(taxonomyUID).terms(termUID) |
| 35 | + .fetch() |
| 36 | + .then((termResponse) => { |
| 37 | + termResponse.name = 'Updated Name' |
| 38 | + return termResponse.update() |
| 39 | + }) |
| 40 | + .then((termResponse) => { |
| 41 | + expect(termResponse.uid).to.be.equal(termUID) |
| 42 | + expect(termResponse.name).to.be.equal('Updated Name') |
| 43 | + done() |
| 44 | + }) |
| 45 | + .catch(done) |
| 46 | + }) |
| 47 | + test('Delete term from uid', done => { |
| 48 | + stack.taxonomy(taxonomyUID).terms(termUID) |
| 49 | + .delete() |
| 50 | + .then((termResponse) => { |
| 51 | + expect(termResponse.notice).to.be.equal('Term deleted successfully.') |
| 52 | + done() |
| 53 | + }) |
| 54 | + .catch(done) |
| 55 | + }) |
| 56 | + test('Query to get all Terms', done => { |
| 57 | + stack.taxonomy(taxonomyUID).terms() |
| 58 | + .query() |
| 59 | + .find() |
| 60 | + .then((response) => { |
| 61 | + response.items.forEach((termResponse) => { |
| 62 | + expect(termResponse.uid).to.be.not.equal(null) |
| 63 | + expect(termResponse.name).to.be.not.equal(null) |
| 64 | + }) |
| 65 | + done() |
| 66 | + }) |
| 67 | + .catch(done) |
| 68 | + }) |
| 69 | + test('Ancestors of the term given', done => { |
| 70 | + stack.taxonomy(taxonomyUID).terms(termUID) |
| 71 | + .ancestors() |
| 72 | + .then((termResponse) => { |
| 73 | + expect(termResponse.terms[0].uid).not.to.be.equal(null) |
| 74 | + expect(termResponse.terms[0].name).not.to.be.equal(null) |
| 75 | + expect(termResponse.terms[0].created_by).not.to.be.equal(null) |
| 76 | + expect(termResponse.terms[0].updated_by).not.to.be.equal(null) |
| 77 | + done() |
| 78 | + }) |
| 79 | + .catch(done) |
| 80 | + }) |
| 81 | + test('Descendants of the term given', done => { |
| 82 | + stack.taxonomy(taxonomyUID).terms(termUID) |
| 83 | + .descendants() |
| 84 | + .then((termResponse) => { |
| 85 | + expect(termResponse.terms[0].uid).not.to.be.equal(null) |
| 86 | + expect(termResponse.terms[0].name).not.to.be.equal(null) |
| 87 | + expect(termResponse.terms[0].created_by).not.to.be.equal(null) |
| 88 | + expect(termResponse.terms[0].updated_by).not.to.be.equal(null) |
| 89 | + done() |
| 90 | + }) |
| 91 | + .catch(done) |
| 92 | + }) |
| 93 | + it('search term', done => { |
| 94 | + const typeahead = 'term_string' |
| 95 | + stack.taxonomy('$all').terms() |
| 96 | + .search(typeahead) |
| 97 | + .then((termResponse) => { |
| 98 | + expect(termResponse.terms).to.be.an('array') |
| 99 | + done() |
| 100 | + }) |
| 101 | + .catch((err) => {console.log(err)}) |
| 102 | + |
| 103 | + }) |
| 104 | + it('move term', done => { |
| 105 | + const term = { |
| 106 | + parent_uid: 'parent_uid', |
| 107 | + order: 2 |
| 108 | + } |
| 109 | + stack.taxonomy(taxonomyUID).terms(termUID) |
| 110 | + .move({ term }) |
| 111 | + .then((termResponse) => { |
| 112 | + expect(termResponse.notice).to.be.equal('Term moved successfully.') |
| 113 | + done() |
| 114 | + }) |
| 115 | + .catch(done) |
| 116 | + }) |
| 117 | + }) |
| 118 | +} |
0 commit comments