File: account_activity_spec.rb

package info (click to toggle)
ruby-twitter 7.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,840 kB
  • sloc: ruby: 10,919; makefile: 6
file content (130 lines) | stat: -rw-r--r-- 5,025 bytes parent folder | download | duplicates (2)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
require 'helper'

describe Twitter::REST::AccountActivity do
  before do
    @client = Twitter::REST::Client.new(consumer_key: 'CK', consumer_secret: 'CS', access_token: 'AT', access_token_secret: 'AS')
  end

  describe '#create_webhook' do
    context 'with a webhook url passed' do
      before do
        stub_post('/1.1/account_activity/all/env_name/webhooks.json?url=url').with(query: {url: 'url'}).to_return(body: fixture('account_activity_create_webhook.json'), headers: {content_type: 'application/json; charset=utf-8'})
      end
      it 'request create webhook' do
        @client.create_webhook('env_name', 'url')
        expect(a_post('/1.1/account_activity/all/env_name/webhooks.json?url=url').with(body: {})).to have_been_made
      end

      it 'returns a webhook response' do
        response = @client.create_webhook('env_name', 'url')
        expect(response).to be_a Hash
        expect(response[:id]).to eq('1234567890')
      end
    end
  end

  describe '#list_webhooks' do
    context 'list webhooks' do
      before do
        stub_get('/1.1/account_activity/all/env_name/webhooks.json').to_return(body: fixture('account_activity_list_webhook.json'), headers: {content_type: 'application/json; charset=utf-8'})
      end
      it 'request list webhooks' do
        @client.list_webhooks('env_name')
        expect(a_get('/1.1/account_activity/all/env_name/webhooks.json').with(body: {})).to have_been_made
      end

      it 'returns a webhook response' do
        response = @client.list_webhooks('env_name')
        expect(response).to be_a Hash
        expect(response[:environments]).to be_a Array
        expect(response[:environments][0][:webhooks]).to be_a Array
        expect(response[:environments][0][:webhooks][0][:id]).to eq('1234567890')
      end
    end
  end

  describe '#trigger_crc_check' do
    context 'trigger crc check' do
      before do
        stub_put('/1.1/account_activity/all/env_name/webhooks/1234567890.json').to_return(status: 204, headers: {content_type: 'application/json; charset=utf-8'})
      end
      it 'request crc check' do
        @client.trigger_crc_check('env_name', '1234567890')
        expect(a_put('/1.1/account_activity/all/env_name/webhooks/1234567890.json').with(body: {})).to have_been_made
      end

      it 'returns a webhook response' do
        response = @client.trigger_crc_check('env_name', '1234567890')
        expect(response).to eq('')
      end
    end
  end

  describe '#create_subscription' do
    context 'create subscription' do
      before do
        stub_post('/1.1/account_activity/all/env_name/subscriptions.json').to_return(status: 204, headers: {content_type: 'application/json; charset=utf-8'})
      end
      it 'request create subscription' do
        @client.create_subscription('env_name')
        expect(a_post('/1.1/account_activity/all/env_name/subscriptions.json').with(body: {})).to have_been_made
      end

      it 'returns a webhook response' do
        response = @client.create_subscription('env_name')
        expect(response).to eq('')
      end
    end
  end

  describe '#check_subscription' do
    context 'check subscription' do
      before do
        stub_get('/1.1/account_activity/all/env_name/subscriptions.json').to_return(status: 204, headers: {content_type: 'application/json; charset=utf-8'})
      end
      it 'request check subscription' do
        @client.check_subscription('env_name')
        expect(a_get('/1.1/account_activity/all/env_name/subscriptions.json').with(body: {})).to have_been_made
      end

      it 'returns a webhook response' do
        response = @client.check_subscription('env_name')
        expect(response).to eq('')
      end
    end
  end

  describe '#delete_webhook' do
    context 'delete webhook' do
      before do
        stub_delete('/1.1/account_activity/all/env_name/webhooks/1234567890.json').to_return(status: 204, headers: {content_type: 'application/json; charset=utf-8'})
      end
      it 'request delete webhook' do
        @client.delete_webhook('env_name', '1234567890')
        expect(a_delete('/1.1/account_activity/all/env_name/webhooks/1234567890.json').with(body: {})).to have_been_made
      end

      it 'returns a webhook response' do
        response = @client.delete_webhook('env_name', '1234567890')
        expect(response).to eq('')
      end
    end
  end

  describe '#deactivate_subscription' do
    context 'deactivate subscription' do
      before do
        stub_delete('/1.1/account_activity/all/env_name/subscriptions.json').to_return(status: 204, headers: {content_type: 'application/json; charset=utf-8'})
      end
      it 'request deactivate subscription' do
        @client.deactivate_subscription('env_name')
        expect(a_delete('/1.1/account_activity/all/env_name/subscriptions.json').with(body: {})).to have_been_made
      end

      it 'returns a webhook response' do
        response = @client.deactivate_subscription('env_name')
        expect(response).to eq('')
      end
    end
  end
end