| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- # frozen_string_literal: true
- require 'rails_helper'
- require './lib/pkparse'
- RSpec.describe Mutations::UploadManyPokemon, type: :graphql do
- subject(:mutation) { described_class.new(object: nil, context: {}) }
- describe 'fields and arguments' do
- let!(:described_class) { PokemonTradeSchema.types['Mutation'] }
- subject { described_class.fields[GraphQLHelpers.fieldnamerize(:upload_many_pokemon)] }
- it { is_expected.to have_graphql_fields(:pokemon, :errors) }
- it { is_expected.to have_graphql_arguments(:base64_encoded_pokemon_files) }
- end
- describe '#resolve' do
- let(:nickname) { Faker::Games::Pokemon.name }
- let(:pokedex_number) { rand(1..151) }
- let(:base64) { 'deadbeef' }
- subject { mutation.resolve(base64_encoded_pokemon_files: [base64]) }
- context 'pokemon is created' do
- before do
- allow_any_instance_of(PKParse::Client).to(
- receive(:parse_base64).and_return(
- PKParse::Response.new(
- [
- {pokedex_number: pokedex_number, nickname: nickname},
- {pokedex_number: pokedex_number, nickname: nickname},
- ],
- ),
- ),
- )
- 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 '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
|