Skip to content
Merged
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
118 changes: 59 additions & 59 deletions spec/api_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def json(data)
.with(headers: request_headers, body: req.message)
.to_return(status: 200, body: { delivery_id: 1 }.to_json, headers: {})

client.send_email(req).should eq({ "delivery_id" => 1 })
expect(client.send_email(req)).to eq({ "delivery_id" => 1 })
end

it "handles validation failures (400)" do
Expand All @@ -93,10 +93,10 @@ def json(data)
.with(headers: request_headers, body: req.message)
.to_return(status: 400, body: err_json, headers: {})

lambda { client.send_email(req) }.should(
expect { client.send_email(req) }.to(
raise_error(Customerio::InvalidResponse) { |error|
error.message.should eq "example error"
error.code.should eq "400"
expect(error.message).to eq("example error")
expect(error.code).to eq("400")
}
)
end
Expand All @@ -113,10 +113,10 @@ def json(data)
.with(headers: request_headers, body: req.message)
.to_return(status: 500, body: "Server unavailable", headers: {})

lambda { client.send_email(req) }.should(
expect { client.send_email(req) }.to(
raise_error(Customerio::InvalidResponse) { |error|
error.message.should eq "Server unavailable"
error.code.should eq "500"
expect(error.message).to eq("Server unavailable")
expect(error.code).to eq("500")
}
)
end
Expand All @@ -130,7 +130,7 @@ def json(data)
)

req.attach('test', content, encode: false)
req.message[:attachments]['test'].should eq content
expect(req.message[:attachments]['test']).to eq(content)

stub_request(:post, api_uri('/v1/send/email'))
.with(headers: request_headers, body: req.message)
Expand All @@ -148,7 +148,7 @@ def json(data)
)

req.attach('test', content)
req.message[:attachments]['test'].should eq Base64.strict_encode64(content)
expect(req.message[:attachments]['test']).to eq(Base64.strict_encode64(content))

stub_request(:post, api_uri('/v1/send/email'))
.with(headers: request_headers, body: req.message)
Expand All @@ -165,8 +165,8 @@ def json(data)

req.attach('test', 'test-content')

lambda { req.attach('test', '') }.should raise_error(/attachment test already exists/)
req.message[:attachments].should eq({ "test" => Base64.strict_encode64("test-content") })
expect { req.attach('test', '') }.to raise_error(/attachment test already exists/)
expect(req.message[:attachments]).to eq({ "test" => Base64.strict_encode64("test-content") })
end
end

Expand All @@ -183,7 +183,7 @@ def json(data)
.with(headers: request_headers, body: req.message)
.to_return(status: 200, body: { delivery_id: 1 }.to_json, headers: {})

client.send_push(req).should eq({ "delivery_id" => 1 })
expect(client.send_push(req)).to eq({ "delivery_id" => 1 })
end

it "handles validation failures (400)" do
Expand All @@ -200,10 +200,10 @@ def json(data)
.with(headers: request_headers, body: req.message)
.to_return(status: 400, body: err_json, headers: {})

lambda { client.send_push(req) }.should(
expect { client.send_push(req) }.to(
raise_error(Customerio::InvalidResponse) { |error|
error.message.should eq "example error"
error.code.should eq "400"
expect(error.message).to eq("example error")
expect(error.code).to eq("400")
}
)
end
Expand All @@ -220,10 +220,10 @@ def json(data)
.with(headers: request_headers, body: req.message)
.to_return(status: 500, body: "Server unavailable", headers: {})

lambda { client.send_push(req) }.should(
expect { client.send_push(req) }.to(
raise_error(Customerio::InvalidResponse) { |error|
error.message.should eq "Server unavailable"
error.code.should eq "500"
expect(error.message).to eq("Server unavailable")
expect(error.code).to eq("500")
}
)
end
Expand All @@ -240,7 +240,7 @@ def json(data)
}
)

