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.15 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.4.36 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.5.14 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.4.35 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.5.13 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.4.34 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.5.12 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.4.33 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.5.11 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.5.10 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.4.32 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.5.9 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.4.31 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.5.8 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.4.30 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.5.7 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.4.29 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.5.6 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.4.28 test/queries/workarea/admin_query_operation_test.rb
workarea-core-3.5.5 test/queries/workarea/admin_query_operation_test.rb