pokemon_trade_schema_spec.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe PokemonTradeSchema, type: :graphql do
  4. let(:object) { create(:pokemon) }
  5. it 'has the base mutation' do
  6. expect(described_class.mutation).to eq ::Types::MutationType.to_graphql
  7. end
  8. it 'has the base query' do
  9. expect(described_class.query).to eq ::Types::QueryType.to_graphql
  10. end
  11. describe '.id_from_object' do
  12. subject { described_class.id_from_object(object, Types::PokemonType, {}) }
  13. it 'encodes the id' do
  14. expect(GraphQL::Schema::UniqueWithinType).to receive(:encode)
  15. subject
  16. end
  17. end
  18. describe '.object_from_id' do
  19. subject { described_class.object_from_id('', {}) }
  20. it 'decodes the id' do
  21. expect(GraphQL::Schema::UniqueWithinType)
  22. .to receive(:decode).and_return([object.class.to_s, object.id])
  23. expect(subject).to eq(object)
  24. end
  25. end
  26. describe '.resolve_type' do
  27. subject { described_class.resolve_type(nil, object, {}) }
  28. context 'when resolves Pokemon' do
  29. # GraphQL::Schema wraps the overriden `.resolve_type`, so the return type
  30. # isn't actually `Types::PokemonType`
  31. specify { expect { subject }.not_to raise_error }
  32. end
  33. context 'when errors on other types' do
  34. let(:object) { Object }
  35. specify { expect { subject }.to raise_error(APIError::BaseError) }
  36. end
  37. end
  38. end