Skip to content

Commit

Permalink
fix: updated tests and types
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinav-from-contentstack committed Jan 8, 2024
1 parent 16931a1 commit c746e27
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 30 deletions.
11 changes: 3 additions & 8 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,12 @@ export class ContentType {
constructor();
content_type_uid: string

Query(): TaxonomyQuery;
Query(): Taxonomy;
Entry(uid: string): Entry;
fetch(fetchOptions?: object): Promise<any>;
}

export class Taxonomies {
constructor();
Query(): TaxonomyQuery;
Entry(uid: string): Entry;
fetch(fetchOptions?: object): Promise<any>;
}
export class Taxonomies extends Taxonomy {}

export class Assets {
constructor();
Expand Down Expand Up @@ -287,7 +282,7 @@ export class Query extends Entry {
findOne(): Promise<any>;
}

export class TaxonomyQuery extends Query {
export class Taxonomy extends Query {
constructor();
above(key: string, value: string, levels?: number): Query;
equalAndAbove(key: string, value: string, levels?: number): Query;
Expand Down
26 changes: 13 additions & 13 deletions test/entry/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ test('.except() - For the reference - Array', function(assert) {

// Taxonomies Endpoint
test('Taxonomies Endpoint: Get Entries With One Term', function(assert) {
let Query = Stack.Taxonomies().Query();
let Query = Stack.Taxonomies();
Query
.where('taxonomies.one', 'term_one')
.toJSON()
Expand All @@ -1380,7 +1380,7 @@ test('Taxonomies Endpoint: Get Entries With One Term', function(assert) {
});

test('Taxonomies Endpoint: Get Entries With Any Term ($in)', function(assert) {
let Query = Stack.Taxonomies().Query();
let Query = Stack.Taxonomies();
Query
.containedIn('taxonomies.one', ['term_one', 'term_two'])
.toJSON()
Expand All @@ -1396,9 +1396,9 @@ test('Taxonomies Endpoint: Get Entries With Any Term ($in)', function(assert) {
})

test('Taxonomies Endpoint: Get Entries With Any Term ($or)', function(assert) {
let Query = Stack.Taxonomies().Query();
let Query1 = Stack.Taxonomies().Query().where('taxonomies.one', 'term_one');
let Query2 = Stack.Taxonomies().Query().where('taxonomies.two', 'term_two');
let Query = Stack.Taxonomies();
let Query1 = Stack.Taxonomies().where('taxonomies.one', 'term_one');
let Query2 = Stack.Taxonomies().where('taxonomies.two', 'term_two');
Query
.or(Query1, Query2)
.toJSON()
Expand All @@ -1414,9 +1414,9 @@ test('Taxonomies Endpoint: Get Entries With Any Term ($or)', function(assert) {
})

test('Taxonomies Endpoint: Get Entries With All Terms ($and)', function(assert) {
let Query1 = Stack.Taxonomies().Query().where('taxonomies.one', 'term_one');
let Query2 = Stack.Taxonomies().Query().where('taxonomies.two', 'term_two');
let Query = Stack.Taxonomies().Query();
let Query1 = Stack.Taxonomies().where('taxonomies.one', 'term_one');
let Query2 = Stack.Taxonomies().where('taxonomies.two', 'term_two');
let Query = Stack.Taxonomies();
Query
.and(Query1, Query2)
.toJSON()
Expand All @@ -1432,7 +1432,7 @@ test('Taxonomies Endpoint: Get Entries With All Terms ($and)', function(assert)
})

test('Taxonomies Endpoint: Get Entries With Any Taxonomy Terms ($exists)', function(assert) {
let Query = Stack.Taxonomies().Query();
let Query = Stack.Taxonomies();
Query
.exists('taxonomies.one')
.toJSON()
Expand All @@ -1448,7 +1448,7 @@ test('Taxonomies Endpoint: Get Entries With Any Taxonomy Terms ($exists)', funct
})

test('Taxonomies Endpoint: Get Entries With Taxonomy Terms and Also Matching Its Children Term ($eq_below, level)', function(assert) {
let Query = Stack.Taxonomies().Query();
let Query = Stack.Taxonomies();
Query
.equalAndBelow('taxonomies.one', 'term_one')
.toJSON()
Expand All @@ -1464,7 +1464,7 @@ test('Taxonomies Endpoint: Get Entries With Taxonomy Terms and Also Matching Its
})

test('Taxonomies Endpoint: Get Entries With Taxonomy Terms Children\'s and Excluding the term itself ($below, level)', function(assert) {
let Query = Stack.Taxonomies().Query();
let Query = Stack.Taxonomies();
Query
.below('taxonomies.one', 'term_one')
.toJSON()
Expand All @@ -1480,7 +1480,7 @@ test('Taxonomies Endpoint: Get Entries With Taxonomy Terms Children\'s and Exclu
})

test('Taxonomies Endpoint: Get Entries With Taxonomy Terms and Also Matching Its Parent Term ($eq_above, level)', function(assert) {
let Query = Stack.Taxonomies().Query();
let Query = Stack.Taxonomies();
Query
.equalAndAbove('taxonomies.one', 'term_one')
.toJSON()
Expand All @@ -1496,7 +1496,7 @@ test('Taxonomies Endpoint: Get Entries With Taxonomy Terms and Also Matching Its
})

test('Taxonomies Endpoint: Get Entries With Taxonomy Terms Parent and Excluding the term itself ($above, level)', function(assert) {
let Query = Stack.Taxonomies().Query();
let Query = Stack.Taxonomies();
Query
.above('taxonomies.one', 'term_one_child')
.toJSON()
Expand Down
22 changes: 13 additions & 9 deletions test/typescript/entry-query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,63 +403,67 @@ describe('Entry Query Test', () => {
done();
});

test('Taxonomy Query: Get entries with any term ($in)', done => {
test('CT Taxonomy Query: Get entries with any term ($in)', done => {
const query = makeEntryQuery().containedIn("taxonomies.taxonomy_uid", ["term_uid1", "term_uid2"]);
expect(query._query).toEqual({"query": {"taxonomies.taxonomy_uid": { "$in": ["term_uid1", "term_uid2"] }}});
done();
});

test('Taxonomy Query: Get entries with any term ($or)', done => {
test('CT Taxonomy Query: Get entries with any term ($or)', done => {
const query1 = makeEntryQuery().where("taxonomies.taxonomy_uid1", "term_uid1");
const query2 = makeEntryQuery().where("taxonomies.taxonomy_uid2", "term_uid2");
const query = makeEntryQuery().or(query1, query2);
expect(query._query).toEqual({"query": { $or: [ {"taxonomies.taxonomy_uid1": "term_uid1"}, {"taxonomies.taxonomy_uid2": "term_uid2"} ] }});
done();
});

test('Taxonomy Query: Get entries with all term ($and)', done => {
test('CT Taxonomy Query: Get entries with all term ($and)', done => {
const query1 = makeEntryQuery().where("taxonomies.taxonomy_uid1", "term_uid1");
const query2 = makeEntryQuery().where("taxonomies.taxonomy_uid2", "term_uid2");
const query = makeEntryQuery().and(query1, query2);
expect(query._query).toEqual({"query": { $and: [ {"taxonomies.taxonomy_uid1": "term_uid1"}, {"taxonomies.taxonomy_uid2": "term_uid2"} ] }});
done();
});

test('Taxonomy Query: Get entries with any taxonomy terms ($exists)', done => {
test('CT Taxonomy Query: Get entries with any taxonomy terms ($exists)', done => {
const query = makeEntryQuery().exists("taxonomies.taxonomy_uid");
expect(query._query).toEqual({"query": {"taxonomies.taxonomy_uid": {$exists: true}}});
done();
});

test('Taxonomy Query: Get entries with taxonomy terms and also matching its children terms ($eq_below, level)', done => {
test('CT Taxonomy Query: Get entries with taxonomy terms and also matching its children terms ($eq_below, level)', done => {
const query = makeEntryQuery().equalAndBelow("taxonomies.taxonomy_uid", "term_uid", 4);
expect(query._query).toEqual({"query": {"taxonomies.taxonomy_uid": {"$eq_below": "term_uid", "levels": 4 }}});
done();
});

test('Taxonomy Query: Get Entries With Taxonomy Terms Children\'s and Excluding the term itself ($below, level) ', done => {
test('CT Taxonomy Query: Get Entries With Taxonomy Terms Children\'s and Excluding the term itself ($below, level) ', done => {
const query = makeEntryQuery().below("taxonomies.taxonomy_uid", "term_uid");
expect(query._query).toEqual({"query": {"taxonomies.taxonomy_uid": {"$below": "term_uid" }}});
done();
});

test('Taxonomy Query: Get Entries With Taxonomy Terms and Also Matching Its Parent Term ($eq_above, level)', done => {
test('CT Taxonomy Query: Get Entries With Taxonomy Terms and Also Matching Its Parent Term ($eq_above, level)', done => {
const query = makeEntryQuery().equalAndAbove("taxonomies.taxonomy_uid", "term_uid", 4);
expect(query._query).toEqual({"query": {"taxonomies.taxonomy_uid": {"$eq_above": "term_uid", "levels": 4 }}});
done();
});

test('Taxonomy Query: Get Entries With Taxonomy Terms Parent and Excluding the term itself ($above, level)', done => {
test('CT Taxonomy Query: Get Entries With Taxonomy Terms Parent and Excluding the term itself ($above, level)', done => {
const query = makeEntryQuery().above("taxonomies.taxonomy_uid", "term_uid", 4);
expect(query._query).toEqual({"query": {"taxonomies.taxonomy_uid": {"$above": "term_uid", "levels": 4 }}});
done();
});

test('Taxonomy find test', done => {
makeTaxonomyQuery().find().then((response) => done()).catch((error) => done());
});
});

function makeEntryQuery() {
return stack.ContentType('uid').Query()
}

function makeTaxonomyQuery() {
return stack.Taxonomies().Query()
return stack.Taxonomies()
}

0 comments on commit c746e27

Please sign in to comment.