Sha256: 00929c72f6e0af4078e130e5627dd179831b7395f4aed9c66c09c7e4425c6785

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

require "micropub/server/rails/middleware"
require "rack/test"

Micropub.configure do |c|
  c.token_endpoint = "https://tokens.indieauth.com/token"
  c.me             = "http://bookisworthy.com"
  c.allowed_scopes = [:post]
end

describe Micropub::Server::Rails::Middleware do
  include Rack::Test::Methods
  let(:rails) { double("rails") }
  def app
    Micropub::Server::Rails::Middleware.new(rails)
  end

  describe "invalid route" do
    it "calls `call` on parent app" do
      expect(rails).to receive(:call).and_return [200, {}, [""]]
      get "/"
    end
  end

  describe "POST /micropub" do
    before do
      expect(Micropub::Token).to receive(:new).with("1234").and_return(token)
    end
    context "when given a valid token" do
      let(:token) { double("Token", valid?: true) }

      it "returns a 201" do
        post "/micropub", {}, "HTTP_AUTHORIZATION" => "Bearer 1234"
        expect(last_response.status).to eq 201
      end

      it "returns a Location header" do
        post "/micropub", {}, "HTTP_AUTHORIZATION" => "Bearer 1234"
        expect(last_response.header["Location"]).to eq "http://bookisworthy.com/posts/1"
      end

      it "with params access_token returns a 201" do
        post "/micropub", {access_token: 1234}
        expect(last_response.status).to eq 201
      end

    end

    context "when given an invalid token" do
      let(:token) { double("Token", valid?: false) }

      it "returns a 401" do
        post "/micropub", {}, "HTTP_AUTHORIZATION" => "Bearer 1234"
        expect(last_response.status).to eq 401
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
micropub-server-rails-0.1.5 spec/lib/micropub/server/rails/middleware_spec.rb