| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- # frozen_string_literal: true
- require 'rails_helper'
- RSpec.describe PokemonTradeSchema, type: :graphql do
- 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
- let(:object) { create(:pokemon) }
- 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 '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 'errors on other types' do
- let(:object) { Object }
- specify { expect { subject }.to raise_error(APIError::BaseError) }
- end
- end
- end
|