Sha256: 0da1449c5606a56f12f58a30f0d2befcbe823ed2a48155c026aa186a3ae5f934

Contents?: true

Size: 1.9 KB

Versions: 6

Compression:

Stored size: 1.9 KB

Contents

require "spec_helper"

RSpec.describe PortalConnectors::MessengerPortalClient do
  def client
    @client ||= PortalConnectors::MessengerPortalClient.singleton
  end

  describe "#create_message_request", vcr: true do
    context "success" do
      it "return message request" do
        params = {
          messenger_app: "whatsapp",
          phone_number: "391231231",
          message: "some message"
        }
        data, ok = client.create_message_request(params)
        expect(ok).to be_truthy
        expect(data["messenger_app"]).to eq("whatsapp")
        expect(data["phone_number"]).to eq("391231231")
        expect(data["message"]).to eq("some message")
        expect(data["status"]).to eq("pending")
      end
    end

    context "fail" do
      it "return error" do
        params = {
          phone_number: "391231231",
          message: "some message"
        }
        data, ok = client.create_message_request(params)
        expect(ok).to be_falsy
        expect(data["error"]).to eq("Wrong signature")
      end
    end
  end

  describe "#update_message_request", vcr: true do
    context "success" do
      it "returns message request" do
        params = {
          id: 1,
          user_sent_message_at_timestamp: 1626895951
        }
        data, ok = client.update_message_request(params)
        expect(ok).to be_truthy
        expect(data["messenger_app"]).to eq("whatsapp")
        expect(data["user_phone_number"]).to eq("391231231")
        expect(data["message"]).to eq("some message")
        expect(data["status"]).to eq("pending")
      end
    end

    context "fail" do
      it "returns error" do
        params = {
          id: 1,
          user_sent_message_at_timestamp: 1626895951,
          fake_field: "test"
        }
        data, ok = client.update_message_request(params)
        expect(ok).to be_falsy
        expect(data["error"]).to eq("Wrong signature")
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
portal-connectors-0.58.39xc spec/lib/portal-connectors/messenger_portal_client_spec.rb
portal-connectors-0.58.39xb spec/lib/portal-connectors/messenger_portal_client_spec.rb
portal-connectors-0.58.39xa spec/lib/portal-connectors/messenger_portal_client_spec.rb
portal-connectors-0.58.39fj spec/lib/portal-connectors/messenger_portal_client_spec.rb
portal-connectors-0.58.39fg spec/lib/portal-connectors/messenger_portal_client_spec.rb
portal-connectors-0.58.38xn spec/lib/portal-connectors/messenger_portal_client_spec.rb