Skip to content

Not throw on sparse data layers. #496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion @here/olp-sdk-dataservice-read/lib/utils/getTile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,12 @@ export async function getTile(
}

if (!quadTreeIndex.subQuads || !quadTreeIndex.subQuads.length) {
return Promise.reject(new Error("Error fetching QuadTreeIndex"));
return Promise.resolve(
new Response("No Content", {
status: 204,
statusText: "No Content"
})
);
}

// Return the data for the requested QuadKey or for the closest parent
Expand Down
73 changes: 61 additions & 12 deletions @here/olp-sdk-dataservice-read/test/unit/getTile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,75 @@
* License-Filename: LICENSE
*/

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

describe("getTile", function() {
const settings = new OlpClientSettings({
environment: "mock-env",
getToken: () => Promise.resolve("mocked-token"),
dm: {
download: (url: string) =>
Promise.resolve(new Response("test-response"))
}
const request = new TileRequest();

let sandbox: sinon.SinonSandbox;
let quadTreeIndexStub: sinon.SinonStub;
let olpClientSettingsStub: sinon.SinonStubbedInstance<core.OlpClientSettings>;

let getBaseUrlRequestStub: sinon.SinonStub;
const fakeURL = "http://fake-base.url";

before(function() {
sandbox = sinon.createSandbox();
});

const request = new TileRequest();
beforeEach(function() {
olpClientSettingsStub = sandbox.createStubInstance(
core.OlpClientSettings
);

quadTreeIndexStub = sandbox.stub(QueryApi, "quadTreeIndex");

getBaseUrlRequestStub = sandbox.stub(core.RequestFactory, "getBaseUrl");
getBaseUrlRequestStub.callsFake(() => Promise.resolve(fakeURL));
});

afterEach(function() {
sandbox.restore();
});

it("Should return 204 response if no quadTreeIndex data", async function() {
const mockedQuadKeyTreeData = {
subQuads: [],
parentQuads: []
};

quadTreeIndexStub.callsFake(
(builder: any, params: any): Promise<QueryApi.Index> => {
return Promise.resolve(mockedQuadKeyTreeData);
}
);

const response = await getTile(
new TileRequest()
.withTileKey({ row: 0, column: 0, level: 0 })
.withFetchOption(FetchOptions.OnlineOnly),
{
settings: olpClientSettingsStub as any,
catalogHrn: core.HRN.fromString("hrn:here:data:::mocked-hrn"),
layerId: "mocked-layer-id",
layerType: "versioned",
catalogVersion: 123
}
);

expect(response.status).eqls(204);
expect(response.statusText).eqls("No Content");
});

it("Should throw an error if not tile key", async function() {
const tile = await getTile(request, {
settings,
catalogHrn: HRN.fromString("hrn:here:data:::mocked-hrn"),
settings: olpClientSettingsStub as any,
catalogHrn: core.HRN.fromString("hrn:here:data:::mocked-hrn"),
layerId: "mocked-layer-id",
layerType: "versioned"
}).catch(err => err.message);
Expand Down