grape-slack-bot 1.6.12 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,141 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SlackBot::Callback do
4
- subject(:callback) {
5
- described_class.new(
6
- class_name: "Test",
7
- user: user,
8
- channel_id: "test_channel_id",
9
- payload: { test: "test" },
10
- config: config
11
- )
12
- }
13
-
14
- let(:config) {
15
- instance_double(
16
- SlackBot::Config,
17
- callback_storage_instance: callback_storage_instance,
18
- callback_user_finder_method: callback_user_finder_method
19
- )
20
- }
21
- let(:callback_storage_instance) { instance_double(SlackBot::CallbackStorage) }
22
- let(:callback_user_finder_method) { ->(user_id) { user } }
23
-
24
- let(:user) { double(:user, id: 1) }
25
-
26
- let(:callback_id) { "test_callback_id" }
27
-
28
- describe ".find" do
29
- subject(:find) { described_class.find(callback_id, user: user, config: config) }
30
-
31
- let(:cached_data) {
32
- {
33
- class_name: "Test",
34
- user_id: user.id,
35
- channel_id: "test_channel_id",
36
- payload: { test: "test" },
37
- args: "test"
38
- }
39
- }
40
-
41
- before do
42
- allow(callback_storage_instance).to receive(:read).with("#{SlackBot::Callback::CALLBACK_KEY_PREFIX}:u#{user.id}:#{callback_id}").and_return(cached_data)
43
- end
44
-
45
- it "returns callback" do
46
- expect(find).to be_a(described_class)
47
- expect(find.id).to eq(callback_id)
48
- expect(find.class_name).to eq("Test")
49
- expect(find.user).to eq(user)
50
- expect(find.channel_id).to eq("test_channel_id")
51
- expect(find.payload).to eq({ test: "test" })
52
- expect(find.args).to be_a(SlackBot::Args)
53
- end
54
-
55
- context "when callback is not found" do
56
- let(:cached_data) { nil }
57
-
58
- it "returns nil" do
59
- expect(find).to be_nil
60
- end
61
- end
62
- end
63
-
64
- describe ".create" do
65
- subject(:create) {
66
- described_class.create(
67
- class_name: "Test",
68
- user: user,
69
- channel_id: "test_channel_id",
70
- payload: { test: "test" },
71
- config: config
72
- )
73
- }
74
-
75
- let(:cached_data) {
76
- {
77
- class_name: "Test",
78
- user_id: user.id,
79
- channel_id: "test_channel_id",
80
- payload: { test: "test" },
81
- args: "",
82
- view_id: nil
83
- }
84
- }
85
-
86
- before do
87
- allow_any_instance_of(described_class).to receive(:generate_id).and_return(callback_id)
88
- allow(callback_storage_instance).to receive(:write).with("#{SlackBot::Callback::CALLBACK_KEY_PREFIX}:u#{user.id}:#{callback_id}", cached_data, expires_in: SlackBot::Callback::CALLBACK_RECORD_EXPIRES_IN).and_return(cached_data)
89
- allow(callback_storage_instance).to receive(:read).with("#{SlackBot::Callback::CALLBACK_KEY_PREFIX}:u#{user.id}:#{callback_id}").and_return(cached_data)
90
- end
91
-
92
- it "creates callback" do
93
- expect(create).to be_a(described_class)
94
- expect(create.id).to be_present
95
- expect(create.class_name).to eq("Test")
96
- expect(create.user).to eq(user)
97
- expect(create.channel_id).to eq("test_channel_id")
98
- expect(create.payload).to eq({ test: "test" })
99
- expect(create.args).to be_a(SlackBot::Args)
100
- end
101
- end
102
-
103
- describe ".find_or_create" do
104
- subject(:find_or_create) {
105
- described_class.find_or_create(
106
- id: callback_id,
107
- class_name: "Test",
108
- user: user,
109
- channel_id: "test_channel_id",
110
- payload: { test: "test" },
111
- config: config
112
- )
113
- }
114
-
115
- let(:cached_data) {
116
- {
117
- class_name: "Test",
118
- user_id: user.id,
119
- channel_id: "test_channel_id",
120
- payload: { test: "test" },
121
- args: ""
122
- }
123
- }
124
-
125
- before do
126
- allow_any_instance_of(described_class).to receive(:generate_id).and_return(callback_id)
127
- allow(callback_storage_instance).to receive(:write).with("#{SlackBot::Callback::CALLBACK_KEY_PREFIX}:u#{user.id}:#{callback_id}", cached_data, expires_in: SlackBot::Callback::CALLBACK_RECORD_EXPIRES_IN).and_return(cached_data)
128
- allow(callback_storage_instance).to receive(:read).with("#{SlackBot::Callback::CALLBACK_KEY_PREFIX}:u#{user.id}:#{callback_id}").and_return(cached_data)
129
- end
130
-
131
- it "finds or creates callback" do
132
- expect(find_or_create).to be_a(described_class)
133
- expect(find_or_create.id).to eq(callback_id)
134
- expect(find_or_create.class_name).to eq("Test")
135
- expect(find_or_create.user).to eq(user)
136
- expect(find_or_create.channel_id).to eq("test_channel_id")
137
- expect(find_or_create.payload).to eq({ test: "test" })
138
- expect(find_or_create.args).to be_a(SlackBot::Args)
139
- end
140
- end
141
- end
@@ -1,5 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SlackBot::Command do
4
-
5
- end
@@ -1,57 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SlackBot::Config do
4
- subject(:config) { described_class.new }
5
-
6
- describe ".configure" do
7
-
8
- end
9
-
10
- describe ".current_instance" do
11
-
12
- end
13
-
14
- describe "#callback_storage" do
15
-
16
- end
17
-
18
- describe "#callback_user_finder" do
19
-
20
- end
21
-
22
- describe "#event" do
23
-
24
- end
25
-
26
- describe "#slash_command_endpoint" do
27
-
28
- end
29
-
30
- describe "#menu_options" do
31
-
32
- end
33
-
34
- describe "#handler_class" do
35
-
36
- end
37
-
38
- describe "#find_event_handler" do
39
-
40
- end
41
-
42
- describe "#find_slash_command_config" do
43
-
44
- end
45
-
46
- describe "#find_menu_options" do
47
-
48
- end
49
-
50
- describe "#find_handler_class" do
51
-
52
- end
53
-
54
- describe "#find_command_config" do
55
-
56
- end
57
- end
@@ -1,95 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SlackBot::DevConsole do
4
- let(:logger) { instance_double(SlackBot::Logger) }
5
- before do
6
- described_class.enabled = true
7
- described_class.logger = logger
8
- end
9
-
10
- describe '.enabled=' do
11
- it 'sets the enabled value' do
12
- expect { described_class.enabled = false }.to change(described_class, :enabled?).from(true).to(false)
13
- end
14
- end
15
-
16
- describe '.logger=' do
17
- let(:new_logger) { instance_double(SlackBot::Logger) }
18
- after { described_class.logger = logger }
19
- it 'sets the logger' do
20
- expect { described_class.logger = new_logger }.to change(described_class, :logger).from(logger).to(new_logger)
21
- end
22
- end
23
-
24
- describe '.log' do
25
- context 'when enabled' do
26
- before { described_class.enabled = true }
27
- it 'logs the message' do
28
- expect(described_class.logger).to receive(:info).with('test')
29
- described_class.log('test')
30
- end
31
- end
32
-
33
- context 'when disabled' do
34
- before { described_class.enabled = false }
35
- it 'does not log the message' do
36
- expect(described_class.logger).not_to receive(:info)
37
- described_class.log('test')
38
- end
39
- end
40
- end
41
-
42
- describe '.log_input' do
43
- context 'when enabled' do
44
- before { described_class.enabled = true }
45
- it 'logs the message' do
46
- expect(described_class.logger).to receive(:info).with('>>> test')
47
- described_class.log_input('test')
48
- end
49
- end
50
-
51
- context 'when disabled' do
52
- before { described_class.enabled = false }
53
- it 'does not log the message' do
54
- expect(described_class.logger).not_to receive(:info)
55
- described_class.log_input('test')
56
- end
57
- end
58
- end
59
-
60
- describe '.log_output' do
61
- context 'when enabled' do
62
- before { described_class.enabled = true }
63
- it 'logs the message' do
64
- expect(described_class.logger).to receive(:info).with('<<< test')
65
- described_class.log_output('test')
66
- end
67
- end
68
-
69
- context 'when disabled' do
70
- before { described_class.enabled = false }
71
- it 'does not log the message' do
72
- expect(described_class.logger).not_to receive(:info)
73
- described_class.log_output('test')
74
- end
75
- end
76
- end
77
-
78
- describe '.log_check' do
79
- context 'when enabled' do
80
- before { described_class.enabled = true }
81
- it 'logs the message' do
82
- expect(described_class.logger).to receive(:info).with('!!! test')
83
- described_class.log_check('test')
84
- end
85
- end
86
-
87
- context 'when disabled' do
88
- before { described_class.enabled = false }
89
- it 'does not log the message' do
90
- expect(described_class.logger).not_to receive(:info)
91
- described_class.log_check('test')
92
- end
93
- end
94
- end
95
- end
@@ -1,74 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SlackBot::Event do
4
- let(:current_user) { double(:current_user) }
5
- let(:params) { double(:params) }
6
- let(:callback) { instance_double(SlackBot::Callback) }
7
- let(:config) { instance_double(SlackBot::Config) }
8
-
9
- subject do
10
- described_class.new(
11
- current_user: current_user,
12
- params: params,
13
- callback: callback,
14
- config: config
15
- )
16
- end
17
-
18
- describe '.view_klass' do
19
- it 'raises exception' do
20
- expect { subject.class.view_klass }.to raise_error(SlackBot::Errors::ViewClassNotImplemented)
21
- end
22
-
23
- context "when view is called" do
24
- before do
25
- subject.class.view :view_name
26
- end
27
- it 'returns view_name' do
28
- expect(subject.class.view_klass).to eq(:view_name)
29
- end
30
- end
31
- end
32
-
33
- describe '.interaction_klass' do
34
- it 'raises exception' do
35
- expect { subject.class.interaction_klass }.to raise_error(SlackBot::Errors::InteractionClassNotImplemented)
36
- end
37
- context "when interaction is called" do
38
- before do
39
- subject.class.interaction :interaction_name
40
- end
41
- it 'returns interaction_name' do
42
- expect(subject.class.interaction_klass).to eq(:interaction_name)
43
- end
44
- end
45
- end
46
-
47
- describe '#initialize' do
48
- it 'sets current_user' do
49
- expect(subject.current_user).to eq(current_user)
50
- end
51
-
52
- it 'sets params' do
53
- expect(subject.params).to eq(params)
54
- end
55
-
56
- it 'sets callback' do
57
- expect(subject.callback).to eq(callback)
58
- end
59
-
60
- it 'sets config' do
61
- expect(subject.config).to eq(config)
62
- end
63
- end
64
-
65
- describe '#call' do
66
- it 'returns nil' do
67
- expect(subject.call).to eq(nil)
68
- end
69
- end
70
-
71
- describe '#publish_view' do
72
-
73
- end
74
- end
@@ -1,5 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SlackBot::GrapeExtension do
4
-
5
- end
@@ -1,95 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SlackBot::Interaction do
4
- subject { described_class.new(current_user: current_user, params: params, callback: callback, config: config) }
5
-
6
- let(:current_user) { double("current_user") }
7
- let(:params) { {} }
8
- let(:callback) { instance_double(SlackBot::Callback, id: "test-callback-id") }
9
- let(:config) { instance_double(SlackBot::Config) }
10
-
11
- before do
12
- allow(callback).to receive(:view_id=).and_return(nil)
13
- allow(callback).to receive(:save).and_return(nil)
14
- end
15
-
16
- it "initializes" do
17
- expect(subject.current_user).to eq(current_user)
18
- expect(subject.params).to eq(params)
19
- expect(subject.callback).to eq(callback)
20
- expect(subject.config).to eq(config)
21
- end
22
-
23
- describe ".open_modal" do
24
- subject(:open_modal) { described_class.open_modal(callback: callback, trigger_id: trigger_id, view: view) }
25
-
26
- let(:trigger_id) { "trigger_id" }
27
- let(:view) { {} }
28
- let(:response) { instance_double(SlackBot::ApiResponse, ok?: true, data: { "view" => { "id" => "view_id" } }) }
29
-
30
- before do
31
- allow(SlackBot::ApiClient).to receive(:new).and_return(instance_double(SlackBot::ApiClient, views_open: response))
32
- end
33
-
34
- it "opens modal" do
35
- expect(open_modal).to eq(SlackBot::Interaction::SlackViewsReply.new(callback&.id, "view_id"))
36
- end
37
-
38
- context "when response is not ok" do
39
- let(:response) { instance_double(SlackBot::ApiResponse, ok?: false, error: "error", data: { "view" => { "id" => "view_id" } }) }
40
-
41
- it "raises error" do
42
- expect { open_modal }.to raise_error(SlackBot::Errors::OpenModalError)
43
- end
44
- end
45
- end
46
-
47
- describe ".update_modal" do
48
- subject(:update_modal) { described_class.update_modal(callback: callback, view_id: view_id, view: view) }
49
-
50
- let(:view_id) { "view_id" }
51
- let(:view) { {} }
52
- let(:response) { instance_double(SlackBot::ApiResponse, ok?: true, data: { "view" => { "id" => "view_id" } }) }
53
-
54
- before do
55
- allow(SlackBot::ApiClient).to receive(:new).and_return(instance_double(SlackBot::ApiClient, views_update: response))
56
- end
57
-
58
- it "updates modal" do
59
- expect(update_modal).to eq(SlackBot::Interaction::SlackViewsReply.new(callback&.id, "view_id"))
60
- end
61
-
62
- context "when response is not ok" do
63
- let(:response) { instance_double(SlackBot::ApiResponse, ok?: false, error: "error", data: { "view" => { "id" => "view_id" } }) }
64
-
65
- it "raises error" do
66
- expect { update_modal }.to raise_error(SlackBot::Errors::UpdateModalError)
67
- end
68
- end
69
- end
70
-
71
- describe ".publish_view" do
72
- subject(:publish_view) { described_class.publish_view(callback: callback, metadata: metadata, user_id: user_id, view: view) }
73
-
74
- let(:user_id) { "user_id" }
75
- let(:metadata) { "metadata" }
76
- let(:view) { {} }
77
- let(:response) { instance_double(SlackBot::ApiResponse, ok?: true, data: { "view" => { "id" => "view_id" } }) }
78
-
79
- before do
80
- allow(SlackBot::ApiClient).to receive(:new).and_return(instance_double(SlackBot::ApiClient, views_publish: response))
81
- end
82
-
83
- it "publishes view" do
84
- expect(publish_view).to eq(SlackBot::Interaction::SlackViewsReply.new(callback&.id, "view_id"))
85
- end
86
-
87
- context "when response is not ok" do
88
- let(:response) { instance_double(SlackBot::ApiResponse, ok?: false, error: "error", data: { "view" => { "id" => "view_id" } }) }
89
-
90
- it "raises error" do
91
- expect { publish_view }.to raise_error(SlackBot::Errors::PublishViewError)
92
- end
93
- end
94
- end
95
- end
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SlackBot::Logger do
4
- describe '#info' do
5
- it 'prints the args' do
6
- expect { subject.info('test') }.to output(%(["test"]\n)).to_stdout
7
- end
8
-
9
- it 'prints the kwargs' do
10
- expect { subject.info(test: 'test') }.to output(%({:test=>"test"}\n)).to_stdout
11
- end
12
- end
13
- end
@@ -1,5 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SlackBot::MenuOptions do
4
-
5
- end
@@ -1,51 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SlackBot::Pager do
4
- let(:args) do
5
- instance_double(SlackBot::Args)
6
- end
7
- before do
8
- allow(args).to receive(:[]).with(:page).and_return(1)
9
- allow(args).to receive(:[]).with(:per_page).and_return(10)
10
- end
11
-
12
- describe '#total_count' do
13
- it 'returns the count of the source cursor' do
14
- source_cursor = double(count: 10)
15
- pager = described_class.new(source_cursor, args: args)
16
- expect(pager.total_count).to eq(10)
17
- end
18
- end
19
-
20
- describe '#pages_count' do
21
- it 'returns the count of the source cursor divided by the limit' do
22
- source_cursor = double(count: 10)
23
- pager = described_class.new(source_cursor, args: args, limit: 5)
24
- expect(pager.pages_count).to eq(2)
25
- end
26
-
27
- it 'returns the count of the source cursor divided by the limit' do
28
- source_cursor = double(count: 11)
29
- pager = described_class.new(source_cursor, args: args, limit: 5)
30
- expect(pager.pages_count).to eq(3)
31
- end
32
- end
33
-
34
- describe '#offset' do
35
- it 'returns the offset based on the page and limit' do
36
- source_cursor = double(count: 10)
37
- pager = described_class.new(source_cursor, args: args, limit: 5, page: 2)
38
- expect(pager.offset).to eq(5)
39
- end
40
- end
41
-
42
- describe '#cursor' do
43
- it 'returns the cursor with the limit and offset' do
44
- source_cursor = double(count: 10)
45
- expect(source_cursor).to receive(:limit).with(5).and_return(source_cursor)
46
- expect(source_cursor).to receive(:offset).with(5).and_return(source_cursor)
47
- pager = described_class.new(source_cursor, args: args, limit: 5, page: 2)
48
- expect(pager.cursor).to eq(source_cursor)
49
- end
50
- end
51
- end
@@ -1,5 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SlackBot::View do
4
-
5
- end
@@ -1,7 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SlackBot do
4
- it 'has a version number' do
5
- expect(described_class::VERSION).not_to be nil
6
- end
7
- end