Skip to content

Commit df96f25

Browse files
get a single taxonomy
1 parent 77caa3b commit df96f25

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

test/api/taxonomy.spec.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
/* eslint-disable no-console */
22
/* eslint-disable promise/always-return */
33
import { stackInstance } from '../utils/stack-instance';
4-
import { TTaxonomies } from './types';
4+
import { TTaxonomies, TTaxonomy } from './types';
55
import dotenv from 'dotenv';
66
import { TaxonomyQuery } from '../../src/lib/taxonomy-query';
7+
import { Taxonomy } from '../../src/lib/taxonomy';
78

89
dotenv.config()
910

1011
const stack = stackInstance();
1112
describe('ContentType API test cases', () => {
1213
it('should give taxonomies when taxonomies method is called', async () => {
13-
const result = await makeTaxonomy().find<TTaxonomies>();
14+
const result = await makeTaxonomies().find<TTaxonomies>();
15+
expect(result).toBeDefined();
16+
});
17+
18+
it('should give a single taxonomy when taxonomy method is called with taxonomyUid', async () => {
19+
const result = await makeTaxonomy('taxonomy_testing').fetch<TTaxonomy>();
1420
expect(result).toBeDefined();
1521
});
1622
});
1723

18-
function makeTaxonomy(): TaxonomyQuery {
19-
const taxonomy = stack.taxonomy();
24+
function makeTaxonomies(): TaxonomyQuery {
25+
const taxonomies = stack.taxonomy();
2026

21-
return taxonomy;
27+
return taxonomies;
2228
}
29+
30+
function makeTaxonomy(taxonomyUid: string): Taxonomy {
31+
const taxonomy = stack.taxonomy(taxonomyUid);
32+
return taxonomy;
33+
}

test/unit/taxonomy.spec.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { TaxonomyQuery } from '../../src/lib/taxonomy-query';
2+
import { Taxonomy } from '../../src/lib/taxonomy';
23
import { AxiosInstance, httpClient } from '@contentstack/core';
34
import MockAdapter from 'axios-mock-adapter';
45
import { taxonomyFindResponseDataMock } from '../utils/mocks';
56
import { MOCK_CLIENT_OPTIONS } from '../utils/constant';
67

78
describe('ta class', () => {
8-
let taxonomy: TaxonomyQuery;
9+
let taxonomies: TaxonomyQuery;
10+
let taxonomy: Taxonomy;
911
let client: AxiosInstance;
1012
let mockClient: MockAdapter;
1113

@@ -15,12 +17,19 @@ describe('ta class', () => {
1517
});
1618

1719
beforeEach(() => {
18-
taxonomy = new TaxonomyQuery(client);
20+
taxonomies = new TaxonomyQuery(client);
21+
taxonomy = new Taxonomy(client, 'taxonomy_testing');
1922
});
2023

21-
it('should return response data when successful', async () => {
24+
it('should return all taxonomies in the response data when successful', async () => {
2225
mockClient.onGet('/taxonomy-manager').reply(200, taxonomyFindResponseDataMock); //TODO: change to /taxonomies
23-
const response = await taxonomy.find();
26+
const response = await taxonomies.find();
2427
expect(response).toEqual(taxonomyFindResponseDataMock);
2528
});
29+
30+
it('should return single taxonomy in the response data when successful', async () => {
31+
mockClient.onGet('/taxonomy-manager/taxonomy_testing').reply(200, taxonomyFindResponseDataMock.taxonomies[0]); //TODO: change to /taxonomies/taxonomyUid
32+
const response = await taxonomy.fetch();
33+
expect(response).toEqual(taxonomyFindResponseDataMock.taxonomies[0]); //TODO: change to taxonomyFindResponseDataMock
34+
});
2635
});

0 commit comments

Comments
 (0)