mirror of
https://github.com/umap-project/umap.git
synced 2025-04-28 19:42:36 +02:00
This make it possible to synchronize datalayers before their creation on the server, allowing at the same time to solve issues related to them not being saved (e.g. duplication of geometries) We use the DataLayer._referenceVersion to track if a DataLayer has been saved on the server. After a save, the _referenceVersion is synched with other peers. To pass the reference version from the server to the frontend, we have two options: - use a header - populate the `options.version` field In the case of a GET on a Datalayer, we could not use the `options` scenario because: - the value in the file is not up to date (it was the value the client has before the save) - the python cannot change it on the fly, as the file is served by nginx So we decided to keep using a header. But on the map view, we load all datalayers metadatas in the map options, so here we cannot use the header scenario, so in this specific case we had to populate `options._referenceVersion`. At the same time, we also changed: - Umap.options.umap_id => Umap.id - DataLayer.umap_id => Datalayer.id - fixed the version number returned by DataLayer.version_metadata
59 lines
2 KiB
JavaScript
59 lines
2 KiB
JavaScript
import { describe, it } from 'mocha'
|
|
|
|
import pkg from 'chai'
|
|
const { expect } = pkg
|
|
|
|
import URLs from '../js/modules/urls.js'
|
|
|
|
describe('URLs', () => {
|
|
// Mock server URLs that will be used for testing
|
|
const mockServerUrls = {
|
|
map_create: '/maps/create/',
|
|
map_update: '/maps/{map_id}/update/',
|
|
datalayer_create: '/maps/{map_id}/datalayers/{pk}/create/',
|
|
datalayer_update: '/maps/{map_id}/datalayers/{pk}/update/',
|
|
}
|
|
|
|
let urls = new URLs(mockServerUrls)
|
|
|
|
describe('get()', () => {
|
|
it('should throw an error if the urlName does not exist', () => {
|
|
expect(() => urls.get('non_existent')).to.throw()
|
|
})
|
|
|
|
it('should return the correct templated URL for known urlNames', () => {
|
|
expect(urls.get('map_create')).to.be.equal('/maps/create/')
|
|
expect(urls.get('map_update', { map_id: '123' })).to.be.equal('/maps/123/update/')
|
|
})
|
|
|
|
it('should return the correct templated URL when provided with parameters', () => {
|
|
expect(urls.get('datalayer_update', { map_id: '123', pk: '456' })).to.be.equal(
|
|
'/maps/123/datalayers/456/update/'
|
|
)
|
|
})
|
|
})
|
|
|
|
describe('map_save()', () => {
|
|
it('should return the create URL if no map_id is provided', () => {
|
|
expect(urls.map_save({})).to.be.equal('/maps/create/')
|
|
})
|
|
|
|
it('should return the update URL if a map_id is provided', () => {
|
|
expect(urls.map_save({ map_id: '123' })).to.be.equal('/maps/123/update/')
|
|
})
|
|
})
|
|
|
|
describe('datalayer_save()', () => {
|
|
it('should return the create URL if created is false', () => {
|
|
expect(urls.datalayer_save({ map_id: '123', pk: '00000000-0000-0000-0000-000000000000', created: false })).to.be.equal(
|
|
'/maps/123/datalayers/00000000-0000-0000-0000-000000000000/create/'
|
|
)
|
|
})
|
|
|
|
it('should return the update URL if created is true', () => {
|
|
expect(urls.datalayer_save({ map_id: '123', pk: '00000000-0000-0000-0000-000000000000', created: true })).to.be.equal(
|
|
'/maps/123/datalayers/00000000-0000-0000-0000-000000000000/update/'
|
|
)
|
|
})
|
|
})
|
|
})
|