|
| 1 | +# frozen_string_literal: true |
| 2 | +RSpec.describe MicrosoftKiotaFaraday::FaradayRequestAdapter do |
| 3 | + subject(:adapter) { described_class.new(authentication_provider) } |
| 4 | + |
| 5 | + let(:authentication_provider) { double("authentication_provider") } |
| 6 | + let(:headers) { { 'content-type' => 'application/json' } } |
| 7 | + let(:body) { { key: "value" }.to_json } |
| 8 | + |
| 9 | + describe "#get_root_parse_node" do |
| 10 | + context "when response is null" do |
| 11 | + it "raises an error" do |
| 12 | + expect { adapter.get_root_parse_node(nil) }.to raise_error(StandardError, 'response cannot be null') |
| 13 | + end |
| 14 | + end |
| 15 | + |
| 16 | + context "when response content type is not found" do |
| 17 | + let(:response) { instance_double(Faraday::Response, body:, headers: {}) } |
| 18 | + |
| 19 | + it "raises an error" do |
| 20 | + expect { adapter.get_root_parse_node(response) }.to raise_error(StandardError, 'no response content type found for deserialization') |
| 21 | + end |
| 22 | + end |
| 23 | + |
| 24 | + context "when response body is nil" do |
| 25 | + let(:response) { instance_double(Faraday::Response, body: nil, headers:) } |
| 26 | + |
| 27 | + it "returns nil" do |
| 28 | + expect(adapter.get_root_parse_node(response)).to be_nil |
| 29 | + end |
| 30 | + end |
| 31 | + |
| 32 | + context "when response body is empty" do |
| 33 | + let(:response) { instance_double(Faraday::Response, body: "", headers:) } |
| 34 | + |
| 35 | + it "returns nil" do |
| 36 | + expect(adapter.get_root_parse_node(response)).to be_nil |
| 37 | + end |
| 38 | + end |
| 39 | + |
| 40 | + context "when response body is not nil" do |
| 41 | + subject(:adapter) { described_class.new(authentication_provider, parse_node_factory) } |
| 42 | + |
| 43 | + let(:response) { instance_double(Faraday::Response, body:, headers:) } |
| 44 | + let(:parse_node_factory) { double("parse_node_factory") } |
| 45 | + let(:parse_node) { double("parse_node") } |
| 46 | + |
| 47 | + before do |
| 48 | + allow(parse_node_factory).to receive(:get_parse_node).with("application/json", body).and_return(parse_node) |
| 49 | + end |
| 50 | + |
| 51 | + it "returns the parse node" do |
| 52 | + expect(adapter.get_root_parse_node(response)).to eq(parse_node) |
| 53 | + end |
| 54 | + end |
| 55 | + end |
| 56 | +end |
0 commit comments