Sha256: 6339f13c4ef5ecd6e358c97ffbf8b1d4a1017f4b9a3330c079be1c35ca2536b6

Contents?: true

Size: 1.42 KB

Versions: 4

Compression:

Stored size: 1.42 KB

Contents

require 'spec_helper'

describe UpdateDossier do
  let(:session) { Fabricate :roqua_core_api_token_session }
  let(:dossier) { Fabricate :roqua_core_api_dossier }
  let(:response) { double }

  before do
    allow(response).to receive(:code) { 200 }
    expect(session).to receive(:patch).with("/dossiers/#{dossier.id}",
                                            dossier: dossier.serializable_hash)
                       .and_return(response)
  end

  describe 'performs a patch on the /dossiers api path' do
    before do
      @result = UpdateDossier.run!(session: session,
                                   dossier: dossier)
    end

    it 'returns true when the call was correct' do
      expect(@result).to be_truthy
    end

    it 'should not have any errors' do
      expect(dossier.errors).to be_empty
    end
  end

  describe 'returns false when the call was incorrect' do
    let(:error) { {'dossier' => { 'id' => ['empty']}} }
    before do
      allow(response).to receive(:[]).with('errors').and_return(error)

      expect(response).to receive(:code).and_return(422)
      @result = UpdateDossier.run!(session: session,
                                   dossier: dossier)
    end

    it 'should return false' do
      expect(@result).to be_falsey
    end

    it 'should add the errors to the dossier' do
      expect(dossier.errors).to_not be_empty
      expect(dossier.errors[:id][0]).to eq 'moet opgegeven zijn'
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
roqua-core-api-0.7.0 spec/lib/roqua/core_api/update_dossier_spec.rb
roqua-core-api-0.6.0 spec/lib/roqua/core_api/update_dossier_spec.rb
roqua-core-api-0.5.0 spec/lib/roqua/core_api/update_dossier_spec.rb
roqua-core-api-0.4.0 spec/lib/roqua/core_api/update_dossier_spec.rb