Skip to content

Commit

Permalink
chore: update ruby client to include new fields: is_cost_data_ready, …
Browse files Browse the repository at this point in the history
…cost_in_pounds, cost_details
  • Loading branch information
joybytes committed Jul 22, 2024
1 parent dea03d6 commit c1bcdf2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 15 deletions.
3 changes: 3 additions & 0 deletions lib/notifications/client/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class Notification
completed_at
created_by_name
one_click_unsubscribe_url
cost_in_pounds
is_cost_data_ready
cost_details
).freeze

attr_reader(*FIELDS)
Expand Down
35 changes: 35 additions & 0 deletions lib/notifications/client/response_costdetails.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'time'

module Notifications
class Client
class CostDetails
FIELDS = %i(
billable_sms_fragments
international_rate_multiplier
sms_rate
billable_sheets_of_paper
postage
).freeze

attr_reader(*FIELDS)

def initialize(cost_details)
FIELDS.each do |field|
instance_variable_set(:"@#{field}", cost_details.fetch(field.to_s, nil))
end
end

%i(
billable_sms_fragments
international_rate_multiplier
sms_rate
billable_sheets_of_paper
postage
).each do |field|
define_method field do
instance_variable_get(:"@#{field}")
end
end
end
end
end
5 changes: 5 additions & 0 deletions spec/factories/client_notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
"sent_at" => "2016-11-29T11:12:40.12354Z",
"completed_at" => "2016-11-29T11:12:52.12354Z",
"created_by_name" => "A. Sender",
"cost_details" => {
"billable_sms_fragments" => 1,
"international_rate_multiplier" => 1.0,
"sms_rate" => 0.05
}
}
end
end
Expand Down
28 changes: 13 additions & 15 deletions spec/notifications/client/get_notification_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
describe Notifications::Client do
let(:client) { build :notifications_client }

let(:uri) {
URI.parse(Notifications::Client::PRODUCTION_BASE_URL)
}
let(:uri) { URI.parse(Notifications::Client::PRODUCTION_BASE_URL) }

describe "get a notification by id" do
before do
Expand All @@ -13,17 +10,9 @@
).to_return(body: mocked_response.to_json)
end

let(:id) {
"1"
}

let!(:notification) {
client.get_notification(id)
}

let(:mocked_response) {
attributes_for(:client_notification)[:body]
}
let(:id) { "1" }
let!(:notification) { client.get_notification(id) }
let(:mocked_response) { attributes_for(:client_notification)[:body] }

it "expects notification" do
expect(notification).to be_a(
Expand All @@ -43,6 +32,8 @@
sent_at
completed_at
created_by_name
cost_in_pounds
is_cost_data_ready
).each do |field|
it "expect to include #{field}" do
expect(
Expand All @@ -51,6 +42,13 @@
end
end

it "expect to include cost_details" do
expect(notification.cost_details).to be_a(Notifications::Client::CostDetails)
expect(notification.cost_details.billable_sms_fragments).to_not be_nil
expect(notification.cost_details.international_rate_multiplier).to_not be_nil
expect(notification.cost_details.sms_rate).to_not be_nil
end

it "parses the time correctly" do
expect(notification.created_at.to_s).to eq("2016-11-29 11:12:30 UTC")
end
Expand Down

0 comments on commit c1bcdf2

Please sign in to comment.