|
| 1 | +# SPDX-License-Identifier: BSD-2-Clause |
| 2 | +# |
| 3 | +# git_hub_app_request_spec.rb |
| 4 | +# Part of NetDEF CI System |
| 5 | +# |
| 6 | +# Copyright (c) 2023 by |
| 7 | +# Network Device Education Foundation, Inc. ("NetDEF") |
| 8 | +# |
| 9 | +# frozen_string_literal: true |
| 10 | + |
| 11 | +describe GitHubApp::Request do |
| 12 | + let(:dummy_class) { Class.new { include GitHubApp::Request } } |
| 13 | + let(:instance) { dummy_class.new } |
| 14 | + |
| 15 | + describe '#get_request' do |
| 16 | + context 'when request json object' do |
| 17 | + it 'must return a hash' do |
| 18 | + allow(instance).to receive(:fetch_user_pass).and_return(%w[user passwd]) |
| 19 | + allow(instance).to receive(:create_http).and_return(double('http', |
| 20 | + request: double('response', |
| 21 | + body: '{"name": "NetDEF"}'))) |
| 22 | + |
| 23 | + result = instance.get_request(URI('http://localhost/test'), json: true) |
| 24 | + expect(result).to eq({ 'name' => 'NetDEF' }) |
| 25 | + end |
| 26 | + end |
| 27 | + |
| 28 | + context 'when request string object' do |
| 29 | + it 'must return a string' do |
| 30 | + allow(instance).to receive(:fetch_user_pass).and_return(%w[user passwd]) |
| 31 | + allow(instance).to receive(:create_http).and_return(double('http', |
| 32 | + request: double('response', |
| 33 | + body: '{"name": "NetDEF"}'))) |
| 34 | + |
| 35 | + result = instance.get_request(URI('http://localhost/test'), json: false) |
| 36 | + expect(result).not_to eq({ 'name' => 'NetDEF' }) |
| 37 | + end |
| 38 | + end |
| 39 | + end |
| 40 | +end |
0 commit comments