Skip to content

Commit

Permalink
unit test corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume-d-o committed Feb 26, 2025
1 parent aacca67 commit 2d4efdf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ class DataServiceMock {
},
])
)
getDownloadUrlsFromOgcApi = jest.fn((url: string) =>
url.indexOf('error') > -1
? Promise.reject(new Error('ogc.unreachable.unknown'))
: Promise.resolve({
name: 'collection1',
title: 'Collection 1',
bulkDownloadLinks: {
'application/geo+json': 'http://example.com/collection1.geojson',
'application/json': 'http://example.com/collection1.json',
},
})
)
}

describe('RecordDownloadsComponent', () => {
Expand Down Expand Up @@ -292,6 +304,7 @@ describe('RecordDownloadsComponent', () => {
description: 'OGC API service',
mimeType: 'application/geo+json',
name: 'Surveillance littorale OGC',
title: 'collection1',
url: newUrl(
'https://demo.ldproxy.net/zoomstack/collections/airports/items'
),
Expand All @@ -302,6 +315,7 @@ describe('RecordDownloadsComponent', () => {
description: 'OGC API service',
mimeType: 'application/json',
name: 'Surveillance littorale OGC',
title: 'collection2',
url: newUrl(
'https://demo.ldproxy.net/zoomstack/collections/airports/items'
),
Expand Down
21 changes: 16 additions & 5 deletions libs/feature/dataviz/src/lib/service/data.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,32 @@ jest.mock('@camptocamp/ogc-client', () => ({
},
OgcApiEndpoint: class {
constructor(private url) {
newEndpointCall(url) // to track endpoint creation
newEndpointCall(url)
}
getCollectionInfo() {
getCollectionInfo(collectionName) {
if (this.url.indexOf('error.http') > -1) {
return Promise.reject({
type: 'http',
info: 'Something went wrong',
httpStatus: 403,
})
}
if (this.url === 'https://my.ogc.api/features') {
return Promise.resolve({
name: collectionName,
title:
collectionName === 'collection1' ? 'collection1' : 'collection2',
bulkDownloadLinks: { json: 'http://json', csv: 'http://csv' },
})
}
return Promise.resolve({
bulkDownloadLinks: { json: 'http://json', csv: 'http://csv' },
})
}
allCollections = Promise.resolve([{ name: 'collection1' }])
allCollections = Promise.resolve([
{ name: 'collection1' },
{ name: 'collection2' },
])
featureCollections =
this.url.indexOf('error.http') > -1
? Promise.reject(new Error())
Expand Down Expand Up @@ -575,7 +586,7 @@ describe('DataService', () => {
accessServiceProtocol: 'ogcFeatures',
},
{
name: 'collection2',
name: 'collection1',
mimeType: 'text/csv',
url: new URL('http://csv'),
type: 'download',
Expand All @@ -593,7 +604,7 @@ describe('DataService', () => {
accessServiceProtocol: 'ogcFeatures',
})
expect(links[0].name).toBe('collection1')
expect(links[1].name).toBe('collection2')
expect(links[1].name).toBe('collection1')
})
})

Expand Down

0 comments on commit 2d4efdf

Please sign in to comment.