pokemon_trade_schema_spec.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe PokemonTradeSchema, type: :graphql do
  4. it 'has the base mutation' do
  5. expect(described_class.mutation).to eq ::Types::MutationType.to_graphql
  6. end
  7. it 'has the base query' do
  8. expect(described_class.query).to eq ::Types::QueryType.to_graphql
  9. end
  10. let(:object) { create(:pokemon) }
  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).to receive(:decode).and_return([object.class.to_s, object.id])
  22. expect(subject).to eq(object)
  23. end
  24. end
  25. describe '.resolve_type' do
  26. subject { described_class.resolve_type(nil, object, {}) }
  27. context 'resolves Pokemon' do
  28. # GraphQL::Schema wraps the overriden `.resolve_type`, so the return type
  29. # isn't actually `Types::PokemonType`
  30. specify { expect { subject }.not_to raise_error }
  31. end
  32. context 'errors on other types' do
  33. let(:object) { Object }
  34. specify { expect { subject }.to raise_error(APIError::BaseError) }
  35. end
  36. end
  37. end