Skip to content

Commit 86841d6

Browse files
committed
Basic unit tests for setAncestor
Added tests for the query proto, one to make sure the query structure is right when setting ancestor once and one to make sure the query structure is right when setting ancestor twice. Also added a unit test to make sure that ancestor is set the right way internally when using setAncestor.
1 parent e84582f commit 86841d6

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

test/entity.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,52 @@ describe('entity', () => {
19151915
assert.deepStrictEqual(entity.queryToQueryProto(query), queryProto);
19161916
});
19171917

1918+
it('should support the filter method with setAncestor', () => {
1919+
const ancestorKey = new entity.Key({
1920+
path: ['Kind2', 'somename'],
1921+
});
1922+
1923+
const ds = new Datastore({projectId: 'project-id'});
1924+
1925+
const query = ds
1926+
.createQuery('Kind1')
1927+
.filter(new PropertyFilter('name', '=', 'John'))
1928+
.start('start')
1929+
.end('end')
1930+
.groupBy(['name'])
1931+
.order('name')
1932+
.select('name')
1933+
.limit(1)
1934+
.offset(1)
1935+
.setAncestor(ancestorKey);
1936+
assert.deepStrictEqual(entity.queryToQueryProto(query), queryProto);
1937+
});
1938+
1939+
it('should support the filter method using setAncestor twice', () => {
1940+
const oldAncestorKey = new entity.Key({
1941+
path: ['Kind1', 'somename1'],
1942+
});
1943+
const ancestorKey = new entity.Key({
1944+
path: ['Kind2', 'somename'],
1945+
});
1946+
1947+
const ds = new Datastore({projectId: 'project-id'});
1948+
1949+
const query = ds
1950+
.createQuery('Kind1')
1951+
.filter(new PropertyFilter('name', '=', 'John'))
1952+
.start('start')
1953+
.end('end')
1954+
.groupBy(['name'])
1955+
.order('name')
1956+
.select('name')
1957+
.limit(1)
1958+
.offset(1)
1959+
.setAncestor(oldAncestorKey)
1960+
.setAncestor(ancestorKey);
1961+
assert.deepStrictEqual(entity.queryToQueryProto(query), queryProto);
1962+
});
1963+
19181964
it('should support the filter method with AND', () => {
19191965
const ancestorKey = new entity.Key({
19201966
path: ['Kind2', 'somename'],

test/query.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,13 @@ describe('Query', () => {
178178
new Query(['kind1']).filter('name', 'Stephen');
179179
});
180180
});
181-
181+
describe('setAncestor', () => {
182+
it('should set the ancestor for the query to search against', done => {
183+
const key = ['kind2', 123];
184+
const query = new Query(['kind1']).setAncestor(key);
185+
assert.deepStrictEqual(query.ancestor, key);
186+
});
187+
});
182188
describe('filter with Filter class', () => {
183189
it('should support filter with Filter', () => {
184190
const now = new Date();

0 commit comments

Comments
 (0)