Sha256: 66ee7ab8a5afedafc0fabe6161263f7c5c63fe88ce085f2bfcbee522715de76a

Contents?: true

Size: 914 Bytes

Versions: 4

Compression:

Stored size: 914 Bytes

Contents

# frozen_string_literal: true

require 'active_support/core_ext/module/attribute_accessors'

module Artemis
  module Adapters
    class TestAdapter
      cattr_accessor :requests
      self.requests = []

      cattr_accessor :responses
      self.responses = []

      Request = Struct.new(:document, :operation_name, :variables, :context)

      private_constant :Request

      def initialize(*)
      end

      def execute(**arguments)
        self.requests << Request.new(*arguments.values_at(:document, :operation_name, :variables, :context))

        response = responses.detect do |mock|
          arguments[:operation_name] == mock.operation_name && mock.arguments == :__unspecified__ || arguments[:variables] == mock.arguments
        end

        response&.data || {
          'data' => { 'test' => 'data' },
          'errors' => [],
          'extensions' => {}
        }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
artemis-0.5.2 lib/artemis/adapters/test_adapter.rb
artemis-0.5.1 lib/artemis/adapters/test_adapter.rb
artemis-0.5.0 lib/artemis/adapters/test_adapter.rb
artemis-0.4.0 lib/artemis/adapters/test_adapter.rb