Skip to content

Commit

Permalink
WIP: Index endpoint specs
Browse files Browse the repository at this point in the history
  • Loading branch information
A5308Y committed Nov 29, 2021
1 parent 3c86ba9 commit b769653
Show file tree
Hide file tree
Showing 4 changed files with 1,539 additions and 27 deletions.
60 changes: 35 additions & 25 deletions lib/ioki/apis/platform_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,69 +49,79 @@ class PlatformApi
base_path: [API_BASE_PATH, 'products', :id],
model_class: Ioki::Model::Platform::DriverVehicleConnection
),
Endpoints.crud_endpoints(
Endpoints::ShowSingular.new(
:client,
base_path: [API_BASE_PATH, 'client'],
except: [:create, :update, :delete],
base_path: [API_BASE_PATH],
model_class: Ioki::Model::Platform::Client
),
Endpoints.crud_endpoints(
Endpoints::Show.new(
:driver_emergency,
base_path: [API_BASE_PATH, 'products', :id],
model_class: Ioki::Model::Platform::DriverEmergency
),
Endpoints::Index.new(
:driver_emergencies,
base_path: [API_BASE_PATH, 'products', :product_id, 'driver_emergencies'],
except: [:create, :update, :delete],
base_path: [API_BASE_PATH, 'products', :id],
model_class: Ioki::Model::Platform::DriverEmergency
),
Endpoints.crud_endpoints(
:pauses,
base_path: [API_BASE_PATH, 'products', :product_id, 'task_lists', :task_list_id, 'pauses'],
:pause,
base_path: [API_BASE_PATH, 'products', :id, 'task_lists', :id],
except: [:create, :update, :delete],
model_class: Ioki::Model::Platform::Pause
),
Endpoints.crud_endpoints(
:receipts,
base_path: [API_BASE_PATH, 'providers', :provider_id, 'receipts'],
:receipt,
base_path: [API_BASE_PATH, 'providers', :id],
except: [:create, :update, :delete],
model_class: Ioki::Model::Platform::Receipt
),
Endpoints.crud_endpoints(
:station_deactivations,
base_path: [API_BASE_PATH, 'products', :product_id, 'stations', :station_id, 'deactivations'],
:station_deactivation,
base_path: [API_BASE_PATH, 'products', :id, 'stations', :id],
paths: {
show: 'deactivation',
index: 'deactivations'
},
except: [:create, :update, :delete],
model_class: Ioki::Model::Platform::Deactivation
),
Endpoints.crud_endpoints(
:task_list_deactivations,
base_path: [API_BASE_PATH, 'products', :product_id, 'task_lists', :task_list_id, 'deactivations'],
:task_list_deactivation,
base_path: [API_BASE_PATH, 'products', :id, 'task_lists', :id],
paths: {
show: 'deactivation',
index: 'deactivations'
},
except: [:create, :update, :delete],
model_class: Ioki::Model::Platform::Deactivation
),
Endpoints.crud_endpoints(
Endpoints::ShowSingular.new(
:current_journey,
base_path: [API_BASE_PATH, 'products', :product_id, 'task_lists', :id, 'current_journey'],
except: [:create, :update, :delete],
base_path: [API_BASE_PATH, 'products', :id, 'task_lists', :id],
model_class: Ioki::Model::Platform::Journey
),
Endpoints.crud_endpoints(
:task_lists,
base_path: [API_BASE_PATH, 'products', :product_id, 'task_lists'],
:task_list,
base_path: [API_BASE_PATH, 'products', :id],
except: [:create, :update, :delete],
model_class: Ioki::Model::Platform::TaskList
),
Endpoints.crud_endpoints(
:tasks,
base_path: [API_BASE_PATH, 'products', :product_id, 'task_lists', :task_list_id, 'tasks'],
:task,
base_path: [API_BASE_PATH, 'products', :id, 'task_lists', :id],
except: [:create, :update, :delete],
model_class: Ioki::Model::Platform::Task
),
Endpoints.crud_endpoints(
:service_credits,
base_path: [API_BASE_PATH, 'providers', :provider_id, 'users', :id, 'service_credits'],
:service_credit,
base_path: [API_BASE_PATH, 'providers', :id, 'users', :id],
except: [:create, :update, :delete],
model_class: Ioki::Model::Platform::ServiceCredit
),
Endpoints.crud_endpoints(
:webhooks,
base_path: [API_BASE_PATH, 'providers', :provider_id, 'webhooks'],
:webhook,
base_path: [API_BASE_PATH, 'providers', :id],
except: [:create, :update, :delete],
model_class: Ioki::Model::Platform::Webhook
),
Expand Down
2 changes: 1 addition & 1 deletion lib/ioki/model/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def attribute_definitions
attr_accessor :_raw_attributes, :_attributes, :_etag

def initialize(raw_attributes = {}, etag = nil)
@_raw_attributes = raw_attributes.transform_keys(&:to_sym)
@_raw_attributes = (raw_attributes || {}).transform_keys(&:to_sym)
@_etag = etag
reset_attributes!
end
Expand Down

Large diffs are not rendered by default.

51 changes: 50 additions & 1 deletion spec/ioki/examples/platform_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
# Compare fixtures/vcr_cassettes for the recorded requests and responses for this example.

setup_platform_client(:platform_client)
let(:real_demo_product_id) { platform_client.products.first.id }
let(:real_demo_provider_id) { platform_client.providers.first.id }

describe 'driver_endpoint' do
let(:real_demo_product_id) { platform_client.products.first.id }
let(:new_driver) do
Ioki::Model::Platform::Driver.new(first_name: 'Suzie', last_name: 'Sabastian', username: 'vcr-suszab')
end
Expand All @@ -21,4 +22,52 @@
expect(platform_client.drivers(real_demo_product_id).map(&:username)).not_to include 'vcr-suszab'
end
end

describe 'index endpoints' do
let(:task_list_id) do
platform_client.task_lists(real_demo_product_id, params: { per_page: 1, page: 1 }).first.id
end
let(:station_id) do
platform_client.stations(real_demo_product_id, params: { page: 2 }).
find { |station| station.location_name == 'Deaktivierungstest' }.
id
end

it 'return their corresponding models' do
expect(platform_client.stations(real_demo_product_id).first).to be_a(Ioki::Model::Platform::Station)
expect(platform_client.vehicles(real_demo_product_id).first).to be_a(Ioki::Model::Platform::Vehicle)
expect(platform_client.rides(real_demo_product_id).first).to be_a(Ioki::Model::Platform::Ride)
expect(platform_client.users(real_demo_provider_id).first).to be_a(Ioki::Model::Platform::User)
expect(platform_client.drivers(real_demo_product_id).first).to be_a(Ioki::Model::Platform::Driver)
expect(platform_client.driver_vehicle_connections(real_demo_product_id).first).to be_a(Ioki::Model::Platform::DriverVehicleConnection)
expect(platform_client.client).to be_a(Ioki::Model::Platform::Client)
expect(platform_client.providers.first).to be_a(Ioki::Model::Platform::Provider)
expect(platform_client.products.first).to be_a(Ioki::Model::Platform::Product)
expect(platform_client.station_deactivations(real_demo_product_id, station_id).first).to be_a(Ioki::Model::Platform::Deactivation)
expect(platform_client.task_lists(real_demo_product_id).first).to be_a(Ioki::Model::Platform::TaskList)
expect(platform_client.tasks(real_demo_product_id, task_list_id).first).to be_a(Ioki::Model::Platform::Task)

# expect(platform_client.pauses(real_demo_product_id, task_list_id).first).to be_a(Ioki::Model::Platform::Pause)
# No task-list-pause defined on the test platform. How can I get one?

# expect(platform_client.task_list_deactivations(real_demo_product_id, task_list_id).first).to be_a(Ioki::Model::Platform::Deactivation)
# Don't know how to deactivate task lists yet.

# expect(platform_client.driver_emergencies(real_demo_product_id).first).to be_a(Ioki::Model::Platform::DriverEmergency)
# feature_not_available. Couldn't find out how to activate it in the test product

# expect(platform_client.receipts(real_demo_provider_id).first).to be_a(Ioki::Model::Platform::Receipt)
# No receipt defined on the test platform. How can I get one?

expect(platform_client.current_journey(real_demo_product_id, task_list_id)).to be_a(Ioki::Model::Platform::Journey)
# Has no data here

# user_id = platform_client.users(real_demo_provider_id).first.id
# expect(platform_client.service_credits(real_demo_provider_id, user_id).first).to be_a(Ioki::Model::Platform::ServiceCredit)
# No service_credits found for user

# expect(platform_client.webhooks(real_demo_provider_id).first).to be_a(Ioki::Model::Platform::Webhook)
# No webhook defined on demo product
end
end
end

0 comments on commit b769653

Please sign in to comment.