-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MIJN-9702-CHORE/BAG-endpoint-vervangen-ivm-deprecation-huidig-endpoint (
#1680) * Changed bag to use new endpoint * Removed comments in favor of new variable name * Somewhere into fixing frontend part * Works on frontend, but uncertainty with parsing * Remove unused mock data. The URL is public and called directly * Found new type of address that worked, so added to tests and fixed problem with it. * Replace part with regex * Added some extra tests and fixed them * add type * removed evil snakecase * Give null when no data instead of empty object * Update src/server/services/bag.ts Co-authored-by: Tim van Oostrom <[email protected]> * Update src/server/services/bag.ts Co-authored-by: Tim van Oostrom <[email protected]> * Update src/server/services/bag.ts Co-authored-by: Tim van Oostrom <[email protected]> * Added explicit return type * Fix test --------- Co-authored-by: Tim van Oostrom <[email protected]>
- Loading branch information
1 parent
44e78e2
commit d122c67
Showing
12 changed files
with
446 additions
and
424 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,65 @@ | ||
import nock from 'nock'; | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
import { fetchBAG } from './bag'; | ||
import bagData from '../../../mocks/fixtures/bag.json'; | ||
import { jsonCopy } from '../../universal/helpers/utils'; | ||
import { Adres } from '../../universal/types'; | ||
|
||
describe('BAG service', () => { | ||
const DUMMY_RESPONSE = jsonCopy(bagData); | ||
const REQUEST_ID = 'x'; | ||
const ADDRESS = { | ||
straatnaam: 'straatje', | ||
huisnummer: 25, | ||
woonplaatsNaam: 'Amsterdam', | ||
} as unknown as Adres; | ||
|
||
it('Bag api should reply correctly', async () => { | ||
nock('https://api.data.amsterdam.nl') | ||
.get('/atlas/search/adres/?q=straatje 25&features=2') | ||
.reply(200, DUMMY_RESPONSE); | ||
// This is only a section of the mock data from the source. | ||
const BAG_MOCK_DATA = { | ||
_embedded: { | ||
adresseerbareobjecten: [ | ||
{ | ||
identificatie: '0363200012145295', | ||
huisnummer: 1, | ||
huisletter: null, | ||
huisnummertoevoeging: null, | ||
postcode: '1011PN', | ||
woonplaatsNaam: 'Amsterdam', | ||
adresseerbaarObjectPuntGeometrieWgs84: { | ||
type: 'Point', | ||
coordinates: [4.9001655, 52.3676456], | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
const address = { | ||
straatnaam: 'straatje', | ||
huisnummer: 25, | ||
woonplaatsNaam: 'Amsterdam', | ||
} as unknown as Adres; | ||
function setupNockResponse(reply: number, response?: object) { | ||
nock('https://api.data.amsterdam.nl') | ||
.get( | ||
'/v1/benkagg/adresseerbareobjecten/?openbareruimteNaam=straatje&huisnummer=25' | ||
) | ||
.reply(reply, response); | ||
} | ||
|
||
const rs = await fetchBAG('x', address); | ||
describe('BAG service', () => { | ||
setupNockResponse(200, BAG_MOCK_DATA); | ||
|
||
expect(rs).toStrictEqual({ | ||
test('Bag api should reply correctly', async () => { | ||
const response = await fetchBAG(REQUEST_ID, ADDRESS); | ||
|
||
expect(response).toStrictEqual({ | ||
status: 'OK', | ||
content: { | ||
address, | ||
bagNummeraanduidingId: null, | ||
latlng: null, | ||
address: ADDRESS, | ||
bagNummeraanduidingId: '0363200012145295', | ||
latlng: { | ||
lat: 52.3676456, | ||
lng: 4.9001655, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('Bag api should fail correctly', async () => { | ||
nock('http://api.data.amsterdam.nl') | ||
.get('/bag', { params: { q: 'undefined' } }) | ||
.reply(500); | ||
// Request non-existing mock url | ||
const rs = await fetchBAG('x', {} as any); | ||
|
||
expect(rs).toStrictEqual({ | ||
status: 'ERROR', | ||
message: 'Kon geen correct zoek adres opmaken.', | ||
content: null, | ||
}); | ||
test('No data in response', async () => { | ||
setupNockResponse(200, {}); | ||
const response = await fetchBAG(REQUEST_ID, ADDRESS); | ||
expect(response).toStrictEqual({ status: 'OK', content: null }); | ||
}); | ||
}); |
Oops, something went wrong.