|
3 | 3 | RSpec.describe UrnLists::ApiClient do |
4 | 4 | describe '#fetch_rows' do |
5 | 5 | before do |
6 | | - stub_request(:post, "https://example.com/oauth/token") |
| 6 | + stub_request(:post, 'https://example.com/oauth/token') |
7 | 7 | .with( |
8 | | - body: {"client_id" => "test_client_id", "client_secret" => "test_client_secret", "grant_type" => "client_credentials", "scope" => "test_scope"}, |
9 | | - headers: { |
10 | | - 'Accept'=>'*/*', |
11 | | - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', |
12 | | - 'Content-Type'=>'application/x-www-form-urlencoded', |
13 | | - 'Host'=>'example.com', |
14 | | - 'User-Agent'=>'Ruby' |
15 | | - }) |
| 8 | + body: { 'client_id' => 'test_client_id', 'client_secret' => 'test_client_secret', |
| 9 | +'grant_type' => 'client_credentials', 'scope' => 'test_scope' }, |
| 10 | + headers: { |
| 11 | + 'Accept' => '*/*', |
| 12 | + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', |
| 13 | + 'Content-Type' => 'application/x-www-form-urlencoded', |
| 14 | + 'Host' => 'example.com', |
| 15 | + 'User-Agent' => 'Ruby' |
| 16 | + } |
| 17 | + ) |
16 | 18 | .to_return( |
17 | | - status: 200, |
| 19 | + status: 200, |
18 | 20 | body: { access_token: 'abc123' }.to_json, |
19 | 21 | headers: { 'Content-Type' => 'application/json' } |
20 | 22 | ) |
21 | 23 |
|
22 | 24 | stub_request(:get, "https://apim.crowncommercial.gov.uk/website-data/manual/paths/invoke/%5Batt%5D.%5Bvw_RMIActiveURNList%5D/?api-version=2016-10-01&filter=Published%20eq%20'True'&sp=/triggers/manual/run&sv=1.0") |
23 | 25 | .with( |
24 | 26 | headers: { |
25 | | - 'Accept' => 'application/json', |
| 27 | + 'Accept' => 'application/json', |
26 | 28 | 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', |
27 | 29 | 'Authorization' => 'Bearer abc123', |
28 | 30 | 'User-Agent' => 'Ruby' |
|
42 | 44 | headers: { 'Content-Type' => 'application/json' } |
43 | 45 | ) |
44 | 46 |
|
45 | | - allow(ENV).to receive(:fetch).and_call_original |
46 | | - allow(ENV).to receive(:fetch).with('MDM_API_TOKEN_URL').and_return('https://example.com/oauth/token') |
47 | | - allow(ENV).to receive(:fetch).with('MDM_API_CLIENT_ID').and_return('test_client_id') |
48 | | - allow(ENV).to receive(:fetch).with('MDM_API_CLIENT_SECRET').and_return('test_client_secret') |
49 | | - allow(ENV).to receive(:fetch).with('MDM_API_SCOPE').and_return('test_scope') |
| 47 | + allow(ENV).to receive(:fetch).and_call_original |
| 48 | + allow(ENV).to receive(:fetch).with('MDM_API_TOKEN_URL').and_return('https://example.com/oauth/token') |
| 49 | + allow(ENV).to receive(:fetch).with('MDM_API_CLIENT_ID').and_return('test_client_id') |
| 50 | + allow(ENV).to receive(:fetch).with('MDM_API_CLIENT_SECRET').and_return('test_client_secret') |
| 51 | + allow(ENV).to receive(:fetch).with('MDM_API_SCOPE').and_return('test_scope') |
50 | 52 | end |
51 | 53 |
|
52 | 54 | it 'fetches and returns customer data' do |
|
0 commit comments