Sha256: 5281e6875fb86126cbd28fd6b05cc59b8b97274c3540a22a4719060937a17c87

Contents?: true

Size: 2 KB

Versions: 1

Compression:

Stored size: 2 KB

Contents

require 'helper'

module Heft
  class Users
    require File.join '.', 'adapters', 'internet'
    
    class << self 
      def add(opts={})
        headers = {'Authorization' => "HOIST #{ENV['APIKEY']}"}

        reply = Adapters::Internet.new.execute T::Request.new(
          :headers  => headers,
          :uri      => 'https://auth.hoi.io/user',
          :body     => opts,
          :verb     => :post
        ) 

        fail "Failed => #{reply.body}" if reply.code > 299
      end

      def contain?(email)
        headers = {'Authorization' => "HOIST #{ENV['APIKEY']}"}

        reply = Adapters::Internet.new.execute T::Request.new(
          :headers  => headers,
          :uri      => 'https://auth.hoi.io/user',
          :body     => {:email => email, :password => "******"},
          :verb     => :post
        ) 

        json = JSON.parse reply.body

        error_message = json['message']

        reply.code === 400 and error_message.match /already a user with that email address/
      end

      private

      def all
        headers = {'Authorization' => "HOIST #{ENV['APIKEY']}", 'Accept' => 'application/json'}

        reply = Adapters::Internet.new.execute T::Request.new(
          :headers  => headers,
          :uri      => 'https://auth.hoi.io/users',
        ) 

        fail "Failed => #{reply.body}" if reply.code > 299

        puts reply.body
      end
    end
  end
end

class UniqueEmail
  class << self
    def next
      require 'securerandom'
      "#{SecureRandom.uuid.to_s}@example.test.com"
    end
  end
end

describe "Hoistapps and users" do
  it "can be asked to add a new one" do # see: http://docs.hoi.io/authentication/overview/api/authentication-api
    email = UniqueEmail.next

    Heft::Users.add :email => email, :password => "xxx_not_a_password_xxx"

    expect(Heft::Users.contain? email).to be_true, "User was not found"
  end

  it "fails when user exists already with the same email"
  it "can be asked to delete a user"
  it "fails unless password is <= 6 characters long"
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
heft-0.0.1 spec/acceptance.tests/users/the_basics_spec.rb