|
17 | 17 | * License-Filename: LICENSE
|
18 | 18 | */
|
19 | 19 |
|
20 |
| -import { assert } from "chai"; |
| 20 | +import { assert, expect } from "chai"; |
21 | 21 | 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"; |
23 | 26 |
|
24 | 27 | 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(); |
32 | 39 | });
|
33 | 40 |
|
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 | + }); |
35 | 84 |
|
36 | 85 | it("Should throw an error if not tile key", async function() {
|
37 | 86 | 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"), |
40 | 89 | layerId: "mocked-layer-id",
|
41 | 90 | layerType: "versioned"
|
42 | 91 | }).catch(err => err.message);
|
|
0 commit comments