A platform for community discussion. Free, open, simple.
DEV: correctly handle contract error in chat sdk (#37446)
Joffrey JAFFEUXefd6f516fc5f
diff --git a/plugins/chat/lib/chat_sdk/channel.rb b/plugins/chat/lib/chat_sdk/channel.rbindex 3e11e47a65e..acaa26012ff 100644--- a/plugins/chat/lib/chat_sdk/channel.rb+++ b/plugins/chat/lib/chat_sdk/channel.rb@@ -28,9 +28,10 @@ module ChatSDK},) doon_success { |messages:| messages }- on_failure { raise "Unexpected error" }+ on_failed_contract { |contract| raise contract.errors.full_messages.join(", ") }on_failed_policy(:can_view_channel) { raise "Guardian can't view channel" }on_failed_policy(:target_message_exists) { raise "Target message doesn't exist" }+ on_failure { raise "Unexpected error" }endenddiff --git a/plugins/chat/spec/lib/chat_sdk/channel_spec.rb b/plugins/chat/spec/lib/chat_sdk/channel_spec.rbindex 3acfe98bd9c..bf55b7ae2d7 100644--- a/plugins/chat/spec/lib/chat_sdk/channel_spec.rb+++ b/plugins/chat/spec/lib/chat_sdk/channel_spec.rb@@ -30,13 +30,21 @@ describe ChatSDK::Channel doendend- context "when target_message doesn’t exist" do+ context "when target_message doesn't exist" doit "fails" doexpect { described_class.messages(**params, target_message_id: -999) }.to raise_error("Target message doesn't exist",)endend++ context "when direction is invalid" do+ it "fails" do+ expect { described_class.messages(**params, direction: "invalid") }.to raise_error(+ "Direction is not included in the list",+ )+ end+ endenddescribe ".start_reply" do