Skip to content

Commit 8121f6a

Browse files
add taxonomy localization test cases
1 parent cdd2fee commit 8121f6a

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

test/api/taxonomy.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Taxonomy } from '../../src/taxonomy';
88

99
dotenv.config()
1010
const countryUsa = process.env.TAX_COUNTRY_USA || 'usa'
11+
const locale = process.env.TAX_LOCALE || 'en-us'
1112
const stack = stackInstance();
1213
describe('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

2438
function makeTaxonomies(): TaxonomyQuery {

test/api/term-query.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import dotenv from 'dotenv';
66
dotenv.config()
77
const stack = stackInstance();
88
const countryUsa = process.env.TAX_COUNTRY_USA || 'usa'
9+
const locale = process.env.TAX_LOCALE || 'en-us'
910

1011
describe("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
});
2242
function makeTerms(taxonomyUid = ""): TermQuery {
2343
const terms = stack.taxonomy(taxonomyUid).term();

test/api/term.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import dotenv from 'dotenv';
55

66
dotenv.config()
77
const countryUsa = process.env.TAX_COUNTRY_USA || 'usa'
8+
const locale = process.env.TAX_LOCALE || 'en-us'
89
const stack = stackInstance();
910

1011
describe("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();

0 commit comments

Comments
 (0)