=begin
Trulioo Ruby SDK

Gem version: 1.0.0
Trulioo OpenAPI version: v1
Generated by OpenAPI Generator version: 5.0.1
=end

require "spec_helper"
require "webmock/rspec"

describe Trulioo::ConnectionApi do
  let(:api) {
    configuration = Trulioo::Configuration.new
    configuration.api_key["ApiKeyAuth"] = "test-api-key"
    configuration.debugging = true
    api_client = Trulioo::ApiClient.new(configuration)
    Trulioo::ConnectionApi.new(api_client)
  }

  describe "#connection_async_callback_url" do
    context "when receiving 200 success" do
      before(:each) do
        stub_request(:any, /.*/).to_return(status: 200, body: "{}")
      end
      let!(:result) {
        api.connection_async_callback_url("trial", Trulioo::TransactionStatus.new)
      }

      it "should correctly call the API" do
        expect(
          a_request(:post, "https://gateway.trulioo.com/trial/connection/v1/async-callback")
        ).to have_been_made
      end

      it "should correctly deserialize the response" do
        expect(result).to eql({})
      end
    end

    context "when receiving 401 unauthorized" do
      before(:each) do
        stub_request(:any, /.*/).to_return(status: 401)
      end

      it "should throw an ApiError" do
        expect {
          api.connection_async_callback_url("trial", Trulioo::TransactionStatus.new)
        }.to raise_error(Trulioo::ApiError, /HTTP status code: 401/)
      end
    end

    context "with parameter 'mode' as nil" do
      it "should throw an ArgumentError" do
        expect { api.connection_async_callback_url(nil, Trulioo::TransactionStatus.new) }.to raise_error(
          ArgumentError,
          "Missing the required parameter 'mode' when calling ConnectionApi.connection_async_callback_url"
        )
      end
    end

    context "with parameter 'transaction_status' as nil" do
      it "should throw an ArgumentError" do
        expect { api.connection_async_callback_url("trial", nil) }.to raise_error(
          ArgumentError,
          "Missing the required parameter 'transaction_status' when calling ConnectionApi.connection_async_callback_url"
        )
      end
    end
  end

  describe "#say_hello" do
    context "when receiving 200 success" do
      before(:each) do
        stub_request(:any, /.*/).to_return(status: 200, body: "Hello Trulioo User")
      end
      let!(:result) {
        api.say_hello("trial", "Trulioo User")
      }

      it "should correctly call the API" do
        expect(
          a_request(:get, "https://gateway.trulioo.com/trial/connection/v1/sayhello/Trulioo%20User")
        ).to have_been_made
      end

      it "should correctly deserialize the response" do
        expect(result).to eql("Hello Trulioo User")
      end
    end

    context "when receiving 401 unauthorized" do
      before(:each) do
        stub_request(:any, /.*/).to_return(status: 401)
      end

      it "should throw an ApiError" do
        expect {
          api.say_hello("trial", "Trulioo User")
        }.to raise_error(Trulioo::ApiError, /HTTP status code: 401/)
      end
    end

    context "with parameter 'mode' as nil" do
      it "should throw an ArgumentError" do
        expect { api.say_hello(nil, "Trulioo User") }.to raise_error(
          ArgumentError,
          "Missing the required parameter 'mode' when calling ConnectionApi.say_hello"
        )
      end
    end

    context "with parameter 'name' as nil" do
      it "should throw an ArgumentError" do
        expect { api.say_hello("trial", nil) }.to raise_error(
          ArgumentError,
          "Missing the required parameter 'name' when calling ConnectionApi.say_hello"
        )
      end
    end
  end

  describe "#test_authentication" do
    context "when receiving 200 success" do
      before(:each) do
        stub_request(:any, /.*/).to_return(status: 200, body: "Hello Trulioo User")
      end
      let!(:result) {
        api.test_authentication("trial")
      }

      it "should correctly call the API" do
        expect(
          a_request(:get, "https://gateway.trulioo.com/trial/connection/v1/testauthentication")
            .with(headers: { "x-trulioo-api-key": "test-api-key" })
        ).to have_been_made
      end

      it "should correctly deserialize the response" do
        expect(result).to eql("Hello Trulioo User")
      end
    end

    context "when receiving 401 unauthorized" do
      before(:each) do
        stub_request(:any, /.*/).to_return(status: 401)
      end

      it "should throw an ApiError" do
        expect {
          api.test_authentication("trial")
        }.to raise_error(Trulioo::ApiError, /HTTP status code: 401/)
      end
    end

    context "with parameter 'mode' as nil" do
      it "should throw an ArgumentError" do
        expect { api.test_authentication(nil) }.to raise_error(
          ArgumentError,
          "Missing the required parameter 'mode' when calling ConnectionApi.test_authentication"
        )
      end
    end
  end
end
