diff --git a/gbfs-validator/__test__/fixtures/conditional_default_reserve_time.js b/gbfs-validator/__test__/fixtures/conditional_default_reserve_time.js index 0a979e3..afc5df2 100644 --- a/gbfs-validator/__test__/fixtures/conditional_default_reserve_time.js +++ b/gbfs-validator/__test__/fixtures/conditional_default_reserve_time.js @@ -15,8 +15,8 @@ function build(opts = {}) { url: `http://${request.hostname}/system_information.json` }, { - name: 'station_information', - url: `http://${request.hostname}/station_information.json` + name: 'vehicle_status', + url: `http://${request.hostname}/vehicle_status.json` }, { name: 'vehicle_types', @@ -131,6 +131,27 @@ function build(opts = {}) { } }) + app.get('/vehicle_status.json', async function(request, reply) { + return { + last_updated: "2024-05-23T15:30:00Z", + ttl: 0, + version: '3.1-RC3', + data: { + vehicles: [ + { + vehicle_id: 'scooter1', + last_reported: "2024-05-23T15:30:00Z", + lat: 12.345678, + lon: 56.789012, + is_reserved: false, + is_disabled: false, + vehicle_type_id: 'abc123' + } + ] + } + } + }) + app.get('/system_pricing_plans.json', async function(request, reply) { return { last_updated: "2024-05-23T15:30:00Z", diff --git a/gbfs-validator/__test__/fixtures/missing_status_feeds.js b/gbfs-validator/__test__/fixtures/missing_status_feeds.js new file mode 100644 index 0000000..5d839c2 --- /dev/null +++ b/gbfs-validator/__test__/fixtures/missing_status_feeds.js @@ -0,0 +1,74 @@ +const fastify = require('fastify') + +function build(opts = {}) { + const app = fastify(opts) + + app.get('/gbfs.json', async function(request, reply) { + return { + last_updated: "2024-05-23T15:30:00Z", + ttl: 0, + version: '3.1-RC3', + data: { + // station_information is listed without station_status or vehicle_status + feeds: [ + { + name: 'system_information', + url: `http://${request.hostname}/system_information.json` + }, + { + name: 'station_information', + url: `http://${request.hostname}/station_information.json` + } + ] + } + } + }) + + app.get('/system_information.json', async function(request, reply) { + return { + last_updated: "2024-05-23T15:30:00Z", + ttl: 0, + version: '3.1-RC3', + data: { + system_id: 'shared_bike', + name: [ + { + text: 'Shared Bike USA', + language: 'en' + } + ], + timezone: 'Etc/UTC', + opening_hours: "Mo-Fr 08:00-17:00", + feed_contact_email: "gg@gmail.com", + languages: ["en"] + } + } + }) + + app.get('/station_information.json', async function(request, reply) { + return { + last_updated: "2024-05-23T15:30:00Z", + ttl: 0, + version: '3.1-RC3', + data: { + stations: [ + { + station_id: 'station1', + name: [ + { + text: 'Station 1', + language: 'en' + } + ], + lat: 12.345678, + lon: 56.789012 + } + ] + } + } + }) + + return app +} + +module.exports = build diff --git a/gbfs-validator/__test__/gbfs.test.js b/gbfs-validator/__test__/gbfs.test.js index a920f5d..7c6edb3 100644 --- a/gbfs-validator/__test__/gbfs.test.js +++ b/gbfs-validator/__test__/gbfs.test.js @@ -602,6 +602,56 @@ describe('required default_reserve_time on reservation price existing v3.1-RC3', }) }) +describe('station_information listed without station_status or vehicle_status v3.1-RC3', () => { + beforeAll(async () => { + gbfsFeedServer = require('./fixtures/missing_status_feeds')() + + await gbfsFeedServer.listen(serverOpts) + + return gbfsFeedServer + }) + + afterAll(() => { + return gbfsFeedServer.close() + }) + + test('gbfs.json feeds should require station_status or vehicle_status', () => { + const url = `http://${gbfsFeedServer.server.address().address}:${ + gbfsFeedServer.server.address().port + }` + const gbfs = new GBFS(`${url}/gbfs.json`) + + expect.assertions(1) + + return gbfs.validation().then((result) => { + expect(result).toMatchObject({ + summary: expect.objectContaining({ + version: { detected: '3.1-RC3', validated: '3.1-RC3' }, + hasErrors: true + }), + files: expect.arrayContaining([ + expect.objectContaining({ + file: 'gbfs.json', + errors: expect.arrayContaining([ + expect.objectContaining({ + instancePath: '/data/feeds', + schemaPath: '#/properties/data/properties/feeds/allOf/0/anyOf', + message: 'must match a schema in anyOf' + }), + expect.objectContaining({ + instancePath: '/data/feeds', + schemaPath: + '#/properties/data/properties/feeds/allOf/1/then/contains', + message: 'must contain at least 1 valid item(s)' + }) + ]) + }) + ]) + }) + }) + }) +}) + describe('conditional required vehicle_type_id', () => { let gbfsFeedServer diff --git a/gbfs-validator/__test__/gbfs.v3.0.test.js b/gbfs-validator/__test__/gbfs.v3.0.test.js index 03b6c9c..13bcc60 100644 --- a/gbfs-validator/__test__/gbfs.v3.0.test.js +++ b/gbfs-validator/__test__/gbfs.v3.0.test.js @@ -59,6 +59,54 @@ describe('default feed', () => { }) }) +describe('DL-DE-ZERO-2.0 licence', () => { + let gbfsFeedServer + + beforeAll(async () => { + const { MockRequests } = require('./fixtures/v3.0/default') + class LicensedMockRequests extends MockRequests { + system_information(...args) { + const json = super.system_information(...args) + + json.data.license_id = 'DL-DE-ZERO-2.0' + + return json + } + } + + let mockRequests = new LicensedMockRequests() + + gbfsFeedServer = mockRequests.build() + + await gbfsFeedServer.listen(serverOpts) + }) + + afterAll(() => { + return gbfsFeedServer.close() + }) + + test('should validate feed', async () => { + const url = `http://${gbfsFeedServer.server.address().address}:${ + gbfsFeedServer.server.address().port + }` + const gbfs = new GBFS(`${url}/gbfs.json`) + + expect.assertions(2) + + return gbfs.validation().then(result => { + expect(get_errors(result)).toEqual([]) + + expect(result).toMatchObject({ + summary: expect.objectContaining({ + version: { detected: '3.0', validated: '3.0' }, + hasErrors: false + }), + files: expect.any(Array) + }) + }) + }) +}) + describe('invalid feed', () => { let gbfsFeedServer diff --git a/gbfs-validator/versions/gbfs-json-schema b/gbfs-validator/versions/gbfs-json-schema index 916327f..01d4cb4 160000 --- a/gbfs-validator/versions/gbfs-json-schema +++ b/gbfs-validator/versions/gbfs-json-schema @@ -1 +1 @@ -Subproject commit 916327fe43ea79683f57c87bc54fdfc24797862f +Subproject commit 01d4cb480410ca234b1d76799daf474b8f839e85