-
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.
Merge pull request #88 from contentstack/next
Types support for Taxonomy and Terms
- Loading branch information
Showing
16 changed files
with
277 additions
and
10 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
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,68 @@ | ||
import { expect } from "chai"; | ||
import { Stack } from "../../types/stack"; | ||
|
||
var taxonomyUID = '' | ||
export function testTaxonomy(stack: Stack) { | ||
describe('Taxonomy API test', () => { | ||
test('Create taxonomy', done => { | ||
const taxonomy = { | ||
uid: 'uid', | ||
name: 'taxonomy', | ||
description: 'Description for Taxonomy' | ||
} | ||
stack.taxonomy().create({taxonomy}) | ||
.then((taxonomyResponse) => { | ||
console.log(taxonomyResponse) | ||
expect(taxonomyResponse.uid).to.be.equal(taxonomy.uid) | ||
expect(taxonomyResponse.name).to.be.equal(taxonomy.name) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
test('Fetch taxonomy from uid', done => { | ||
stack.taxonomy(taxonomyUID).fetch() | ||
.then((taxonomyResponse) => { | ||
console.log(taxonomyResponse) | ||
expect(taxonomyResponse.uid).to.be.equal(taxonomyUID) | ||
expect(taxonomyResponse.name).not.to.be.equal('a') | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
test('Update taxonomy from uid', done => { | ||
stack.taxonomy(taxonomyUID) | ||
.fetch() | ||
.then((taxonomyResponse) => { | ||
taxonomyResponse.name = 'updated name' | ||
return taxonomyResponse.update() | ||
}) | ||
.then((taxonomyResponse) => { | ||
console.log(taxonomyResponse) | ||
expect(taxonomyResponse.uid).to.be.equal(taxonomyUID) | ||
expect(taxonomyResponse.name).to.be.equal('updated name') | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
test('Delete taxonomy from uid', done => { | ||
stack.taxonomy(taxonomyUID) | ||
.delete() | ||
.then((taxonomyResponse) => { | ||
expect(taxonomyResponse.notice).to.be.equal('Taxonomy deleted successfully.') | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
test('Query to get all taxonomies', async () => { | ||
await stack.taxonomy() | ||
.query() | ||
.find() | ||
.then((response) => { | ||
response.items.forEach((taxonomyResponse) => { | ||
expect(taxonomyResponse.uid).to.be.not.equal(null) | ||
expect(taxonomyResponse.name).to.be.not.equal(null) | ||
}) | ||
}) | ||
}) | ||
}) | ||
} |
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,118 @@ | ||
import { expect } from "chai"; | ||
import { Stack } from "../../types/stack"; | ||
var taxonomyUID = '' | ||
var termUID = '' | ||
export function testTerm(stack: Stack) { | ||
describe('Term API test', () => { | ||
test('Create Term', done => { | ||
const term = { | ||
uid: 'term_uid', | ||
name: 'term name', | ||
parent_uid: 'parent_uid', | ||
order: 1 | ||
} | ||
stack.taxonomy(taxonomyUID).terms().create({term}) | ||
.then((termResponse) => { | ||
expect(termResponse.uid).to.be.equal(term.uid) | ||
expect(termResponse.name).to.be.equal(term.name) | ||
done() | ||
}) | ||
.catch((err) => { | ||
console.log(err) | ||
}) | ||
}) | ||
test('Fetch term from uid', done => { | ||
stack.taxonomy(taxonomyUID).terms(termUID).fetch() | ||
.then((termResponse) => { | ||
expect(termResponse.uid).to.be.equal(termUID) | ||
expect(termResponse.name).not.to.be.equal(null) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
test('Update term from uid', done => { | ||
stack.taxonomy(taxonomyUID).terms(termUID) | ||
.fetch() | ||
.then((termResponse) => { | ||
termResponse.name = 'Updated Name' | ||
return termResponse.update() | ||
}) | ||
.then((termResponse) => { | ||
expect(termResponse.uid).to.be.equal(termUID) | ||
expect(termResponse.name).to.be.equal('Updated Name') | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
test('Delete term from uid', done => { | ||
stack.taxonomy(taxonomyUID).terms(termUID) | ||
.delete() | ||
.then((termResponse) => { | ||
expect(termResponse.notice).to.be.equal('Term deleted successfully.') | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
test('Query to get all Terms', done => { | ||
stack.taxonomy(taxonomyUID).terms() | ||
.query() | ||
.find() | ||
.then((response) => { | ||
response.items.forEach((termResponse) => { | ||
expect(termResponse.uid).to.be.not.equal(null) | ||
expect(termResponse.name).to.be.not.equal(null) | ||
}) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
test('Ancestors of the term given', done => { | ||
stack.taxonomy(taxonomyUID).terms(termUID) | ||
.ancestors() | ||
.then((termResponse) => { | ||
expect(termResponse.terms[0].uid).not.to.be.equal(null) | ||
expect(termResponse.terms[0].name).not.to.be.equal(null) | ||
expect(termResponse.terms[0].created_by).not.to.be.equal(null) | ||
expect(termResponse.terms[0].updated_by).not.to.be.equal(null) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
test('Descendants of the term given', done => { | ||
stack.taxonomy(taxonomyUID).terms(termUID) | ||
.descendants() | ||
.then((termResponse) => { | ||
expect(termResponse.terms[0].uid).not.to.be.equal(null) | ||
expect(termResponse.terms[0].name).not.to.be.equal(null) | ||
expect(termResponse.terms[0].created_by).not.to.be.equal(null) | ||
expect(termResponse.terms[0].updated_by).not.to.be.equal(null) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
it('search term', done => { | ||
const typeahead = 'term_string' | ||
stack.taxonomy('$all').terms() | ||
.search(typeahead) | ||
.then((termResponse) => { | ||
expect(termResponse.terms).to.be.an('array') | ||
done() | ||
}) | ||
.catch((err) => {console.log(err)}) | ||
|
||
}) | ||
it('move term', done => { | ||
const term = { | ||
parent_uid: 'parent_uid', | ||
order: 2 | ||
} | ||
stack.taxonomy(taxonomyUID).terms(termUID) | ||
.move({ term }) | ||
.then((termResponse) => { | ||
expect(termResponse.notice).to.be.equal('Term moved successfully.') | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
}) | ||
} |
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
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,20 @@ | ||
import { AnyProperty, SystemFields } from "../../utility/fields"; | ||
import { Creatable, Queryable, SystemFunction } from "../../utility/operations"; | ||
import { Term, Terms } from "../taxonomy/terms" | ||
|
||
export interface Taxonomy extends SystemFields, SystemFunction<Taxonomy> { | ||
terms(): Terms | ||
terms(uid: string): Term | ||
} | ||
|
||
export interface Taxonomies extends Queryable<Taxonomy, {taxonomy: TaxonomyData}> { | ||
} | ||
|
||
export interface Taxonomies extends Creatable<Taxonomy, {taxonomy: TaxonomyData}> { | ||
} | ||
|
||
export interface TaxonomyData extends AnyProperty { | ||
name: string | ||
uid: string | ||
description: string | ||
} |
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,24 @@ | ||
import { AnyProperty, SystemFields } from "../../../utility/fields"; | ||
import { Creatable, Queryable, Searchable, SystemFunction } from "../../../utility/operations"; | ||
|
||
export interface Term extends SystemFields, SystemFunction<Term> { | ||
ancestors(data?: { include_children_count?: boolean, include_referenced_entries_count?: boolean, include_count?: boolean, skip?: number, limit?: number}): Promise<Term> | ||
descendants(data?: { include_children_count?: boolean, include_referenced_entries_count?: boolean, include_count?: boolean, skip?: number, limit?: number}): Promise<Term> | ||
move(data: { term: { parent_uid?: string, order: number } }, force?: boolean): Promise<Term> | ||
} | ||
|
||
export interface Terms extends Creatable<Term, {term: TermData}> { | ||
} | ||
|
||
export interface Terms extends Searchable<Term, string> { | ||
} | ||
|
||
export interface Terms extends Queryable<Term, {term: TermData}> { | ||
} | ||
|
||
export interface TermData extends AnyProperty { | ||
name: string | ||
uid: string | ||
parent_uid?: string | ||
order: number | ||
} |
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