Sha256: 7d2a307a4427ae1b5ddb9b2648fc0d57505d481128b5eb596fee992352819e47

Contents?: true

Size: 1.9 KB

Versions: 32

Compression:

Stored size: 1.9 KB

Contents

require 'spec_helper'

describe 'tokens' do
  context "with a hmac client" do
    let!(:client) { create_client }

    context "with a user" do
      let!(:email)    { Faker::Internet.email }
      let!(:password) { SecureRandom.hex(5) }
      let!(:user)     { client.users.create!(name: Faker::Name.name, email: email, password: password) }

      it "retrieves a token by login information" do
        if Ey::Core::Client.mocking?
          token = SecureRandom.hex(10)
          client.data[:users][user.id]["token"] = token
        end

        expect(client.get_token_by_login(email: email, password: password).body["api_token"]).to be
      end

      it "does not retrieve a token with login information with an incorrect password" do
        if Ey::Core::Client.mocking?
          token = SecureRandom.hex(10)
          client.data[:users][user.id]["token"] = token
        end

        expect {
          client.get_token_by_login(email: email, password: "whoops")
        }.to raise_error(Ey::Core::Response::Unauthorized)
      end

      it "generates a token" do
        token = client.tokens.create!(on_behalf_of: user)
        expect(token.auth_id).not_to be_nil
      end

      it "lists tokens" do
        tokens = user.tokens.all
        expect(tokens).not_to be_empty
      end

      it "gets a token" do
        token = user.tokens.first
        expect(token.reload).to be
      end

      context "with multiple users" do
        let!(:other_user) { client.users.create(name: Faker::Name.name, email: Faker::Internet.email) }

        it "only shows the correct tokens" do
          expect(user.tokens.all.count).to eq(1)
          expect(other_user.tokens.all.count).to eq(1)
          expect(user.tokens.first.on_behalf_of).to eq(client.url_for("/users/#{user.identity}"))
          expect(other_user.tokens.first.on_behalf_of).to eq(client.url_for("/users/#{other_user.identity}"))
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
ey-core-3.1.11 spec/tokens_spec.rb
ey-core-3.1.10 spec/tokens_spec.rb
ey-core-3.1.9 spec/tokens_spec.rb
ey-core-3.1.8 spec/tokens_spec.rb
ey-core-3.1.7 spec/tokens_spec.rb
ey-core-3.1.6 spec/tokens_spec.rb
ey-core-3.1.5 spec/tokens_spec.rb
ey-core-3.1.4 spec/tokens_spec.rb
ey-core-3.1.3 spec/tokens_spec.rb
ey-core-3.1.2 spec/tokens_spec.rb
ey-core-3.1.1 spec/tokens_spec.rb
ey-core-3.1.0 spec/tokens_spec.rb