Sha256: 15b096ce817ec4e3ac0b73829bec10aa93e22bacbea4a29645f901d5a415f337

Contents?: true

Size: 1.61 KB

Versions: 14

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

require "spec_helper"

RSpec.describe Blacklight::Solr::Response::Group, api: true do
  subject do
    group.groups.first
  end

  let(:response) do
    create_response(sample_response)
  end

  let(:group) do
    response.grouped.find { |x| x.key == "result_group_ssi" }
  end

  describe "#doclist" do
    it "is the raw list of documents from solr" do
      expect(subject.doclist).to be_a Hash
      expect(subject.doclist['docs'].first[:id]).to eq 1
    end
  end

  describe "#total" do
    it "is the number of results found in a group" do
      expect(subject.total).to eq 2
    end
  end

  describe "#start" do
    it "is the offset for the results in the group" do
      expect(subject.start).to eq 0
    end
  end

  describe "#docs" do
    it "is a list of SolrDocuments" do
      subject.docs.each do |doc|
        expect(doc).to be_a_kind_of SolrDocument
      end

      expect(subject.docs.first.id).to eq 1
    end
  end

  describe "#field" do
    it "is the field the group belongs to" do
      expect(subject.field).to eq "result_group_ssi"
    end
  end
end

def create_response(response, params = {})
  Blacklight::Solr::Response.new(response, params)
end

def sample_response
  { "responseHeader" => { "params" => { "rows" => 3, "group.limit" => 5 } },
    "grouped" =>
     { 'result_group_ssi' =>
       { 'groups' => [{ 'groupValue' => "Group 1", 'doclist' => { 'numFound' => 2, 'start' => 0, 'docs' => [{ id: 1 }, { id: 'x' }] } },
                      { 'groupValue' => "Group 2", 'doclist' => { 'numFound' => 3, 'docs' => [{ id: 2 }, id: 3] } }],
         'ngroups' => "3" } } }
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
blacklight-8.2.2 spec/models/blacklight/solr/response/group_spec.rb
blacklight-8.2.1 spec/models/blacklight/solr/response/group_spec.rb
blacklight-8.2.0 spec/models/blacklight/solr/response/group_spec.rb
blacklight-8.1.0 spec/models/blacklight/solr/response/group_spec.rb
blacklight-8.0.1 spec/models/blacklight/solr/response/group_spec.rb
blacklight-8.0.0 spec/models/blacklight/solr/response/group_spec.rb
blacklight-8.0.0.beta8 spec/models/blacklight/solr/response/group_spec.rb
blacklight-8.0.0.beta7 spec/models/blacklight/solr/response/group_spec.rb
blacklight-8.0.0.beta6 spec/models/blacklight/solr/response/group_spec.rb
blacklight-8.0.0.beta5 spec/models/blacklight/solr/response/group_spec.rb
blacklight-8.0.0.beta4 spec/models/blacklight/solr/response/group_spec.rb
blacklight-8.0.0.beta3 spec/models/blacklight/solr/response/group_spec.rb
blacklight-8.0.0.beta2 spec/models/blacklight/solr/response/group_spec.rb
blacklight-8.0.0.beta1 spec/models/blacklight/solr/response/group_spec.rb