-
Notifications
You must be signed in to change notification settings - Fork 92
/
interaction_spec.rb
112 lines (100 loc) · 3.16 KB
/
interaction_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# frozen_string_literal: true
require 'securerandom'
require 'discordrb'
describe Discordrb::API::Interaction do
let(:interaction_token) { SecureRandom.base64(200) }
let(:interaction_id) { SecureRandom.random_number(1000) }
let(:application_id) { SecureRandom.random_number(1000) }
let(:content) { 'hello world' }
let(:callback_type) { Discordrb::Interaction::CALLBACK_TYPES[:channel_message] }
let(:file) { double(File) }
describe '#create_interaction_response' do
it 'sends a JSON payload with headers when file is not specified' do
expect(Discordrb::API).to receive(:request).with(
:interactions_iid_token_callback,
interaction_id,
:post,
"#{Discordrb::API.api_base}/interactions/#{interaction_id}/#{interaction_token}/callback",
{ type: callback_type, data: { content: content } }.to_json,
{ content_type: :json }
)
Discordrb::API::Interaction.create_interaction_response(
interaction_token,
interaction_id,
callback_type,
content
)
end
it 'sends a multipart payload when a file is specified' do
expect(Discordrb::API).to receive(:request).with(
:interactions_iid_token_callback,
interaction_id,
:post,
"#{Discordrb::API.api_base}/interactions/#{interaction_id}/#{interaction_token}/callback",
{ file: file, payload_json: { type: callback_type, data: { content: content } }.to_json },
nil
)
Discordrb::API::Interaction.create_interaction_response(
interaction_token,
interaction_id,
callback_type,
content,
nil, # tts
nil, # embeds
nil, # allowed_mentions
nil, # flags
nil, # components
file
)
end
end
describe '#get_original_interaction_response' do
it 'calls webhook api with correct parameters' do
expect(Discordrb::API::Webhook).to receive(:token_get_message).with(
interaction_id,
application_id,
'@original'
)
Discordrb::API::Interaction.get_original_interaction_response(
interaction_id,
application_id
)
end
end
describe '#edit_original_interaction_response' do
it 'calls webhook api with correct parameters' do
expect(Discordrb::API::Webhook).to receive(:token_edit_message).with(
interaction_id,
application_id,
'@original',
content,
nil, # embeds
nil, # allowed_mentions
nil, # components
file
)
Discordrb::API::Interaction.edit_original_interaction_response(
interaction_id,
application_id,
content,
nil, # embeds
nil, # allowed_mentions
nil, # components
file
)
end
end
describe '#delete_original_interaction_response' do
it 'calls webhook api with correct parameters' do
expect(Discordrb::API::Webhook).to receive(:token_delete_message).with(
interaction_token,
application_id,
'@original'
)
Discordrb::API::Interaction.delete_original_interaction_response(
interaction_token,
application_id
)
end
end
end