Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/ioki/apis/operator_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,13 @@ class OperatorApi
model_class: Ioki::Model::Operator::User,
except: [:update, :delete]
),
Endpoints::Create.new(
:eligibility_group_membership,
base_path: [API_BASE_PATH, 'providers', :id, 'eligibility_group_memberships'],
path: 'manually_assign_by_email_address',
model_class: Ioki::Model::Operator::EligibilityGroupMembership,
method_name: 'eligibility_group_memberships_manually_assign_by_email_address'
),
Endpoints::ShowSingular.new(
:users_recently_used_stations,
base_path: nil,
Expand Down
53 changes: 53 additions & 0 deletions lib/ioki/model/operator/eligibility_group_membership.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# frozen_string_literal: true

module Ioki
module Model
module Operator
class EligibilityGroupMembership < Base
attribute :email_address,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This model is a bit convoluted. It combines the schema used in the POST request with the response serializer. We usually only do that if both are named identically and match conceptually (e.g. POST User schema returns a User). In this context, it seems the two models are conceptually different.

Personally I'd split them up:

  1. Ioki::Model::Operator::EligibilityGroupMembershipManuallyAssignByEmailAddress
  2. Ioki::Model::Operator::EligibilityGroupMembership

You should be able to set the schema as outgoing_model_class in the endpoint configuration.

on: :create,
type: :string

attribute :user_segment_slug,
on: :create,
type: :string

attribute :id,
on: :read,
type: :string

attribute :type,
on: :read,
type: :string

attribute :created_at,
on: :read,
type: :date_time

attribute :updated_at,
on: :read,
type: :date_time

attribute :user_id,
on: :read,
type: :string

attribute :eligibility_group_slug,
on: [:read, :create],
type: :string

attribute :state,
on: :read,
type: :string

attribute :active_strategies,
on: :read,
type: :array

attribute :activated_at,
on: :read,
type: :date_time
end
end
end
end
15 changes: 15 additions & 0 deletions spec/ioki/model/operator/eligibility_group_membership_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

RSpec.describe Ioki::Model::Operator::EligibilityGroupMembership do
it { is_expected.to define_attribute(:email_address).as(:string) }
it { is_expected.to define_attribute(:user_segment_slug).as(:string) }
it { is_expected.to define_attribute(:eligibility_group_slug).as(:string) }
it { is_expected.to define_attribute(:id).as(:string) }
it { is_expected.to define_attribute(:type).as(:string) }
it { is_expected.to define_attribute(:created_at).as(:date_time) }
it { is_expected.to define_attribute(:updated_at).as(:date_time) }
it { is_expected.to define_attribute(:user_id).as(:string) }
it { is_expected.to define_attribute(:state).as(:string) }
it { is_expected.to define_attribute(:active_strategies).as(:array) }
it { is_expected.to define_attribute(:activated_at).as(:date_time) }
end
27 changes: 27 additions & 0 deletions spec/ioki/operator_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,33 @@
end
end

describe '#eligibility_group_memberships_manually_assign_by_email_address(provider_id, membership)' do
let(:membership) do
Ioki::Model::Operator::EligibilityGroupMembership.new(
{
email_address: 'horst.schlemmer@example.com',
user_segment_slug: 'vhh_default',
eligibility_group_slug: 'users_with_driver_assistance'
}
)
end

it 'calls request on the client with expected params' do
expect(operator_client).to receive(:request) do |params|
expect(params[:url].to_s)
.to eq('operator/providers/0815/eligibility_group_memberships/manually_assign_by_email_address')
expect(params[:method]).to eq(:post)
expect(params[:body]).to eq({ data: membership.serialize(:create, format: :json) })
[result_with_data, full_response]
end

expect(
operator_client.eligibility_group_memberships_manually_assign_by_email_address('0815', membership, options)
)
.to be_a(Ioki::Model::Operator::EligibilityGroupMembership)
end
end

describe '#create_ride_inquiry(product_id)' do
let(:ride_inquiry) { Ioki::Model::Operator::RideInquiry.new }

Expand Down