| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- # frozen_string_literal: true
- require 'rails_helper'
- require './lib/pk_parse'
- RSpec.describe Mutations::UploadManyPokemon, type: :graphql do
- subject(:mutation) { described_class.new(object: nil, context: {}) }
- describe 'fields and arguments' do
- subject do
- described_class.fields[GraphQLHelpers.fieldnamerize(:upload_many_pokemon)]
- end
- let!(:described_class) { PokemonTradeSchema.types['Mutation'] }
- it { is_expected.to have_graphql_fields(:pokemon, :errors) }
- it { is_expected.to have_graphql_arguments(:base64_encoded_pokemon_files) }
- end
- describe '#resolve' do
- subject { mutation.resolve(base64_encoded_pokemon_files: [base64]) }
- let(:nickname) { Faker::Games::Pokemon.name }
- let(:pokedex_number) { rand(1..151) }
- let(:base64) { 'deadbeef' }
- context 'when pokemon is created' do
- before do
- parsed_pkmn = PKParse::Response.new(
- [
- {pokedex_number: pokedex_number, nickname: nickname},
- {pokedex_number: pokedex_number, nickname: nickname},
- ],
- )
- allow_any_instance_of(PKParse::Client)
- .to receive(:parse_base64).and_return(parsed_pkmn)
- end
- it 'returns pokemon' do
- expect(subject[:pokemon]).not_to be_nil
- expect(subject[:pokemon].length).to eq(2)
- end
- specify { expect { subject }.to change(Pokemon, :count).by(2) }
- end
- context 'when pokemon could not be created' do
- before do
- allow_any_instance_of(PKParse::Client).to(
- receive(:parse_base64).and_raise(PKParse::Error.new('foo')),
- )
- end
- it 'returns errors' do
- expect(subject[:errors].length).to eq(1)
- expect(subject[:errors].first).to respond_to(:message)
- end
- end
- end
- end
|