Sha256: 276cb36c401fb4d7dc936e9f4dc6086611d5360b85bfa3d0a40db3d00bb22007

Contents?: true

Size: 1.35 KB

Versions: 6

Compression:

Stored size: 1.35 KB

Contents

require "spec_helper"

RSpec.describe Ribose::Client do
  describe "#new" do
    context "no attribtues provided" do
      it "initialize with default configuration" do
        client = Ribose::Client.new

        expect(client.api_token).to eq(Ribose.configuration.api_token)
        expect(client.user_email).to eq(Ribose.configuration.user_email)
      end
    end

    context "custom attribtues provided" do
      it "initialize with the supplied attribtues" do
        client = Ribose::Client.new(token: 123, email: "john@ex.com")

        expect(client.api_token).to eq("123")
        expect(client.user_email).to eq("john@ex.com")
      end
    end
  end

  describe ".from_login" do
    it "authenticate the user and build a client" do
      email = "useremail@example..com"
      password = "supersecretpassword"

      allow(Ribose::Session).to receive(:create).and_return(session_hash)
      client = Ribose::Client.from_login(email: email, password: password)

      expect(client.user_email).to eq(email)
      expect(client.api_token).to eq(session_hash["authentication_token"])
    end
  end

  def session_hash
    {
      "authentication_token" => "SecretToken",
      "last_activity" => {
        "id" => 122072207,
        "session_id" => "SessionId",
        "browser" => "Ribose Ruby Client",
        "user_id" => "user-uuid-123-4567"
      },
    }
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ribose-0.4.1 spec/ribose/client_spec.rb
ribose-0.4.0 spec/ribose/client_spec.rb
ribose-0.3.2 spec/ribose/client_spec.rb
ribose-0.3.1 spec/ribose/client_spec.rb
ribose-0.3.0 spec/ribose/client_spec.rb
ribose-0.2.0 spec/ribose/client_spec.rb