File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import { Taxonomy } from '../../src/taxonomy';
88
99dotenv . config ( )
1010const countryUsa = process . env . TAX_COUNTRY_USA || 'usa'
11+ const locale = process . env . TAX_LOCALE || 'en-us'
1112const stack = stackInstance ( ) ;
1213describe ( 'ContentType API test cases' , ( ) => {
1314 it ( 'should give taxonomies when taxonomies method is called' , async ( ) => {
@@ -19,6 +20,19 @@ describe('ContentType API test cases', () => {
1920 const result = await makeTaxonomy ( countryUsa ) . fetch < TTaxonomy > ( ) ;
2021 expect ( result ) . toBeDefined ( ) ;
2122 } ) ;
23+
24+ it ( 'should give a localized taxonomy when a locale is passed to fetch' , async ( ) => {
25+ const result = await makeTaxonomy ( countryUsa ) . fetch < TTaxonomy > ( locale ) ;
26+ expect ( result ) . toBeDefined ( ) ;
27+ if ( result . publish_details ) {
28+ expect ( result . publish_details . locale ) . toBeDefined ( ) ;
29+ }
30+ } ) ;
31+
32+ it ( 'should give a taxonomy with locale fallback when includeFallback is chained' , async ( ) => {
33+ const result = await makeTaxonomy ( countryUsa ) . includeFallback ( ) . fetch < TTaxonomy > ( locale ) ;
34+ expect ( result ) . toBeDefined ( ) ;
35+ } ) ;
2236} ) ;
2337
2438function makeTaxonomies ( ) : TaxonomyQuery {
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import dotenv from 'dotenv';
66dotenv . config ( )
77const stack = stackInstance ( ) ;
88const countryUsa = process . env . TAX_COUNTRY_USA || 'usa'
9+ const locale = process . env . TAX_LOCALE || 'en-us'
910
1011describe ( "Terms API test cases" , ( ) => {
1112 it ( "should check for terms is defined" , async ( ) => {
@@ -18,6 +19,25 @@ describe("Terms API test cases", () => {
1819 expect ( result . terms [ 0 ] . updated_by ) . toBeDefined ( ) ;
1920 }
2021 } ) ;
22+
23+ it ( "should return terms for the requested locale when locale() is chained" , async ( ) => {
24+ const result = await makeTerms ( countryUsa ) . locale ( locale ) . find < TTerm > ( ) ;
25+ if ( result . terms && result . terms . length ) {
26+ expect ( result . terms ) . toBeDefined ( ) ;
27+ result . terms . forEach ( ( term ) => {
28+ if ( term . publish_details ) {
29+ expect ( term . publish_details . locale ) . toEqual ( locale ) ;
30+ }
31+ } ) ;
32+ }
33+ } ) ;
34+
35+ it ( "should return terms with locale fallback when includeFallback() is chained" , async ( ) => {
36+ const result = await makeTerms ( countryUsa ) . locale ( locale ) . includeFallback ( ) . find < TTerm > ( ) ;
37+ if ( result . terms ) {
38+ expect ( result . terms ) . toBeDefined ( ) ;
39+ }
40+ } ) ;
2141} ) ;
2242function makeTerms ( taxonomyUid = "" ) : TermQuery {
2343 const terms = stack . taxonomy ( taxonomyUid ) . term ( ) ;
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import dotenv from 'dotenv';
55
66dotenv . config ( )
77const countryUsa = process . env . TAX_COUNTRY_USA || 'usa'
8+ const locale = process . env . TAX_LOCALE || 'en-us'
89const stack = stackInstance ( ) ;
910
1011describe ( "Terms API test cases" , ( ) => {
@@ -17,6 +18,19 @@ describe("Terms API test cases", () => {
1718 expect ( result . updated_by ) . toBeDefined ( ) ;
1819 } ) ;
1920
21+ it ( "should get a localized term when a locale is passed to fetch" , async ( ) => {
22+ const result = await makeTerms ( "texas" ) . fetch < TTerm > ( locale ) ;
23+ expect ( result ) . toBeDefined ( ) ;
24+ if ( result . publish_details ) {
25+ expect ( result . publish_details . locale ) . toBeDefined ( ) ;
26+ }
27+ } ) ;
28+
29+ it ( "should get a term with locale fallback when includeFallback is chained" , async ( ) => {
30+ const result = await makeTerms ( "texas" ) . includeFallback ( ) . fetch < TTerm > ( locale ) ;
31+ expect ( result ) . toBeDefined ( ) ;
32+ } ) ;
33+
2034 it ( "should get locales for a term" , async ( ) => {
2135 const result = await makeTerms ( "texas" ) . locales < TTerms > ( ) ;
2236 expect ( result ) . toBeDefined ( ) ;
You can’t perform that action at this time.
0 commit comments