Sha256: 54ac3b1dc54799c5a4784b066a1bbf78bf849cea1545ce8862bb63b4b6d1c3fa

Contents?: true

Size: 1.89 KB

Versions: 62

Compression:

Stored size: 1.89 KB

Contents

require 'test_helper'

module Workarea
  class AdminQueryOperationTest < Workarea::TestCase
    include TestCase::SearchIndexing

    def test_use_query
      op = AdminQueryOperation.new
      assert(op.use_query?)

      op = AdminQueryOperation.new(ids: %w(1 2 3))
      refute(op.use_query?)
    end

    def test_count
      products = Array.new(3) { |i| create_product(name: "Foo#{i}") }
      products.each { |p| Search::Admin.for(p).save }

      query = Search::AdminProducts.new
      op = AdminQueryOperation.new(query_id: query.to_global_id)
      assert_equal(3, op.count)

      query = Search::AdminProducts.new(q: 'foo1 foo2')
      op = AdminQueryOperation.new(query_id: query.to_global_id)
      assert_equal(2, op.count)

      query = Search::AdminProducts.new(q: 'foo1 foo2')
      op = AdminQueryOperation.new(
        query_id: query.to_global_id,
        exclude_ids: products.last.to_global_id
      )
      assert_equal(1, op.count)

      op = AdminQueryOperation.new(ids: products.map(&:to_global_id))
      assert_equal(3, op.count)

      op = AdminQueryOperation.new(
        ids: products.map(&:to_global_id),
        exclude_ids: products.first.to_global_id
      )
      assert_equal(2, op.count)

      op = AdminQueryOperation.new(ids: products.first.to_global_id)
      assert_equal(1, op.count)

      op = AdminQueryOperation.new(
        ids: products.first.to_global_id,
        exclude_ids: products.last.to_global_id
      )
      assert_equal(1, op.count)
    end

    def test_query_delegations
      services = Array.new(3) { create_shipping_service }

      query = AdminSearchQueryWrapper.new
      op = AdminQueryOperation.new(
        query_id: query.to_gid_param,
        model_type: 'Workarea::Shipping::Service'
      )

      assert_equal(3, op.count)
      assert_equal(3, op.results.count)
      assert_equal('Workarea::Shipping::Service', op.params[:model_type])
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.5.26 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.4.45 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.5.25 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.5.23 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.4.44 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.5.22 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.4.43 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.5.21 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.4.42 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.5.20 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.4.41 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.5.19 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.4.40 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.5.18 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.4.39 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.5.17 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.4.38 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.5.16 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.4.37 test/queries/workarea/admin_query_operation_test.rb