Sha256: 4c4a0ad3ca5fff35e969e04e0e6382bb9b66fa127b7c233e102497ac83cb3ed7

Contents?: true

Size: 1.82 KB

Versions: 76

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe LHS::Record do
  context 'creation failed' do
    let(:datastore) { 'http://local.ch/v2' }

    before do
      LHC.config.placeholder(:datastore, datastore)
      class Record < LHS::Record
        endpoint '{+datastore}/{campaign_id}/feedbacks'
        endpoint '{+datastore}/feedbacks'
      end
    end

    let(:error_message) { "ratings must be set when review or name or review_title is set | The property value is required; it cannot be null, empty, or blank." }

    let(:creation_error) do
      {
        "status" => 400,
        "message" => error_message,
        "fields" => [
          {
            "name" => "ratings",
            "details" => [{ "code" => "REQUIRED_PROPERTY_VALUE" }]
          }, {
            "name" => "recommended",
            "details" => [{ "code" => "REQUIRED_PROPERTY_VALUE" }]
          }
        ]
      }
    end

    it 'provides errors when creation failed' do
      stub_request(:post, "#{datastore}/feedbacks")
        .to_return(status: 400, body: creation_error.to_json)
      record = Record.create(name: 'Steve')
      expect(record).to be_kind_of Record
      expect(record.errors).to be_present
      expect(record.name).to eq 'Steve'
      expect(record.errors.include?(:ratings)).to eq true
      expect(record.errors.include?(:recommended)).to eq true
      expect(record.errors[:ratings]).to eq ['REQUIRED_PROPERTY_VALUE']
      expect(record.errors.messages).to eq('ratings' => ["REQUIRED_PROPERTY_VALUE"], 'recommended' => ["REQUIRED_PROPERTY_VALUE"])
      expect(record.errors.message).to eq error_message
    end

    it 'doesnt fail when no fields are provided by the backend' do
      stub_request(:post, "#{datastore}/feedbacks")
        .to_return(status: 400, body: {}.to_json)
      Record.create(name: 'Steve')
    end
  end
end

Version data entries

76 entries across 76 versions & 1 rubygems

Version Path
lhs-26.2.0 spec/record/creation_failed_spec.rb
lhs-26.1.0 spec/record/creation_failed_spec.rb
lhs-26.0.1 spec/record/creation_failed_spec.rb
lhs-26.0.0 spec/record/creation_failed_spec.rb
lhs-25.2.0 spec/record/creation_failed_spec.rb
lhs-25.1.0 spec/record/creation_failed_spec.rb
lhs-25.0.4 spec/record/creation_failed_spec.rb
lhs-25.0.3 spec/record/creation_failed_spec.rb
lhs-25.0.2 spec/record/creation_failed_spec.rb
lhs-25.0.1 spec/record/creation_failed_spec.rb
lhs-25.0.0 spec/record/creation_failed_spec.rb
lhs-24.1.2 spec/record/creation_failed_spec.rb
lhs-24.1.1 spec/record/creation_failed_spec.rb
lhs-24.1.0 spec/record/creation_failed_spec.rb
lhs-24.1.0.pre.2 spec/record/creation_failed_spec.rb
lhs-24.1.0.pre.1 spec/record/creation_failed_spec.rb
lhs-24.0.0 spec/record/creation_failed_spec.rb
lhs-23.0.2 spec/record/creation_failed_spec.rb
lhs-23.0.1 spec/record/creation_failed_spec.rb
lhs-23.0.0 spec/record/creation_failed_spec.rb