-
Notifications
You must be signed in to change notification settings - Fork 9
taxonomy and terms implementation in types #86
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
555987d
feat: :sparkles: taxonomy and terms implementation for typescript
harshithad0703 851dd36
fix: :bug: taxonomy bug fix
harshithad0703 35ae017
feat: :sparkles: terms implementaion with descendants and move function
harshithad0703 e383a94
fix: :bug: taxonomy bug fix in query unit test case
harshithad0703 ee4ffed
fix: taxonomy and terms fixes
harshithad0703 dff07de
test: :white_check_mark: taxonomy API test cases
harshithad0703 fb363c4
test: :white_check_mark: terms api test cases and search implementation
harshithad0703 b0d85b1
test: :white_check_mark: changes in search unit test in terms
harshithad0703 f4642c4
changed default host name
harshithad0703 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.