Skip to content

Commit

Permalink
Adding Query Conformance Tests (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidt-sebastian committed Jan 29, 2018
1 parent f2cccfe commit 0f7a975
Show file tree
Hide file tree
Showing 9 changed files with 359 additions and 156 deletions.
347 changes: 244 additions & 103 deletions conformance/runner.js

Large diffs are not rendered by default.

52 changes: 50 additions & 2 deletions conformance/test-definition.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ option java_package = "com.google.cloud.firestore.conformance";

import "google/firestore/v1beta1/firestore.proto";
import "google/firestore/v1beta1/common.proto";
import "google/firestore/v1beta1/query.proto";

// A collection of tests.
message TestSuite {
Expand All @@ -26,6 +27,7 @@ message Test {
UpdateTest update = 5;
UpdatePathsTest update_paths = 6;
DeleteTest delete = 7;
QueryTest query = 8;
}
}

Expand Down Expand Up @@ -101,7 +103,53 @@ message SetOption {
repeated FieldPath fields = 2; // field paths for a Merge option
}

// A field path.
message QueryTest {
string coll_path = 1; // path of collection, e.g. "projects/projectID/databases/(default)/documents/C"
repeated Clause clauses = 2;
google.firestore.v1beta1.StructuredQuery query = 3;
bool is_error = 4;
}

message Clause {
oneof clause {
Select select = 1;
Where where = 2;
OrderBy order_by = 3;
int32 offset = 4;
int32 limit = 5;
Cursor start_at = 6;
Cursor start_after = 7;
Cursor end_at = 8;
Cursor end_before = 9;
}
}

message Select {
repeated FieldPath fields = 1;
}

message Where {
FieldPath path = 1;
string op = 2;
string json_value = 3;
}

message OrderBy {
FieldPath path = 1;
string direction = 2; // "asc" or "desc"
}

message Cursor {
// one of:
DocSnapshot doc_snapshot = 1;
repeated string json_values = 2;
}

message DocSnapshot {
string path = 1;
string json_data = 2;
}

message FieldPath {
repeated string field = 1;
}
}
Binary file modified conformance/test-suite.binproto
Binary file not shown.
1 change: 1 addition & 0 deletions src/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,5 @@ function convertDocument(document) {
module.exports = {
documentFromJson: convertDocument,
timestampFromJson: convertTimestamp,
valueFromJson: convertValue,
};
2 changes: 1 addition & 1 deletion src/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ class FieldPath extends Path {

/**
* Turns a field path argument into a [FieldPath]{@link FieldPath}.
* Supports FieldPaths as input (which are passed through) and dot-seperated
* Supports FieldPaths as input (which are passed through) and dot-separated
* strings.
*
* @private
Expand Down
9 changes: 7 additions & 2 deletions src/reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -1384,10 +1384,13 @@ class Query {
}

let options = {
before: before,
values: [],
};

if (before) {
options.before = true;
}

for (let i = 0; i < fieldValues.length; ++i) {
let fieldValue = fieldValues[i];

Expand Down Expand Up @@ -1716,7 +1719,9 @@ class Query {

let structuredQuery = reqOpts.structuredQuery;

if (this._fieldFilters.length) {
if (this._fieldFilters.length === 1) {
structuredQuery.where = this._fieldFilters[0].toProto();
} else if (this._fieldFilters.length > 1) {
let filters = [];
for (let fieldFilter of this._fieldFilters) {
filters.push(fieldFilter.toProto());
Expand Down
54 changes: 38 additions & 16 deletions test/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,22 @@ function fieldFilters(fieldPath, op, value) {
filters.push({fieldFilter: filter});
}

return {
where: {
compositeFilter: {
op: 'AND',
filters: filters,
if (filters.length === 1) {
return {
where: {
fieldFilter: filters[0].fieldFilter,
},
},
};
};
} else {
return {
where: {
compositeFilter: {
op: 'AND',
filters: filters,
},
},
};
}
}

function unaryFilters(fieldPath, equals) {
Expand All @@ -108,14 +116,22 @@ function unaryFilters(fieldPath, equals) {
});
}

return {
where: {
compositeFilter: {
op: 'AND',
filters: filters,
if (filters.length === 1) {
return {
where: {
unaryFilter: filters[0].unaryFilter,
},
},
};
};
} else {
return {
where: {
compositeFilter: {
op: 'AND',
filters: filters,
},
},
};
}
}

function orderBy(fieldPath, direction) {
Expand Down Expand Up @@ -164,11 +180,14 @@ function select(field) {
function startAt(before, value) {
let cursor = {
startAt: {
before: before,
values: [],
},
};

if (before) {
cursor.startAt.before = true;
}

let values = [].slice.call(arguments, 1);

for (value of values) {
Expand All @@ -188,11 +207,14 @@ function startAt(before, value) {
function endAt(before, value) {
let cursor = {
endAt: {
before: before,
values: [],
},
};

if (before) {
cursor.endAt.before = true;
}

let values = [].slice.call(arguments, 1);

for (value of values) {
Expand Down
25 changes: 9 additions & 16 deletions test/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,15 @@ function query(transaction) {
},
],
where: {
compositeFilter: {
filters: [
{
fieldFilter: {
field: {
fieldPath: 'foo',
},
op: 'EQUAL',
value: {
stringValue: 'bar',
valueType: 'stringValue',
},
},
},
],
op: 'AND',
fieldFilter: {
field: {
fieldPath: 'foo',
},
op: 'EQUAL',
value: {
stringValue: 'bar',
valueType: 'stringValue',
},
},
},
},
Expand Down
25 changes: 9 additions & 16 deletions test/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,22 +533,15 @@ describe('Query watch', function() {
structuredQuery: {
from: [{collectionId: 'col'}],
where: {
compositeFilter: {
filters: [
{
fieldFilter: {
field: {
fieldPath: 'included',
},
op: 'EQUAL',
value: {
stringValue: 'yes',
valueType: 'stringValue',
},
},
},
],
op: 'AND',
fieldFilter: {
field: {
fieldPath: 'included',
},
op: 'EQUAL',
value: {
stringValue: 'yes',
valueType: 'stringValue',
},
},
},
},
Expand Down

0 comments on commit 0f7a975

Please sign in to comment.