File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,11 +22,13 @@ export class Term {
2222 * import contentstack from '@contentstack/delivery-sdk'
2323 *
2424 * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
25- * const result = await stack.taxonomy('taxonomy_uid').term('term_uid').locales().fetch() ;
25+ * const result = await stack.taxonomy('taxonomy_uid').term('term_uid').locales();
2626 */
27- locales ( ) : this {
28- this . _urlPath = `${ this . _urlPath } /locales` ;
29- return this ;
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 ;
3032 }
3133
3234 async fetch < T > ( ) : Promise < T > {
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ describe("Terms API test cases", () => {
1717 it ( "should get locales for a term" , async ( ) => {
1818 // const result = await makeTerms("term1").locales().fetch();
1919 // API under building phase, so it should throw error
20- expect ( async ( ) => await makeTerms ( "term1" ) . locales ( ) . fetch ( ) ) . rejects . toThrow ( ) ;
20+ expect ( async ( ) => await makeTerms ( "term1" ) . locales ( ) ) . rejects . toThrow ( ) ;
2121 // TODO: add assertions
2222 } ) ;
2323} ) ;
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 , termLocalesFindResponseDataMock } 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' ;
@@ -26,10 +26,10 @@ describe('Term class', () => {
2626 expect ( response ) . toEqual ( termQueryFindResponseDataMock . terms [ 0 ] ) ;
2727 } ) ;
2828
29- it ( 'should fetch locales for a term when locales().fetch() is called' , async ( ) => {
30- mockClient . onGet ( '/taxonomy-manager/taxonomy_testing/terms/term1/locales' ) . reply ( 200 , termLocalesFindResponseDataMock ) ;
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
3131
32- const response = await term . locales ( ) . fetch ( ) ;
33- expect ( response ) . toEqual ( termLocalesFindResponseDataMock . locales ) ;
32+ const response = await term . locales ( ) ;
33+ expect ( response ) . toEqual ( termLocalesResponseDataMock . terms ) ;
3434 } ) ;
3535} ) ;
Original file line number Diff line number Diff line change @@ -1699,19 +1699,8 @@ const taxonomyFindResponseDataMock = {
16991699 ]
17001700}
17011701
1702- const termLocalesFindResponseDataMock = {
1703- "locales" : [
1704- {
1705- "code" : "en-us" ,
1706- "name" : "English (United States)" ,
1707- "fallback_code" : null
1708- } ,
1709- {
1710- "code" : "es-es" ,
1711- "name" : "Spanish (Spain)" ,
1712- "fallback_code" : "en-us"
1713- }
1714- ]
1702+ const termLocalesResponseDataMock = {
1703+ terms : [ ]
17151704}
17161705
17171706const termQueryFindResponseDataMock = {
@@ -1759,5 +1748,5 @@ export {
17591748 gfieldQueryFindResponseDataMock ,
17601749 taxonomyFindResponseDataMock ,
17611750 termQueryFindResponseDataMock ,
1762- termLocalesFindResponseDataMock ,
1751+ termLocalesResponseDataMock ,
17631752} ;
You can’t perform that action at this time.
0 commit comments