# frozen_string_literal: true require 'rails_helper' RSpec.describe PokemonTradeSchema, type: :graphql do let(:object) { create(:pokemon) } it 'has the base mutation' do expect(described_class.mutation).to eq ::Types::MutationType.to_graphql end it 'has the base query' do expect(described_class.query).to eq ::Types::QueryType.to_graphql end describe '.id_from_object' do subject { described_class.id_from_object(object, Types::PokemonType, {}) } it 'encodes the id' do expect(GraphQL::Schema::UniqueWithinType).to receive(:encode) subject end end describe '.object_from_id' do subject { described_class.object_from_id('', {}) } it 'decodes the id' do expect(GraphQL::Schema::UniqueWithinType) .to receive(:decode).and_return([object.class.to_s, object.id]) expect(subject).to eq(object) end end describe '.resolve_type' do subject { described_class.resolve_type(nil, object, {}) } context 'when resolves Pokemon' do # GraphQL::Schema wraps the overriden `.resolve_type`, so the return type # isn't actually `Types::PokemonType` specify { expect { subject }.not_to raise_error } end context 'when errors on other types' do let(:object) { Object } specify { expect { subject }.to raise_error(APIError::BaseError) } end end end