Sha256: ff1d918857ce2935e83da8da9ceb4acf54f37265e4a0ddc3eb4835d79d74f8c8

Contents?: true

Size: 1.54 KB

Versions: 11

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

RSpec.describe GraphqlDevise::MountMethod::OperationPreparers::CustomOperationPreparer do
  describe '#call' do
    subject(:prepared) { described_class.new(selected_keys: selected_keys, custom_operations: operations, mapping_name: mapping_name).call }

    let(:login_operation)  { double(:confirm_operation, graphql_name: nil) }
    let(:logout_operation) { double(:sign_up_operation, graphql_name: nil) }
    let(:mapping_name)     { :user }
    let(:operations)       { { login: login_operation, logout: logout_operation, invalid: double(:invalid) } }
    let(:selected_keys)    { [:login, :logout, :sign_up, :confirm] }

    it 'returns only those operations with no custom operation provided' do
      expect(prepared.keys).to contain_exactly(:user_login, :user_logout)
    end

    it 'prepares custom operations' do
      expect(login_operation).to receive(:graphql_name).with('UserLogin')
      expect(logout_operation).to receive(:graphql_name).with('UserLogout')

      prepared

      expect(login_operation.instance_variable_get(:@resource_name)).to eq(:user)
      expect(logout_operation.instance_variable_get(:@resource_name)).to eq(:user)
    end

    context 'when no selected keys are provided' do
      let(:selected_keys) { [] }

      it 'returns no operations' do
        expect(prepared).to eq({})
      end
    end

    context 'when no custom operations are provided' do
      let(:operations) { {} }

      it 'returns no operations' do
        expect(prepared).to eq({})
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
graphql_devise-0.14.3 spec/services/mount_method/operation_preparers/custom_operation_preparer_spec.rb
graphql_devise-0.14.2 spec/services/mount_method/operation_preparers/custom_operation_preparer_spec.rb
graphql_devise-0.14.1 spec/services/mount_method/operation_preparers/custom_operation_preparer_spec.rb
graphql_devise-0.14.0 spec/services/mount_method/operation_preparers/custom_operation_preparer_spec.rb
graphql_devise-0.13.6 spec/services/mount_method/operation_preparers/custom_operation_preparer_spec.rb
graphql_devise-0.13.5 spec/services/mount_method/operation_preparers/custom_operation_preparer_spec.rb
graphql_devise-0.13.4 spec/services/mount_method/operation_preparers/custom_operation_preparer_spec.rb
graphql_devise-0.13.3 spec/services/mount_method/operation_preparers/custom_operation_preparer_spec.rb
graphql_devise-0.13.2 spec/services/mount_method/operation_preparers/custom_operation_preparer_spec.rb
graphql_devise-0.13.1 spec/services/mount_method/operation_preparers/custom_operation_preparer_spec.rb
graphql_devise-0.13.0 spec/services/mount_method/operation_preparers/custom_operation_preparer_spec.rb