|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe 'ChannelAccessToken::ApiClient query parameter names' do |
| 4 | + let(:client) { Line::Bot::V2::ChannelAccessToken::ApiClient.new } |
| 5 | + |
| 6 | + describe 'GET /oauth2/v2.1/verify (verify_channel_token_by_jwt)' do |
| 7 | + let(:access_token) { 'test_access_token_value' } |
| 8 | + let(:response_body) do |
| 9 | + { "clientId" => "1234567890", "expiresIn" => 12345 }.to_json |
| 10 | + end |
| 11 | + |
| 12 | + it 'sends access_token as snake_case query key, not accessToken' do |
| 13 | + # Exact query match: passes only when the key is "access_token" (snake_case). |
| 14 | + # If camelCase "accessToken" were used instead, the stub would not match and |
| 15 | + # WebMock would raise an error, failing the test. |
| 16 | + stub_request(:get, "https://api.line.me/oauth2/v2.1/verify") |
| 17 | + .with(query: { "access_token" => access_token }) |
| 18 | + .to_return(status: 200, body: response_body, headers: { 'Content-Type' => 'application/json' }) |
| 19 | + |
| 20 | + body, status_code, _headers = client.verify_channel_token_by_jwt_with_http_info( |
| 21 | + access_token: access_token |
| 22 | + ) |
| 23 | + |
| 24 | + expect(status_code).to eq(200) |
| 25 | + expect(body.client_id).to eq("1234567890") |
| 26 | + expect(body.expires_in).to eq(12345) |
| 27 | + end |
| 28 | + end |
| 29 | + |
| 30 | + describe 'GET /oauth2/v2.1/tokens/kid (gets_all_valid_channel_access_token_key_ids)' do |
| 31 | + let(:client_assertion_type) { 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer' } |
| 32 | + let(:client_assertion) { 'test_jwt_assertion' } |
| 33 | + let(:response_body) do |
| 34 | + { "kids" => ["kid1", "kid2"] }.to_json |
| 35 | + end |
| 36 | + |
| 37 | + it 'sends client_assertion_type and client_assertion as snake_case query keys, not camelCase' do |
| 38 | + # Exact query match: passes only when the keys are "client_assertion_type" and |
| 39 | + # "client_assertion" (snake_case). If camelCase were used, the stub would not match. |
| 40 | + expected_query = { |
| 41 | + "client_assertion_type" => client_assertion_type, |
| 42 | + "client_assertion" => client_assertion |
| 43 | + } |
| 44 | + stub_request(:get, "https://api.line.me/oauth2/v2.1/tokens/kid") |
| 45 | + .with(query: expected_query) |
| 46 | + .to_return(status: 200, body: response_body, headers: { 'Content-Type' => 'application/json' }) |
| 47 | + |
| 48 | + body, status_code, _headers = client.gets_all_valid_channel_access_token_key_ids_with_http_info( |
| 49 | + client_assertion_type: client_assertion_type, |
| 50 | + client_assertion: client_assertion |
| 51 | + ) |
| 52 | + |
| 53 | + expect(status_code).to eq(200) |
| 54 | + expect(body.kids).to eq(["kid1", "kid2"]) |
| 55 | + end |
| 56 | + end |
| 57 | +end |
0 commit comments