Skip to content

Commit 43988d9

Browse files
committed
Not throw on sparse data layers.
Rerutrn 204 if QuadTreeIndex response is empty. Resolves: OLPSUP-16894 Signed-off-by: Oleksii Zubko <[email protected]>
1 parent f3f336c commit 43988d9

File tree

2 files changed

+67
-13
lines changed

2 files changed

+67
-13
lines changed

@here/olp-sdk-dataservice-read/lib/utils/getTile.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,12 @@ export async function getTile(
149149
}
150150

151151
if (!quadTreeIndex.subQuads || !quadTreeIndex.subQuads.length) {
152-
return Promise.reject(new Error("Error fetching QuadTreeIndex"));
152+
return Promise.resolve(
153+
new Response("No Content", {
154+
status: 204,
155+
statusText: "No Content"
156+
})
157+
);
153158
}
154159

155160
// Return the data for the requested QuadKey or for the closest parent

@here/olp-sdk-dataservice-read/test/unit/getTile.test.ts

+61-12
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,75 @@
1717
* License-Filename: LICENSE
1818
*/
1919

20-
import { assert } from "chai";
20+
import { assert, expect } from "chai";
2121
import { TileRequest, getTile } from "@here/olp-sdk-dataservice-read/lib";
22-
import { OlpClientSettings, HRN } from "@here/olp-sdk-core";
22+
import * as core from "@here/olp-sdk-core";
23+
import { QueryApi } from "@here/olp-sdk-dataservice-api";
24+
import sinon = require("sinon");
25+
import { FetchOptions } from "@here/olp-sdk-core";
2326

2427
describe("getTile", function() {
25-
const settings = new OlpClientSettings({
26-
environment: "mock-env",
27-
getToken: () => Promise.resolve("mocked-token"),
28-
dm: {
29-
download: (url: string) =>
30-
Promise.resolve(new Response("test-response"))
31-
}
28+
const request = new TileRequest();
29+
30+
let sandbox: sinon.SinonSandbox;
31+
let quadTreeIndexStub: sinon.SinonStub;
32+
let olpClientSettingsStub: sinon.SinonStubbedInstance<core.OlpClientSettings>;
33+
34+
let getBaseUrlRequestStub: sinon.SinonStub;
35+
const fakeURL = "http://fake-base.url";
36+
37+
before(function() {
38+
sandbox = sinon.createSandbox();
3239
});
3340

34-
const request = new TileRequest();
41+
beforeEach(function() {
42+
olpClientSettingsStub = sandbox.createStubInstance(
43+
core.OlpClientSettings
44+
);
45+
46+
quadTreeIndexStub = sandbox.stub(QueryApi, "quadTreeIndex");
47+
48+
getBaseUrlRequestStub = sandbox.stub(core.RequestFactory, "getBaseUrl");
49+
getBaseUrlRequestStub.callsFake(() => Promise.resolve(fakeURL));
50+
});
51+
52+
afterEach(function() {
53+
sandbox.restore();
54+
});
55+
56+
it("Should return 204 response if no quadTreeIndex data", async function() {
57+
const mockedQuadKeyTreeData = {
58+
subQuads: [],
59+
parentQuads: []
60+
};
61+
62+
quadTreeIndexStub.callsFake(
63+
(builder: any, params: any): Promise<QueryApi.Index> => {
64+
return Promise.resolve(mockedQuadKeyTreeData);
65+
}
66+
);
67+
68+
const response = await getTile(
69+
new TileRequest()
70+
.withTileKey({ row: 0, column: 0, level: 0 })
71+
.withFetchOption(FetchOptions.OnlineOnly),
72+
{
73+
settings: olpClientSettingsStub as any,
74+
catalogHrn: core.HRN.fromString("hrn:here:data:::mocked-hrn"),
75+
layerId: "mocked-layer-id",
76+
layerType: "versioned",
77+
catalogVersion: 123
78+
}
79+
);
80+
81+
expect(response.status).eqls(204);
82+
expect(response.statusText).eqls("No Content");
83+
});
3584

3685
it("Should throw an error if not tile key", async function() {
3786
const tile = await getTile(request, {
38-
settings,
39-
catalogHrn: HRN.fromString("hrn:here:data:::mocked-hrn"),
87+
settings: olpClientSettingsStub as any,
88+
catalogHrn: core.HRN.fromString("hrn:here:data:::mocked-hrn"),
4089
layerId: "mocked-layer-id",
4190
layerType: "versioned"
4291
}).catch(err => err.message);

0 commit comments

Comments
 (0)