File tree Expand file tree Collapse file tree 4 files changed +41
-1
lines changed Expand file tree Collapse file tree 4 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,25 @@ export class Term {
1212 this . _termUid = termUid ;
1313 this . _urlPath = `/taxonomy-manager/${ this . _taxonomyUid } /terms/${ this . _termUid } ` ; // TODO: change to /taxonomies
1414 }
15+
16+ /**
17+ * @method locales
18+ * @memberof Term
19+ * @description Fetches locales for the term
20+ * @returns {Promise<T> }
21+ * @example
22+ * import contentstack from '@contentstack/delivery-sdk'
23+ *
24+ * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
25+ * const result = await stack.taxonomy('taxonomy_uid').term('term_uid').locales();
26+ */
27+ async locales < T > ( ) : Promise < T > {
28+ const urlPath = `/taxonomy-manager/${ this . _taxonomyUid } /terms/${ this . _termUid } /locales` ;
29+ const response = await getData ( this . _client , urlPath ) ;
30+ if ( response . locales ) return response . locales as T ;
31+ return response ;
32+ }
33+
1534 async fetch < T > ( ) : Promise < T > {
1635 const response = await getData ( this . _client , this . _urlPath ) ;
1736
Original file line number Diff line number Diff line change @@ -13,7 +13,15 @@ describe("Terms API test cases", () => {
1313 expect ( result . created_by ) . toBeDefined ( ) ;
1414 expect ( result . updated_by ) . toBeDefined ( ) ;
1515 } ) ;
16+
17+ it ( "should get locales for a term" , async ( ) => {
18+ // const result = await makeTerms("term1").locales().fetch();
19+ // API under building phase, so it should throw error
20+ expect ( async ( ) => await makeTerms ( "term1" ) . locales ( ) ) . rejects . toThrow ( ) ;
21+ // TODO: add assertions
22+ } ) ;
1623} ) ;
24+
1725function makeTerms ( termUid = "" ) : Term {
1826 const terms = stack . taxonomy ( "taxonomy_testing" ) . term ( termUid ) ;
1927 return terms ;
Original file line number Diff line number Diff line change 11import { AxiosInstance , httpClient } from '@contentstack/core' ;
22import MockAdapter from 'axios-mock-adapter' ;
3- import { termQueryFindResponseDataMock } from '../utils/mocks' ;
3+ import { termQueryFindResponseDataMock , termLocalesResponseDataMock } from '../utils/mocks' ;
44import { MOCK_CLIENT_OPTIONS } from '../utils/constant' ;
55import { Term } from '../../src/lib/term' ;
66import { Taxonomy } from '../../src/lib/taxonomy' ;
@@ -25,4 +25,11 @@ describe('Term class', () => {
2525 const response = await term . fetch ( ) ;
2626 expect ( response ) . toEqual ( termQueryFindResponseDataMock . terms [ 0 ] ) ;
2727 } ) ;
28+
29+ it ( 'should fetch locales for a term when locales() is called' , async ( ) => {
30+ mockClient . onGet ( '/taxonomy-manager/taxonomy_testing/terms/term1/locales' ) . reply ( 200 , termLocalesResponseDataMock . terms ) ; //TODO: change to /taxonomies
31+
32+ const response = await term . locales ( ) ;
33+ expect ( response ) . toEqual ( termLocalesResponseDataMock . terms ) ;
34+ } ) ;
2835} ) ;
Original file line number Diff line number Diff line change @@ -1698,6 +1698,11 @@ const taxonomyFindResponseDataMock = {
16981698 }
16991699 ]
17001700}
1701+
1702+ const termLocalesResponseDataMock = {
1703+ terms : [ ]
1704+ }
1705+
17011706const termQueryFindResponseDataMock = {
17021707 "terms" : [
17031708 {
@@ -1743,4 +1748,5 @@ export {
17431748 gfieldQueryFindResponseDataMock ,
17441749 taxonomyFindResponseDataMock ,
17451750 termQueryFindResponseDataMock ,
1751+ termLocalesResponseDataMock ,
17461752} ;
You can’t perform that action at this time.
0 commit comments