req.message[:custom_device].should eq({
expect(req.message[:custom_device]).to eq({
platform: 'ios',
token: 'sample-token',
})
Expand All @@ -249,7 +249,7 @@ def json(data)
.with(headers: request_headers, body: req.message)
.to_return(status: 200, body: { delivery_id: 2 }.to_json, headers: {})

client.send_push(req).should eq({ "delivery_id" => 2 })
expect(client.send_push(req)).to eq({ "delivery_id" => 2 })
end
end

Expand All @@ -266,7 +266,7 @@ def json(data)
.with(headers: request_headers, body: req.message)
.to_return(status: 200, body: { delivery_id: 1 }.to_json, headers: {})

client.send_sms(req).should eq({ "delivery_id" => 1 })
expect(client.send_sms(req)).to eq({ "delivery_id" => 1 })
end

it "handles validation failures (400)" do
Expand All @@ -283,10 +283,10 @@ def json(data)
.with(headers: request_headers, body: req.message)
.to_return(status: 400, body: err_json, headers: {})

lambda { client.send_sms(req) }.should(
expect { client.send_sms(req) }.to(
raise_error(Customerio::InvalidResponse) { |error|
error.message.should eq "example error"
error.code.should eq "400"
expect(error.message).to eq("example error")
expect(error.code).to eq("400")
}
)
end
Expand All @@ -303,10 +303,10 @@ def json(data)
.with(headers: request_headers, body: req.message)
.to_return(status: 500, body: "Server unavailable", headers: {})

lambda { client.send_sms(req) }.should(
expect { client.send_sms(req) }.to(
raise_error(Customerio::InvalidResponse) { |error|
error.message.should eq "Server unavailable"
error.code.should eq "500"
expect(error.message).to eq("Server unavailable")
expect(error.code).to eq("500")
}
)
end
Expand All @@ -325,7 +325,7 @@ def json(data)
.with(headers: request_headers, body: req.message)
.to_return(status: 200, body: { delivery_id: 1 }.to_json, headers: {})

client.send_inbox_message(req).should eq({ "delivery_id" => 1 })
expect(client.send_inbox_message(req)).to eq({ "delivery_id" => 1 })
end

it "handles validation failures (400)" do
Expand All @@ -342,10 +342,10 @@ def json(data)
.with(headers: request_headers, body: req.message)
.to_return(status: 400, body: err_json, headers: {})

lambda { client.send_inbox_message(req) }.should(
expect { client.send_inbox_message(req) }.to(
raise_error(Customerio::InvalidResponse) { |error|
error.message.should eq "example error"
error.code.should eq "400"
expect(error.message).to eq("example error")
expect(error.code).to eq("400")
}
)
end
Expand All @@ -362,10 +362,10 @@ def json(data)
.with(headers: request_headers, body: req.message)
.to_return(status: 500, body: "Server unavailable", headers: {})

lambda { client.send_inbox_message(req) }.should(
expect { client.send_inbox_message(req) }.to(
raise_error(Customerio::InvalidResponse) { |error|
error.message.should eq "Server unavailable"
error.code.should eq "500"
expect(error.message).to eq("Server unavailable")
expect(error.code).to eq("500")
}
)
end
Expand All @@ -384,7 +384,7 @@ def json(data)
.with(headers: request_headers, body: req.message)
.to_return(status: 200, body: { delivery_id: 1 }.to_json, headers: {})

client.send_in_app(req).should eq({ "delivery_id" => 1 })
expect(client.send_in_app(req)).to eq({ "delivery_id" => 1 })
end

it "handles validation failures (400)" do
Expand All @@ -401,10 +401,10 @@ def json(data)
.with(headers: request_headers, body: req.message)
.to_return(status: 400, body: err_json, headers: {})

lambda { client.send_in_app(req) }.should(
expect { client.send_in_app(req) }.to(
raise_error(Customerio::InvalidResponse) { |error|
error.message.should eq "example error"
error.code.should eq "400"
expect(error.message).to eq("example error")
expect(error.code).to eq("400")
}
)
end
Expand All @@ -421,10 +421,10 @@ def json(data)
.with(headers: request_headers, body: req.message)
.to_return(status: 500, body: "Server unavailable", headers: {})

lambda { client.send_in_app(req) }.should(
expect { client.send_in_app(req) }.to(
raise_error(Customerio::InvalidResponse) { |error|
error.message.should eq "Server unavailable"
error.code.should eq "500"
expect(error.message).to eq("Server unavailable")
expect(error.code).to eq("500")
}
)
end
Expand All @@ -442,7 +442,7 @@ def json(data)
.with(headers: request_headers, body: req.message)
.to_return(status: 200, body: { trigger_id: "abc123" }.to_json, headers: {})

client.trigger_broadcast(req).should eq({ "trigger_id" => "abc123" })
expect(client.trigger_broadcast(req)).to eq({ "trigger_id" => "abc123" })
end

it "sends with email list audience" do
Expand All @@ -457,7 +457,7 @@ def json(data)
.with(headers: request_headers, body: req.message)
.to_return(status: 200, body: { trigger_id: "abc123" }.to_json, headers: {})

client.trigger_broadcast(req).should eq({ "trigger_id" => "abc123" })
expect(client.trigger_broadcast(req)).to eq({ "trigger_id" => "abc123" })
end

it "sends with id list audience" do
Expand All @@ -471,7 +471,7 @@ def json(data)
.with(headers: request_headers, body: req.message)
.to_return(status: 200, body: { trigger_id: "abc123" }.to_json, headers: {})

client.trigger_broadcast(req).should eq({ "trigger_id" => "abc123" })
expect(client.trigger_broadcast(req)).to eq({ "trigger_id" => "abc123" })
end

it "sends with data_file_url audience" do
Expand All @@ -484,35 +484,35 @@ def json(data)
.with(headers: request_headers, body: req.message)
.to_return(status: 200, body: { trigger_id: "abc123" }.to_json, headers: {})

client.trigger_broadcast(req).should eq({ "trigger_id" => "abc123" })
expect(client.trigger_broadcast(req)).to eq({ "trigger_id" => "abc123" })
end

it "raises an error when broadcast_id is missing" do
lambda {
expect {
Customerio::TriggerBroadcastRequest.new(data: { headline: "Test" })
}.should raise_error(ArgumentError, "broadcast_id is required")
}.to raise_error(ArgumentError, "broadcast_id is required")
end

it "raises an error when broadcast_id is not an integer" do
lambda {
expect {
Customerio::TriggerBroadcastRequest.new(broadcast_id: "12")
}.should raise_error(ArgumentError, "broadcast_id must be an integer")
}.to raise_error(ArgumentError, "broadcast_id must be an integer")
end

it "raises an error when multiple audience fields are provided" do
lambda {
expect {
Customerio::TriggerBroadcastRequest.new(
broadcast_id: 12,
emails: ["a@example.com"],
ids: [1, 2],
)
}.should raise_error(ArgumentError, /only one of/)
}.to raise_error(ArgumentError, /only one of/)
end

it "raises an error when request is not a TriggerBroadcastRequest" do
lambda {
expect {
client.trigger_broadcast("not a request")
}.should raise_error(ArgumentError, /must be an instance of/)
}.to raise_error(ArgumentError, /must be an instance of/)
end

it "handles validation failures (400)" do
Expand All @@ -527,10 +527,10 @@ def json(data)
.with(headers: request_headers, body: req.message)
.to_return(status: 400, body: err_json, headers: {})

lambda { client.trigger_broadcast(req) }.should(
expect { client.trigger_broadcast(req) }.to(
raise_error(Customerio::InvalidResponse) { |error|
error.message.should eq "example error"
error.code.should eq "400"
expect(error.message).to eq("example error")
expect(error.code).to eq("400")
}
)
end
Expand All @@ -544,10 +544,10 @@ def json(data)
.with(headers: request_headers, body: req.message)
.to_return(status: 500, body: "Server unavailable", headers: {})

lambda { client.trigger_broadcast(req) }.should(
expect { client.trigger_broadcast(req) }.to(
raise_error(Customerio::InvalidResponse) { |error|
error.message.should eq "Server unavailable"
error.code.should eq "500"
expect(error.message).to eq("Server unavailable")
expect(error.code).to eq("500")
}
)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/base_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def api_client_request_headers
with(headers: api_client_request_headers).
to_return(status: 400, body: "", headers: {})

lambda { api_client.request_and_verify_response(:put, '/some/path', "") }.should(
expect { api_client.request_and_verify_response(:put, '/some/path', "") }.to(
raise_error(Customerio::InvalidResponse)
)
end
Expand All @@ -83,7 +83,7 @@ def api_client_request_headers
with(headers: api_client_request_headers).
to_return(status: 200, body: "Test", headers: {})

api_client.request_and_verify_response(:put, '/some/path', "").body.should eq("Test")
expect(api_client.request_and_verify_response(:put, '/some/path', "").body).to eq("Test")
end
end
end
Loading