# frozen_string_literal: true require_relative '../../../spec_helper' require 'rexml/document' module Aws module Stubbing module Protocols describe Query do describe '#stub_data' do def normalize(xml) result = String.new # REXML only accepts mutable strings REXML::Document.new(xml).write(result, 2) result.strip end let(:api) { ApiHelper.sample_query::Client.api } let(:operation) { api.operation(:list_users) } it 'returns a stubbed http response' do resp = Query.new.stub_data(api, operation, {}) expect(resp).to be_kind_of(Seahorse::Client::Http::Response) expect(resp.status_code).to eq(200) end it 'populates the body with the stub data' do now = Time.now data = { is_truncated: false, users: [ { path: '/', arn: 'arn:aws:iam::123456789012:user/name', user_name: 'name', user_id: 'user-id', create_date: now, } ] } resp = Query.new.stub_data(api, operation, data) expect(normalize(resp.body.string)).to eq(normalize(<<-XML)) / name user-id arn:aws:iam::123456789012:user/name #{now.utc.iso8601} false stubbed-request-id XML end it 'can stub errors' do resp = Query.new.stub_error('error-code') expect(normalize(resp.body.string)).to eq(normalize(<<-XML)) error-code stubbed-response-error-message XML end end end end end end