Skip to content

Commit

Permalink
added support for v3.1-RC
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessandro100 committed May 23, 2024
1 parent 203896f commit ac7b598
Show file tree
Hide file tree
Showing 24 changed files with 3,572 additions and 33 deletions.
2 changes: 1 addition & 1 deletion RULES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This project validates feeds up to version 3.0 of the [JSON Schemas](https://github.com/MobilityData/gbfs-json-schema).
This project validates feeds up to version 3.1-RC of the [JSON Schemas](https://github.com/MobilityData/gbfs-json-schema).
# Files presence
The validator will flag any missing file. It will inform the user if the missing file is required or not, as per the conditions in the GBFS version that it detects.

Expand Down
64 changes: 32 additions & 32 deletions gbfs-validator/__test__/__snapshots__/gbfs.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

exports[`initialization should correctly initialize validator per default 1`] = `
GBFS {
"auth": Object {},
"gotOptions": Object {
"headers": Object {
"auth": {},
"gotOptions": {
"headers": {
"user-agent": "MobilityData GBFS-Validator/1.1.1 (Node 16.0.1)",
},
},
"options": Object {
"options": {
"docked": false,
"freefloating": false,
"version": null,
Expand All @@ -19,13 +19,13 @@ GBFS {

exports[`initialization should correctly initialize validator with options 1`] = `
GBFS {
"auth": Object {},
"gotOptions": Object {
"headers": Object {
"auth": {},
"gotOptions": {
"headers": {
"user-agent": "MobilityData GBFS-Validator/1.1.1 (Node 16.0.1)",
},
},
"options": Object {
"options": {
"docked": true,
"freefloating": true,
"version": "v2.1",
Expand All @@ -38,19 +38,19 @@ exports[`initialization should throw an error without url 1`] = `"Missing URL"`;

exports[`initialization with auth should correctly initialize with \`basic_auth\` 1`] = `
GBFS {
"auth": Object {
"basicAuth": Object {
"auth": {
"basicAuth": {
"password": "mypassword",
"user": "myuser",
},
"type": "basic_auth",
},
"gotOptions": Object {
"headers": Object {
"gotOptions": {
"headers": {
"Authorization": "basic bXl1c2VyOm15cGFzc3dvcmQ=",
},
},
"options": Object {
"options": {
"docked": false,
"freefloating": false,
"version": null,
Expand All @@ -61,18 +61,18 @@ GBFS {

exports[`initialization with auth should correctly initialize with \`bearer_token\` 1`] = `
GBFS {
"auth": Object {
"bearerToken": Object {
"auth": {
"bearerToken": {
"token": "mytoken",
},
"type": "bearer_token",
},
"gotOptions": Object {
"headers": Object {
"gotOptions": {
"headers": {
"Authorization": "Bearer mytoken",
},
},
"options": Object {
"options": {
"docked": false,
"freefloating": false,
"version": null,
Expand All @@ -83,32 +83,32 @@ GBFS {

exports[`initialization with auth should correctly initialize with multiple \`headers\` 1`] = `
GBFS {
"auth": Object {
"headers": Array [
Object {
"auth": {
"headers": [
{
"key": "mykey",
"value": "myvalue",
},
Object {
{
"key": "mysecondkey",
"value": "mysecondvalue",
},
Object {
{
"key": "mythirdkey",
"value": "mythirdvalue",
},
],
"type": "headers",
},
"gotOptions": Object {
"headers": Object {
"gotOptions": {
"headers": {
"mykey": "myvalue",
"mysecondkey": "mysecondvalue",
"mythirdkey": "mythirdvalue",
"user-agent": "MobilityData GBFS-Validator/1.1.1 (Node 16.0.1)",
},
},
"options": Object {
"options": {
"docked": false,
"freefloating": false,
"version": null,
Expand All @@ -119,22 +119,22 @@ GBFS {

exports[`initialization with auth should correctly initialize with one \`headers\` 1`] = `
GBFS {
"auth": Object {
"headers": Array [
Object {
"auth": {
"headers": [
{
"key": "mykey",
"value": "myvalue",
},
],
"type": "headers",
},
"gotOptions": Object {
"headers": Object {
"gotOptions": {
"headers": {
"mykey": "myvalue",
"user-agent": "MobilityData GBFS-Validator/1.1.1 (Node 16.0.1)",
},
},
"options": Object {
"options": {
"docked": false,
"freefloating": false,
"version": null,
Expand Down
225 changes: 225 additions & 0 deletions gbfs-validator/__test__/fixtures/conditional_default_reserve_time.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
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-RC',
data: {
feeds: [
{
name: 'system_information',
url: `http://${request.hostname}/system_information.json`
},
{
name: 'station_information',
url: `http://${request.hostname}/station_information.json`
},
{
name: 'vehicle_types',
url: `http://${request.hostname}/vehicle_types.json`
},
{
name: 'system_pricing_plans',
url: `http://${request.hostname}/system_pricing_plans.json`
},
]

}
}
})

