create_pokemon_spec.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Mutations::CreatePokemon, type: :graphql do
  4. subject(:mutation) { described_class.new(object: nil, context: {}) }
  5. describe 'fields and arguments' do
  6. subject do
  7. described_class.fields[GraphQLHelpers.fieldnamerize(:create_pokemon)]
  8. end
  9. let!(:described_class) { PokemonTradeSchema.types['Mutation'] }
  10. it { is_expected.to have_graphql_fields(:pokemon, :errors) }
  11. it { is_expected.to have_graphql_arguments(:pokedex_number, :nickname) }
  12. end
  13. describe '#resolve' do
  14. subject do
  15. mutation.resolve(nickname: nickname, pokedex_number: pokedex_number)
  16. end
  17. let(:nickname) { Faker::Games::Pokemon.name }
  18. let(:pokedex_number) { rand(1..151) }
  19. it 'returns pokemon' do
  20. expect(subject[:pokemon]).not_to be_nil
  21. expect(subject[:pokemon]).to be_a Pokemon
  22. end
  23. specify { expect { subject }.to change(Pokemon, :count).by(1) }
  24. context 'when pokemon could not be created' do
  25. let(:pokedex_number) { nil }
  26. it 'returns errors' do
  27. expect(subject[:errors].length).to eq(1)
  28. end
  29. end
  30. end
  31. end