Sha256: 2bfbe14486b01d7b7edc41c8e32a2b774a1f8306d7a06cc719c4a38eb4caf0a1

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

describe PUNK::CreateSessionAction do
  let(:remote_addr) { Faker::Internet.ip_v4_address }
  let(:user_agent) { Faker::Internet.user_agent }

  context "with no claim provided" do
    it "returns a validation error" do
      view = described_class.run(remote_addr: remote_addr, user_agent: user_agent).result.render(:json)
      expect(view).to match("claim is not present")
    end
  end

  context "with an email claim provided" do
    it "created an identity and a session" do
      email = Faker::Internet.email
      view = described_class.run(claim: email, remote_addr: remote_addr, user_agent: user_agent).result.render(:json)
      session = PUNK::Session.find(slug: ActiveSupport::JSON.decode(view)["slug"])
      expect(session.identity.claim_type).to eq(:email)
      expect(session.identity.claim).to eq(email)
    end
  end

  context "with a phone claim provided" do
    it "created an identity and a session" do
      phone = generate(:phone)
      view = described_class.run(claim: phone, remote_addr: remote_addr, user_agent: user_agent).result.render(:json)
      session = PUNK::Session.find(slug: ActiveSupport::JSON.decode(view)["slug"])
      expect(session.identity.claim_type).to eq(:phone)
      expect(session.identity.claim).to eq(phone)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
punk-0.4.1 spec/actions/sessions/punk/create_session_action_spec.rb