Sha256: 3f7e609f2b883246b5783749a856dab6aba4720f7c171837cc307e28f560f0b8

Contents?: true

Size: 820 Bytes

Versions: 4

Compression:

Stored size: 820 Bytes

Contents

require 'rails_helper'

module PandaPal
  RSpec.describe ApiCall, type: :model do
    let!(:subject) { ApiCall.create!(logic: '"#{p[:foo]}_bar"') }
    let!(:jwt) { subject.jwt_token }

    describe ".from_jwt" do
      it "finds an ApiCall from a JWT" do
        expect(ApiCall.from_jwt(jwt)).to eq subject
      end

      it "fails if the JWT is invalid" do
        expect{ ApiCall.from_jwt("really.bad.jwt") }.to raise_error(JWT::DecodeError)
      end
    end

    describe "#call" do
      it "calls the function with parameters" do
        expect(subject.call({ foo: 'FOO' })).to eq 'FOO_bar'
      end
    end

    describe "#call_url" do
      it "generates a URL with the expected placholders" do
        expect(subject.call_url).to eq "/panda_pal/call_logic?foo=TODO&token=#{jwt}"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
panda_pal-5.12.3 spec/models/panda_pal/api_call_spec.rb
panda_pal-5.12.2 spec/models/panda_pal/api_call_spec.rb
panda_pal-5.12.1 spec/models/panda_pal/api_call_spec.rb
panda_pal-5.12.0 spec/models/panda_pal/api_call_spec.rb