Skip to content

Commit b6249fd

Browse files
authored
Merge pull request #372 from ml054/RDBC-714
RDBC-714 ProjectionBehavior test
2 parents fe5a892 + fd6d9e3 commit b6249fd

File tree

2 files changed

+67
-9
lines changed

2 files changed

+67
-9
lines changed

src/Documents/Session/DocumentQuery.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,14 @@ export class DocumentQuery<T extends object>
148148
propertiesOrQueryData.isProjectInto = true;
149149
const queryData = propertiesOrQueryData as QueryData;
150150

151-
// add nested object types to result so we can properly read types
151+
// add nested object types to result, so we can properly read types
152152
if (!queryData.isCustomFunction) {
153153
queryData.fields = [...queryData.fields, `${CONSTANTS.Documents.Metadata.KEY}.${CONSTANTS.Documents.Metadata.NESTED_OBJECT_TYPES}`];
154154
queryData.projections = [...queryData.projections, CONSTANTS.Documents.Metadata.NESTED_OBJECT_TYPES_PROJECTION_FIELD];
155155
}
156156

157-
queryData.projectionBehavior = projectionBehavior;
157+
// we don't assign here projection behavior as it comes from override which already holds proper behavior from QueryData
158+
// queryData.projectionBehavior = projectionBehavior;
158159

159160
return this.createDocumentQueryInternal(projectionType, queryData);
160161
}
@@ -211,10 +212,10 @@ export class DocumentQuery<T extends object>
211212
public includeExplanations(
212213
explanationsCallback: ValueCallback<Explanations>): IDocumentQuery<T>;
213214
public includeExplanations(
214-
options: ExplanationOptions,
215+
options: ExplanationOptions,
215216
explanationsCallback?: ValueCallback<Explanations>): IDocumentQuery<T>;
216217
public includeExplanations(
217-
optionsOrExplanationsCallback: ExplanationOptions | ValueCallback<Explanations>,
218+
optionsOrExplanationsCallback: ExplanationOptions | ValueCallback<Explanations>,
218219
explanationsCallback?: ValueCallback<Explanations>): IDocumentQuery<T> {
219220
if (arguments.length === 1) {
220221
return this.includeExplanations(
@@ -223,7 +224,7 @@ export class DocumentQuery<T extends object>
223224

224225
this._includeExplanations(
225226
optionsOrExplanationsCallback as ExplanationOptions, explanationsCallback);
226-
227+
227228
return this;
228229
}
229230

@@ -667,7 +668,7 @@ export class DocumentQuery<T extends object>
667668
}
668669

669670
public highlight(
670-
parameters: HighlightingParameters,
671+
parameters: HighlightingParameters,
671672
hightlightingsCallback: ValueCallback<Highlightings>): IDocumentQuery<T> {
672673
this._highlight(parameters, hightlightingsCallback);
673674
return this;
@@ -740,8 +741,8 @@ export class DocumentQuery<T extends object>
740741
fieldName: Field<T>, shapeWkt: string, relation: SpatialRelation, distanceErrorPct: number): IDocumentQuery<T>;
741742
public relatesToShape(
742743
fieldName: Field<T>,
743-
shapeWkt: string,
744-
relation: SpatialRelation,
744+
shapeWkt: string,
745+
relation: SpatialRelation,
745746
units: SpatialUnits,
746747
distanceErrorPct: number): IDocumentQuery<T>;
747748
public relatesToShape(
@@ -750,7 +751,7 @@ export class DocumentQuery<T extends object>
750751
relation: SpatialRelation,
751752
distanceErrorPctOrUnits?: SpatialUnits | number,
752753
distanceErrorPct?: number): IDocumentQuery<T> {
753-
754+
754755
let units;
755756
if (TypeUtil.isNullOrUndefined(distanceErrorPct)) {
756757
if (TypeUtil.isString(distanceErrorPctOrUnits)) {

test/Issues/RDBC_714.ts

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { AbstractJavaScriptIndexCreationTask, IDocumentStore } from "../../src";
2+
import { disposeTestDocumentStore, testContext, } from "../Utils/TestUtil";
3+
import { assertThat, assertThrows } from "../Utils/AssertExtensions";
4+
import { Employee } from "../Assets/Entities";
5+
6+
describe("RDBC-714", function () {
7+
8+
let store: IDocumentStore;
9+
10+
beforeEach(async function () {
11+
store = await testContext.getDocumentStore();
12+
});
13+
14+
afterEach(async () => {
15+
await disposeTestDocumentStore(store);
16+
});
17+
18+
it("can use projection behavior", async () => {
19+
await store.executeIndex(new Employee_ByFullName());
20+
21+
const session = store.openSession();
22+
await session.store(Object.assign(new Employee(), { firstName: "Robert", lastName: "King" }));
23+
await session.saveChanges();
24+
25+
await testContext.waitForIndexing(store);
26+
27+
const query = session.query(Employee, Employee_ByFullName)
28+
.selectFields(["fullName"], EmployeeProjectedDetails, "FromDocumentOrThrow")
29+
30+
await assertThrows(async () => await query.all(),
31+
err => {
32+
assertThat(err.name)
33+
.isEqualTo("InvalidQueryException");
34+
});
35+
});
36+
})
37+
38+
class Employee_ByFullName extends AbstractJavaScriptIndexCreationTask<Employee> {
39+
public constructor() {
40+
super();
41+
42+
this.map(Employee, e => {
43+
return {
44+
fullName: e.firstName + " " + e.lastName
45+
}
46+
})
47+
48+
this.store("fullName", "Yes");
49+
}
50+
}
51+
52+
class EmployeeProjectedDetails {
53+
private fullName: null;
54+
constructor() {
55+
this.fullName = null;
56+
}
57+
}

0 commit comments

Comments
 (0)