-
Notifications
You must be signed in to change notification settings - Fork 9
feat/cs 41208 Taxonomy support #80
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 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import cloneDeep from 'lodash/cloneDeep' | ||
import { | ||
create, | ||
fetch, | ||
query, | ||
update, | ||
deleteEntity | ||
} from '../../entity' | ||
|
||
export function Taxonomy (http, data) { | ||
this.stackHeaders = data.stackHeaders | ||
this.urlPath = `/taxonomies` | ||
|
||
if (data.taxonomy) { | ||
Object.assign(this, cloneDeep(data.taxonomy)) | ||
this.urlPath = `/taxonomies/${this.uid}` | ||
|
||
/** | ||
* @description The Update taxonomy call is used to update an existing taxonomy. | ||
* @memberof Taxonomy | ||
* @func update | ||
* @returns {Promise<Taxonomy.Taxonomy>} Promise for Taxonomy instance | ||
* @example | ||
* import * as contentstack from '@contentstack/management' | ||
* const client = contentstack.client() | ||
* | ||
* client.stack({ api_key: 'api_key'}).taxonomy('taxonomy_uid').fetch() | ||
* .then((taxonomy) => { | ||
* taxonomy.name = 'taxonomy name' | ||
* return taxonomy.update() | ||
* }) | ||
* .then((taxonomy) => console.log(taxonomy)) | ||
* | ||
*/ | ||
this.update = update(http, 'taxonomy') | ||
|
||
/** | ||
* @description The Delete taxonomy call is used to delete an existing taxonomy. | ||
* @memberof Taxonomy | ||
* @func delete | ||
* @returns {Promise<Taxonomy.Taxonomy>} Response Object. | ||
* @example | ||
* import * as contentstack from '@contentstack/management' | ||
* const client = contentstack.client() | ||
* | ||
* client.stack({ api_key: 'api_key'}).taxonomy('taxonomy_uid').delete() | ||
* .then((response) => console.log(response.notice)) | ||
* | ||
*/ | ||
this.delete = deleteEntity(http) | ||
|
||
/** | ||
* @description The Fetch taxonomy call is used to fetch an existing taxonomy. | ||
* @memberof Taxonomy | ||
* @func fetch | ||
* @returns {Promise<Taxonomy.Taxonomy>} Promise for Taxonomy instance | ||
* @example | ||
* import * as contentstack from '@contentstack/management' | ||
* const client = contentstack.client() | ||
* | ||
* client.stack({ api_key: 'api_key'}).taxonomy('taxonomy_uid').fetch() | ||
* .then((taxonomy) => console.log(taxonomy)) | ||
* | ||
*/ | ||
this.fetch = fetch(http, 'taxonomy') | ||
} else { | ||
/** | ||
* @description The Create taxonomy call is used to create a taxonomy. | ||
* @memberof Taxonomy | ||
* @func create | ||
* @returns {Promise<Taxonomy.Taxonomy>} Promise for Taxonomy instance | ||
* @example | ||
* import * as contentstack from '@contentstack/management' | ||
* const client = contentstack.client() | ||
* const taxonomy = { | ||
* uid: 'taxonomy_testing1', | ||
* name: 'taxonomy testing', | ||
* description: 'Description for Taxonomy testing' | ||
* } | ||
* client.stack({ api_key: 'api_key'}).taxonomy().create({taxonomy}) | ||
* .then(taxonomy) => console.log(taxonomy) | ||
* | ||
*/ | ||
this.create = create({ http }) | ||
|
||
/** | ||
* @description The Query on Taxonomy will allow to fetch details of all Taxonomies. | ||
* @memberof Taxonomy | ||
* @param {Object} params - URI parameters | ||
* @prop {Object} params.query - Queries that you can use to fetch filtered results. | ||
* @func query | ||
* @returns {Array<Taxonomy>} Array of Taxonomy. | ||
* | ||
* @example | ||
* import * as contentstack from '@contentstack/management' | ||
* const client = contentstack.client() | ||
* | ||
* client.stack().taxonomy().query().find() | ||
* .then((taxonomies) => console.log(taxonomies) | ||
*/ | ||
this.query = query({ http: http, wrapperCollection: TaxonomyCollection }) | ||
} | ||
} | ||
export function TaxonomyCollection (http, data) { | ||
const obj = cloneDeep(data.taxonomy) || [] | ||
const taxonomyCollection = obj.map((userdata) => { | ||
return new Taxonomy(http, { taxonomy: userdata, stackHeaders: data.stackHeaders }) | ||
}) | ||
return taxonomyCollection | ||
} |
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,86 @@ | ||
import { expect } from 'chai' | ||
import { describe, it, setup } from 'mocha' | ||
import { jsonReader } from '../utility/fileOperations/readwrite' | ||
import { contentstackClient } from '../utility/ContentstackClient.js' | ||
|
||
var client = {} | ||
var stack = {} | ||
|
||
const taxonomy = { | ||
uid: 'taxonomy_testing1', | ||
name: 'taxonomy testing', | ||
description: 'Description for Taxonomy testing' | ||
} | ||
|
||
var taxonomyUID = '' | ||
// var taxonomyDelUID = 'taxonomy_testing' | ||
harshithad0703 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
describe('taxonomy api Test', () => { | ||
setup(() => { | ||
const user = jsonReader('loggedinuser.json') | ||
stack = jsonReader('stack.json') | ||
client = contentstackClient(user.authtoken) | ||
}) | ||
|
||
it('Create taxonomy', done => { | ||
makeTaxonomy() | ||
.create([{ taxonomy }]) | ||
.then((taxonomyResponse) => { | ||
expect(taxonomyResponse.name).to.be.equal(taxonomy.name) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('Fetch taxonomy from uid', done => { | ||
makeTaxonomy(taxonomyUID) | ||
.fetch() | ||
.then((taxonomyResponse) => { | ||
expect(taxonomyResponse.uid).to.be.equal(taxonomyUID) | ||
expect(taxonomyResponse.name).to.be.not.equal(null) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
it('Update taxonomy from uid', done => { | ||
makeTaxonomy(taxonomyUID) | ||
.fetch() | ||
.then((taxonomyResponse) => { | ||
taxonomyResponse.name = 'Updated Name' | ||
return taxonomyResponse.update() | ||
}) | ||
.then((taxonomyResponse) => { | ||
expect(taxonomyResponse.uid).to.be.equal(taxonomyUID) | ||
expect(taxonomyResponse.name).to.be.equal('Updated Name') | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
|
||
// it('Delete taxonomy from uid', done => { | ||
harshithad0703 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
// makeTaxonomy(taxonomyDelUID) | ||
// .delete() | ||
// .then((taxonomyResponse) => { | ||
// expect(taxonomyResponse.notice).to.be.equal('Taxonomy deleted successfully.') | ||
// done() | ||
// }) | ||
// .catch(done) | ||
// }) | ||
|
||
it('Query to get all taxonomies', async () => { | ||
makeTaxonomy() | ||
.query() | ||
.find() | ||
.then((response) => { | ||
response.items.forEach((taxonomyResponse) => { | ||
expect(taxonomyResponse.uid).to.be.not.equal(null) | ||
expect(taxonomyResponse.name).to.be.not.equal(null) | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
function makeTaxonomy (uid = null) { | ||
return client.stack({ api_key: stack.api_key }).taxonomy(uid) | ||
} |
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
Oops, something went wrong.
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.