Skip to content

Commit

Permalink
encode URL of imported vector data again (#2820)
Browse files Browse the repository at this point in the history
* fix forUrl(): take the URL as ID again if not specified

* improve doc
  • Loading branch information
taulinger authored Jan 16, 2025
1 parent 838cd29 commit 3c9d312
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/services/ImportVectorDataService.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { UnavailableGeoResourceError } from '../domain/errors';
/**
*
* @typedef {Object} ImportVectorDataOptions
* @property {string} [id] the ID of the created VectorGeoResource. If not set, id will be created
* @property {string} [id] the ID of the created VectorGeoResource. If not set, it will be created, or if the VectorGeoResource is imported from a URL, the URL will be taken as the ID.
* @property {string} [label] the label of the created VectorGeoResource
* @property {SourceType|VectorSourceType} [sourceType] the source type. Can be either a SourceType or a VectorSourceType instance. If not set it will be tried to detect it
*/
Expand Down Expand Up @@ -58,7 +58,8 @@ export class ImportVectorDataService {
* @returns GeoResourceFuture or `null` when given source type is not supported
*/
forUrl(url, options = {}) {
const { id, label, sourceType } = { ...this._newDefaultImportVectorDataOptions(), ...options };
// const { id, label, sourceType } = { ...this._newDefaultImportVectorDataOptions(), ...options };
const { id, label, sourceType } = { ...this._newDefaultImportVectorDataOptions(), ...options, ...{ id: options.id ?? url } };

// check if optional sourceType is supported
if (sourceType && !this._mapSourceTypeToVectorSourceType(sourceType)) {
Expand Down
35 changes: 35 additions & 0 deletions test/service/ImportVectorDataService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,41 @@ describe('ImportVectorDataService', () => {
});

describe('forUrl', () => {
it('returns a GeoResourceFuture', () => {
const instanceUnderTest = setup();
const url = 'http://my.url';
const options = {
label: 'label',
sourceType: VectorSourceType.KML
};
const geoResourceServiceSpy = spyOn(geoResourceService, 'addOrReplace').and.callFake(addOrReplaceMethodMock);

const geoResourceFuture = instanceUnderTest.forUrl(url, options);

expect(geoResourceFuture.id).toBe(url);
expect(geoResourceFuture.label).toBeNull();
expect(geoResourceServiceSpy).toHaveBeenCalledWith(geoResourceFuture);
expect(geoResourceFuture.marker).toBe(handledByGeoResourceServiceMarker);
});

it('returns a GeoResourceFuture for given ID', () => {
const instanceUnderTest = setup();
const url = 'http://my.url';
const options = {
id: 'http://my.url||foo||true',
label: 'label',
sourceType: VectorSourceType.KML
};
const geoResourceServiceSpy = spyOn(geoResourceService, 'addOrReplace').and.callFake(addOrReplaceMethodMock);

const geoResourceFuture = instanceUnderTest.forUrl(url, options);

expect(geoResourceFuture.id).toBe(options.id);
expect(geoResourceFuture.label).toBeNull();
expect(geoResourceServiceSpy).toHaveBeenCalledWith(geoResourceFuture);
expect(geoResourceFuture.marker).toBe(handledByGeoResourceServiceMarker);
});

it('returns a GeoResourceFuture for given VectorSourceType', () => {
const instanceUnderTest = setup();
const url = 'http://my.url';
Expand Down

0 comments on commit 3c9d312

Please sign in to comment.