app.get('/system_information.json', async function(request, reply) {
return {
last_updated: "2024-05-23T15:30:00Z",
ttl: 0,
version: '3.1-RC',
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: "[email protected]",
languages: ["en"]
}
}
})

app.get('/vehicle_types.json', async function(request, reply) {
return {
last_updated: "2024-05-23T15:30:00Z",
ttl: 0,
version: '3.1-RC',
data: {
vehicle_types: [
{
// default_reserve_time is required
vehicle_type_id: 'abc123',
form_factor: 'scooter',
propulsion_type: 'human',
name: [
{
text: 'Example Bicycle',
language: 'en'
}
],
//default_reserve_time: 30, // should throw error
return_type: ['any_station', 'free_floating'],
vehicle_assets: {
icon_url: 'https://www.example.com/assets/icon_bicycle.svg',
icon_url_dark:
'https://www.example.com/assets/icon_bicycle_dark.svg',
icon_last_modified: '2021-06-15'
},
default_pricing_plan_id: 'car_plan_2',
pricing_plan_ids: ['car_plan_2', 'car_plan_1']
},
{
// default_reserve_time is required
vehicle_type_id: 'efg456',
form_factor: 'car',
propulsion_type: 'electric',
name: [
{
text: 'Example Electric Car',
language: 'en'
}
],
default_reserve_time: 30,
max_range_meters: 100,
return_type: ['any_station', 'free_floating'],
vehicle_assets: {
icon_url: 'https://www.example.com/assets/icon_car.svg',
icon_url_dark: 'https://www.example.com/assets/icon_car_dark.svg',
icon_last_modified: '2021-06-15'
},
default_pricing_plan_id: 'car_plan_1',
pricing_plan_ids: ['car_plan_1', 'car_plan_2', 'car_plan_3']
},
{
// default_reserve_time is NOT required
vehicle_type_id: 'efg4567',
form_factor: 'car',
propulsion_type: 'electric',
name: [
{
text: 'Example Electric Car 2',
language: 'en'
}
],
//default_reserve_time: 30,
max_range_meters: 100,
return_type: ['any_station', 'free_floating'],
vehicle_assets: {
icon_url: 'https://www.example.com/assets/icon_car.svg',
icon_url_dark: 'https://www.example.com/assets/icon_car_dark.svg',
icon_last_modified: '2021-06-15'
},
default_pricing_plan_id: 'car_plan_2',
pricing_plan_ids: ['car_plan_2']
}
]
}
}
})

app.get('/system_pricing_plans.json', async function(request, reply) {
return {
last_updated: "2024-05-23T15:30:00Z",
ttl: 0,
version: '3.1-RC',
data: {
plans: [
{
plan_id: 'car_plan_1',
name: [
{
text: 'Basic',
language: 'en'
}
],
currency: 'USD',
price: 0,
is_taxable: false,
description: [
{
text: 'Basic plan',
language: 'en'
}
],
reservation_price_per_min: 3
},
{
plan_id: 'car_plan_2',
name: [
{
text: 'Basic 2',
language: 'en'
}
],
currency: 'USD',
price: 0,
is_taxable: false,
description: [
{
text: 'Basic plan',
language: 'en'
}
],
},
{
plan_id: 'car_plan_3',
name: [
{
text: 'Basic 3',
language: 'en'
}
],
currency: 'USD',
price: 0,
is_taxable: false,
description: [
{
text: 'Basic plan',
language: 'en'
}
],
reservation_price_flat_rate: 5
},
{
plan_id: 'car_plan_4',
name: [
{
text: 'Basic 4',
language: 'en'
}
],
currency: 'USD',
price: 0,
is_taxable: false,
description: [
{
text: 'Basic plan',
language: 'en'
}
],
reservation_price_flat_rate: 5,
reservation_price_per_min: 3 // this should throw an error
}
]
}
}
})

return app
}

module.exports = build
Loading

0 comments on commit ac7b598

Please sign in to comment.