From caae7362f15f2da51a7912243f7674eadd25edef Mon Sep 17 00:00:00 2001 From: Ayushi Agrawal Date: Tue, 10 Dec 2024 15:30:27 +0530 Subject: [PATCH 1/6] Adding result method to MobitelDeliveryDetail class --- app/models/mobitel_delivery_detail.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/mobitel_delivery_detail.rb b/app/models/mobitel_delivery_detail.rb index e010beec55..7232b4eea9 100644 --- a/app/models/mobitel_delivery_detail.rb +++ b/app/models/mobitel_delivery_detail.rb @@ -13,6 +13,10 @@ def in_progress? false end + def result + "sent" + end + def self.create_with_communication!(message:, recipient_number:) ActiveRecord::Base.transaction do delivery_detail = create!( From 501076304fb8944d151adf56fa0abc6428d6f105 Mon Sep 17 00:00:00 2001 From: Ayushi Agrawal Date: Tue, 10 Dec 2024 15:43:12 +0530 Subject: [PATCH 2/6] adding specs --- spec/models/mobitel_delivery_detail_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/models/mobitel_delivery_detail_spec.rb b/spec/models/mobitel_delivery_detail_spec.rb index 3d4b2f6470..83ccdce4e3 100644 --- a/spec/models/mobitel_delivery_detail_spec.rb +++ b/spec/models/mobitel_delivery_detail_spec.rb @@ -36,4 +36,10 @@ expect(communication.detailable.message).to eq message end end + + describe "#result" do + it "returns successful state because messages are either successful or fails at API validation" do + expect(described_class.new.result).to eq("sent") + end + end end From fd0dcec4e5b9e3d9753333fbd6d6cf2a05808675 Mon Sep 17 00:00:00 2001 From: Ayushi Agrawal Date: Tue, 10 Dec 2024 18:04:49 +0530 Subject: [PATCH 3/6] adding more specs --- .../notifications_experiment_spec.rb | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/models/experimentation/notifications_experiment_spec.rb b/spec/models/experimentation/notifications_experiment_spec.rb index dbcf27610d..efea47e828 100644 --- a/spec/models/experimentation/notifications_experiment_spec.rb +++ b/spec/models/experimentation/notifications_experiment_spec.rb @@ -844,4 +844,28 @@ described_class.first.monitor end end + + describe "#notification_result" do + let(:notification) { create(:notification, status: "sent", communications: [communication]) } + + subject { described_class.new.send(:notification_result, notification.id) } + context "with mobitel as sms vendor" do + let(:detailable) { create(:mobitel_delivery_detail) } + let(:communication) { create(:communication, detailable_type: "MobitelDeliveryDetail", detailable_id: detailable.id) } + + it "returns successful result" do + expected_result = { + notification_status: notification.status, + notification_status_updated_at: notification.updated_at, + result: :success, + successful_communication_id: communication.id, + successful_communication_type: communication.communication_type, + successful_communication_created_at: communication.created_at.to_s, + successful_delivery_status: communication.detailable.result + } + expect { subject }.not_to raise_error + expect(subject).to eq(expected_result) + end + end + end end From 471c443d764b17154e5e47b2bda59660bd3c9c9e Mon Sep 17 00:00:00 2001 From: Ayushi Agrawal Date: Tue, 10 Dec 2024 18:32:47 +0530 Subject: [PATCH 4/6] fixing spec fialures --- .../notifications_experiment_spec.rb | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/spec/models/experimentation/notifications_experiment_spec.rb b/spec/models/experimentation/notifications_experiment_spec.rb index efea47e828..b0c583f0d9 100644 --- a/spec/models/experimentation/notifications_experiment_spec.rb +++ b/spec/models/experimentation/notifications_experiment_spec.rb @@ -852,19 +852,15 @@ context "with mobitel as sms vendor" do let(:detailable) { create(:mobitel_delivery_detail) } let(:communication) { create(:communication, detailable_type: "MobitelDeliveryDetail", detailable_id: detailable.id) } - + it "returns successful result" do - expected_result = { - notification_status: notification.status, - notification_status_updated_at: notification.updated_at, - result: :success, - successful_communication_id: communication.id, - successful_communication_type: communication.communication_type, - successful_communication_created_at: communication.created_at.to_s, - successful_delivery_status: communication.detailable.result - } expect { subject }.not_to raise_error - expect(subject).to eq(expected_result) + actual_result = subject + expect(actual_result[:notification_status]).to eq(notification.status) + expect(actual_result[:successful_communication_id]).to eq(communication.id) + expect(actual_result[:successful_communication_type]).to eq(communication.communication_type) + expect(actual_result[:successful_delivery_status]).to eq(communication.detailable.result) + expect(actual_result[:notification_status_updated_at].to_date).to eq(notification.updated_at.to_date) end end end From 84b114f407c9c70fc0325bd1ce7c7d594feb0f07 Mon Sep 17 00:00:00 2001 From: Ayushi Agrawal Date: Wed, 11 Dec 2024 17:55:08 +0530 Subject: [PATCH 5/6] adding specs for each detailable type --- .../notifications_experiment_spec.rb | 51 ++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/spec/models/experimentation/notifications_experiment_spec.rb b/spec/models/experimentation/notifications_experiment_spec.rb index b0c583f0d9..ea7ae84b0c 100644 --- a/spec/models/experimentation/notifications_experiment_spec.rb +++ b/spec/models/experimentation/notifications_experiment_spec.rb @@ -847,11 +847,58 @@ describe "#notification_result" do let(:notification) { create(:notification, status: "sent", communications: [communication]) } + let(:communication) { create(:communication, detailable_type: detailable_type, detailable_id: detailable.id) } subject { described_class.new.send(:notification_result, notification.id) } - context "with mobitel as sms vendor" do + + context "with Mobitel as sms vendor" do let(:detailable) { create(:mobitel_delivery_detail) } - let(:communication) { create(:communication, detailable_type: "MobitelDeliveryDetail", detailable_id: detailable.id) } + let(:detailable_type) { "MobitelDeliveryDetail" } + + it "returns successful result" do + expect { subject }.not_to raise_error + actual_result = subject + expect(actual_result[:notification_status]).to eq(notification.status) + expect(actual_result[:successful_communication_id]).to eq(communication.id) + expect(actual_result[:successful_communication_type]).to eq(communication.communication_type) + expect(actual_result[:successful_delivery_status]).to eq(communication.detailable.result) + expect(actual_result[:notification_status_updated_at].to_date).to eq(notification.updated_at.to_date) + end + end + + context "with AlphaSMS as vendor" do + let(:detailable) { create(:alpha_sms_delivery_detail, request_status: "Sent") } + let(:detailable_type) { "AlphaSmsDeliveryDetail" } + + it "returns successful result" do + expect { subject }.not_to raise_error + actual_result = subject + expect(actual_result[:notification_status]).to eq(notification.status) + expect(actual_result[:successful_communication_id]).to eq(communication.id) + expect(actual_result[:successful_communication_type]).to eq(communication.communication_type) + expect(actual_result[:successful_delivery_status]).to eq(communication.detailable.result) + expect(actual_result[:notification_status_updated_at].to_date).to eq(notification.updated_at.to_date) + end + end + + context "with BSNL as vendor" do + let(:detailable) { create(:bsnl_delivery_detail, message_status: "7") } + let(:detailable_type) { "BsnlDeliveryDetail" } + + it "returns successful result" do + expect { subject }.not_to raise_error + actual_result = subject + expect(actual_result[:notification_status]).to eq(notification.status) + expect(actual_result[:successful_communication_id]).to eq(communication.id) + expect(actual_result[:successful_communication_type]).to eq(communication.communication_type) + expect(actual_result[:successful_delivery_status]).to eq(communication.detailable.result) + expect(actual_result[:notification_status_updated_at].to_date).to eq(notification.updated_at.to_date) + end + end + + context "with Twilio as vendor" do + let(:detailable) { create(:twilio_sms_delivery_detail, result: "sent") } + let(:detailable_type) { "TwilioSmsDeliveryDetail" } it "returns successful result" do expect { subject }.not_to raise_error From b25886bd83bccdd041b12da5248255e232f4d814 Mon Sep 17 00:00:00 2001 From: Ayushi Agrawal Date: Thu, 12 Dec 2024 12:32:58 +0530 Subject: [PATCH 6/6] standardrb fixes --- spec/models/experimentation/notifications_experiment_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/experimentation/notifications_experiment_spec.rb b/spec/models/experimentation/notifications_experiment_spec.rb index ea7ae84b0c..45f570f75a 100644 --- a/spec/models/experimentation/notifications_experiment_spec.rb +++ b/spec/models/experimentation/notifications_experiment_spec.rb @@ -896,7 +896,7 @@ end end - context "with Twilio as vendor" do + context "with Twilio as vendor" do let(:detailable) { create(:twilio_sms_delivery_detail, result: "sent") } let(:detailable_type) { "TwilioSmsDeliveryDetail" }