Skip to content

Commit 4824b60

Browse files
committed
Add test
1 parent f808ec4 commit 4824b60

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

spec/line/bot/client_channel_token_spec.rb

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,28 @@
1010
}
1111
EOS
1212

13+
ISSUE_CHANNEL_ACCESS_TOKEN_21_CONTENT = <<"EOS"
14+
{
15+
"access_token": "eyJhbGciOiJIUzxxxxxx",
16+
"token_type": "Bearer",
17+
"expires_in": 2592000,
18+
"key_id": "sDTOzw5wIfxxxxPEzcmeQA"
19+
}
20+
EOS
21+
22+
GET_CHANNEL_ACCESS_TOKEN_KEY_IDS_21_CONTENT = <<"EOS"
23+
{
24+
"key_ids": [
25+
"U_gdnFYKTWRxxxxDVZexGg",
26+
"sDTOzw5wIfWxxxxzcmeQA",
27+
"73hDyp3PxGfxxxxD6U5qYA",
28+
"FHGanaP79smDxxxxyPrVw",
29+
"CguB-0kxxxxdSM3A5Q_UtQ",
30+
"G82YP96jhHwyKSxxxx7IFA"
31+
]
32+
}
33+
EOS
34+
1335
WebMock.allow_net_connect!
1436

1537
describe Line::Bot::Client do
@@ -51,4 +73,41 @@ def generate_client
5173

5274
expect(response).to be_a(Net::HTTPOK)
5375
end
76+
77+
it 'issues an oauth access token v2.1' do
78+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/oauth2/v2.1/token'
79+
stub_request(:post, uri_template).to_return { |request| {body: ISSUE_CHANNEL_ACCESS_TOKEN_21_CONTENT, status: 200} }
80+
81+
client = generate_client
82+
response = client.issue_channel_access_token_21('jwt_string')
83+
84+
expect(response).to be_a(Net::HTTPOK)
85+
result = JSON.parse(response.body)
86+
expect(result['access_token']).to eq 'eyJhbGciOiJIUzxxxxxx'
87+
expect(result['expires_in']).to eq 2592000
88+
expect(result['token_type']).to eq 'Bearer'
89+
expect(result['key_id']).to eq 'sDTOzw5wIfxxxxPEzcmeQA'
90+
end
91+
92+
it 'revokes the oauth access token v2.1' do
93+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/oauth2/v2.1/revoke'
94+
stub_request(:post, uri_template).to_return { |request| {body: '', status: 200} }
95+
96+
client = generate_client
97+
98+
response = client.revoke_channel_access_token_21('sDTOzw5wIfxxxxPEzcmeQA'):
99+
100+
expect(response).to be_a(Net::HTTPOK)
101+
end
102+
103+
it 'get all valid channel access token key ids v2.1' do
104+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/oauth2/v2.1/tokens/kid'
105+
stub_request(:post, uri_template).to_return { |request| {body: GET_CHANNEL_ACCESS_TOKEN_KEY_IDS_21_CONTENT, status: 200} }
106+
107+
client = generate_client
108+
109+
response = client.get_channel_access_token_key_ids_21('jwt_string')
110+
111+
expect(response).to be_a(Net::HTTPOK)
112+
end
54113
end

0 commit comments

Comments
 (0)