Update URLs tests

This commit is contained in:
Alexis Métaireau 2024-10-23 16:27:30 +02:00 committed by Yohan Boniface
parent c0aef13021
commit f9c50eb788

View file

@ -8,10 +8,10 @@ import URLs from '../js/modules/urls.js'
describe('URLs', () => { describe('URLs', () => {
// Mock server URLs that will be used for testing // Mock server URLs that will be used for testing
const mockServerUrls = { const mockServerUrls = {
map_create: '/maps/create', map_create: '/maps/create/',
map_update: '/maps/{map_id}/update', map_update: '/maps/{map_id}/update/',
datalayer_create: '/maps/{map_id}/datalayers/create', datalayer_create: '/maps/{map_id}/datalayers/{pk}/create/',
datalayer_update: '/maps/{map_id}/datalayers/{pk}/update', datalayer_update: '/maps/{map_id}/datalayers/{pk}/update/',
} }
let urls = new URLs(mockServerUrls) let urls = new URLs(mockServerUrls)
@ -22,37 +22,37 @@ describe('URLs', () => {
}) })
it('should return the correct templated URL for known urlNames', () => { it('should return the correct templated URL for known urlNames', () => {
expect(urls.get('map_create')).to.be.equal('/maps/create') expect(urls.get('map_create')).to.be.equal('/maps/create/')
expect(urls.get('map_update', { map_id: '123' })).to.be.equal('/maps/123/update') 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', () => { it('should return the correct templated URL when provided with parameters', () => {
expect(urls.get('datalayer_update', { map_id: '123', pk: '456' })).to.be.equal( expect(urls.get('datalayer_update', { map_id: '123', pk: '456' })).to.be.equal(
'/maps/123/datalayers/456/update' '/maps/123/datalayers/456/update/'
) )
}) })
}) })
describe('map_save()', () => { describe('map_save()', () => {
it('should return the create URL if no map_id is provided', () => { it('should return the create URL if no map_id is provided', () => {
expect(urls.map_save({})).to.be.equal('/maps/create') expect(urls.map_save({})).to.be.equal('/maps/create/')
}) })
it('should return the update URL if a map_id is provided', () => { 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') expect(urls.map_save({ map_id: '123' })).to.be.equal('/maps/123/update/')
}) })
}) })
describe('datalayer_save()', () => { describe('datalayer_save()', () => {
it('should return the create URL if no pk is provided', () => { it('should return the create URL if created is false', () => {
expect(urls.datalayer_save({ map_id: '123' })).to.be.equal( expect(urls.datalayer_save({ map_id: '123', pk: '00000000-0000-0000-0000-000000000000', created: false })).to.be.equal(
'/maps/123/datalayers/create' '/maps/123/datalayers/00000000-0000-0000-0000-000000000000/create/'
) )
}) })
it('should return the update URL if a pk is provided', () => { it('should return the update URL if created is true', () => {
expect(urls.datalayer_save({ map_id: '123', pk: '456' })).to.be.equal( expect(urls.datalayer_save({ map_id: '123', pk: '00000000-0000-0000-0000-000000000000', created: true })).to.be.equal(
'/maps/123/datalayers/456/update' '/maps/123/datalayers/00000000-0000-0000-0000-000000000000/update/'
) )
}) })
}) })