-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: ✅ unit test cases for terms implementation (except search and m…
…ove)
- Loading branch information
1 parent
a0e855e
commit 96ba089
Showing
4 changed files
with
217 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
import Axios from 'axios' | ||
import { expect } from 'chai' | ||
import { describe, it } from 'mocha' | ||
import MockAdapter from 'axios-mock-adapter' | ||
import { Terms } from '../../lib/stack/taxonomy/terms' | ||
import { systemUidMock, stackHeadersMock, termsMock, noticeMock } from './mock/objects' | ||
|
||
describe('Contentstack Term test', () => { | ||
it('term create test', done => { | ||
var mock = new MockAdapter(Axios) | ||
mock.onPost(`/taxonomies/taxonomy_uid/terms`).reply(200, { | ||
term: { | ||
...termsMock | ||
} | ||
}) | ||
makeTerms() | ||
.create() | ||
.then((term) => { | ||
checkTerms(term) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
it('Term fetch test', done => { | ||
var mock = new MockAdapter(Axios) | ||
mock.onGet(`/taxonomies/taxonomy_uid/terms/UID`).reply(200, { | ||
term: { | ||
...termsMock | ||
} | ||
}) | ||
makeTerms({ | ||
term: { | ||
...systemUidMock | ||
}, | ||
stackHeaders: stackHeadersMock | ||
}) | ||
.fetch() | ||
.then((term) => { | ||
checkTerms(term) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
it('Terms query test', done => { | ||
var mock = new MockAdapter(Axios) | ||
mock.onGet(`/taxonomies/taxonomy_uid/terms`).reply(200, { | ||
terms: [ | ||
termsMock | ||
] | ||
}) | ||
makeTerms() | ||
.query() | ||
.find() | ||
.then((terms) => { | ||
checkTerms(terms.items[0]) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
it('Term update test', done => { | ||
var mock = new MockAdapter(Axios) | ||
mock.onPut(`/taxonomies/taxonomy_uid/terms/UID`).reply(200, { | ||
term: { | ||
...termsMock | ||
} | ||
}) | ||
makeTerms({ | ||
term: { | ||
...systemUidMock | ||
}, | ||
stackHeaders: stackHeadersMock | ||
}) | ||
.update() | ||
.then((term) => { | ||
checkTerms(term) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
it('term delete test', done => { | ||
var mock = new MockAdapter(Axios) | ||
mock.onDelete(`/taxonomies/taxonomy_uid/terms/UID`).reply(200, { | ||
...noticeMock | ||
}) | ||
makeTerms({ | ||
term: { | ||
...systemUidMock | ||
}, | ||
stackHeaders: stackHeadersMock | ||
}) | ||
.delete() | ||
.then((term) => { | ||
expect(term.notice).to.be.equal(noticeMock.notice) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
it('Term ancestors test', done => { | ||
var mock = new MockAdapter(Axios) | ||
mock.onGet(`/taxonomies/taxonomy_uid/terms/UID/ancestors`).reply(200, { ...termsMock }) | ||
makeTerms({ | ||
term: { | ||
...systemUidMock | ||
}, | ||
stackHeaders: stackHeadersMock | ||
}) | ||
.ancestors() | ||
.then((terms) => { | ||
checkTerms(terms) | ||
expect(terms.uid).to.be.equal('UID') | ||
expect(terms.parent_uid).to.be.equal('term_2') | ||
expect(terms.ancestors[0].uid).to.be.equal('term_1') | ||
expect(terms.ancestors[1].uid).to.be.equal('term_2') | ||
expect(terms.ancestors[1].parent_uid).to.be.equal('term_1') | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
it('Term descendants test', done => { | ||
var mock = new MockAdapter(Axios) | ||
mock.onGet(`/taxonomies/taxonomy_uid/terms/UID/descendants`).reply(200, { ...termsMock }) | ||
makeTerms({ | ||
term: { | ||
...systemUidMock | ||
}, | ||
stackHeaders: stackHeadersMock | ||
}) | ||
.descendants() | ||
.then((terms) => { | ||
checkTerms(terms) | ||
expect(terms.uid).to.be.equal('UID') | ||
expect(terms.descendants[0].uid).to.be.equal('term_4') | ||
expect(terms.descendants[1].uid).to.be.equal('term_5') | ||
expect(terms.descendants[1].parent_uid).to.be.equal('term_4') | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
it('Term test without term uid', done => { | ||
const term = makeTerms() | ||
expect(term.stackHeaders).to.be.equal(undefined) | ||
expect(term.update).to.be.equal(undefined) | ||
expect(term.delete).to.be.equal(undefined) | ||
expect(term.fetch).to.be.equal(undefined) | ||
expect(term.create).not.to.be.equal(undefined) | ||
expect(term.query).not.to.be.equal(undefined) | ||
done() | ||
}) | ||
it('Term test with term uid', done => { | ||
const term = makeTerms({ | ||
term: { | ||
...systemUidMock | ||
} | ||
}) | ||
expect(term.urlPath).to.be.equal(`/taxonomies/taxonomy_uid/terms/${systemUidMock.uid}`) | ||
expect(term.stackHeaders).to.be.equal(undefined) | ||
expect(term.update).not.to.be.equal(undefined) | ||
expect(term.delete).not.to.be.equal(undefined) | ||
expect(term.fetch).not.to.be.equal(undefined) | ||
expect(term.create).to.be.equal(undefined) | ||
expect(term.query).to.be.equal(undefined) | ||
done() | ||
}) | ||
}) | ||
|
||
function makeTerms (data = {}) { | ||
return new Terms(Axios, { taxonomy_uid: 'taxonomy_uid', ...data }) | ||
} | ||
|
||
function checkTerms (terms) { | ||
expect(terms.name).to.be.equal('name') | ||
} |