seven_api 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +7 -6
- data/.idea/inspectionProfiles/Project_Default.xml +5 -5
- data/.idea/ruby-client.iml +48 -13
- data/Gemfile +2 -2
- data/LICENSE +21 -21
- data/README.md +1 -1
- data/Rakefile +5 -5
- data/doc/SevenApi/Client.html +8 -8
- data/doc/SevenApi/Contacts/Action.html +0 -0
- data/doc/SevenApi/Contacts.html +0 -0
- data/doc/SevenApi/Endpoint.html +0 -0
- data/doc/SevenApi/Hooks/Action.html +0 -0
- data/doc/SevenApi/Hooks/EventType.html +0 -0
- data/doc/SevenApi/Hooks/RequestMethod.html +0 -0
- data/doc/SevenApi/Hooks/Validator.html +26 -26
- data/doc/SevenApi/Hooks.html +0 -0
- data/doc/SevenApi/Journal/Type.html +0 -0
- data/doc/SevenApi/Journal/Validator.html +18 -18
- data/doc/SevenApi/Journal.html +0 -0
- data/doc/SevenApi/Lookup/Type.html +0 -0
- data/doc/SevenApi/Lookup.html +0 -0
- data/doc/SevenApi/Resource.html +13 -13
- data/doc/SevenApi/Resources/Analytics.html +2 -2
- data/doc/SevenApi/Resources/Balance.html +2 -2
- data/doc/SevenApi/Resources/Contacts.html +6 -6
- data/doc/SevenApi/Resources/Hooks.html +10 -10
- data/doc/SevenApi/Resources/Journal.html +2 -2
- data/doc/SevenApi/Resources/Lookup.html +8 -8
- data/doc/SevenApi/Resources/Pricing.html +2 -2
- data/doc/SevenApi/Resources/Sms.html +2 -2
- data/doc/SevenApi/Resources/Status.html +2 -2
- data/doc/SevenApi/Resources/Subaccounts.html +18 -18
- data/doc/SevenApi/Resources/ValidateForVoice.html +2 -2
- data/doc/SevenApi/Resources/Voice.html +2 -2
- data/doc/SevenApi/Resources.html +0 -0
- data/doc/SevenApi/Sms/Type.html +0 -0
- data/doc/SevenApi/Sms.html +0 -0
- data/doc/SevenApi/Subaccounts/Action.html +0 -0
- data/doc/SevenApi/Subaccounts/Validator.html +29 -29
- data/doc/SevenApi/Subaccounts.html +0 -0
- data/doc/SevenApi/Util.html +39 -39
- data/doc/SevenApi.html +0 -0
- data/document.sh +3 -0
- data/lib/seven_api/client.rb +32 -32
- data/lib/seven_api/contacts.rb +5 -5
- data/lib/seven_api/endpoint.rb +0 -0
- data/lib/seven_api/hooks.rb +69 -68
- data/lib/seven_api/journal.rb +39 -39
- data/lib/seven_api/lookup.rb +12 -12
- data/lib/seven_api/numbers.rb +9 -9
- data/lib/seven_api/paginated.rb +10 -10
- data/lib/seven_api/rcs.rb +0 -0
- data/lib/seven_api/resource.rb +1 -2
- data/lib/seven_api/resources/analytics.rb +54 -54
- data/lib/seven_api/resources/balance.rb +19 -19
- data/lib/seven_api/resources/contacts.rb +56 -56
- data/lib/seven_api/resources/groups.rb +56 -56
- data/lib/seven_api/resources/hooks.rb +40 -40
- data/lib/seven_api/resources/journal.rb +20 -20
- data/lib/seven_api/resources/lookup.rb +63 -63
- data/lib/seven_api/resources/numbers.rb +70 -69
- data/lib/seven_api/resources/pricing.rb +20 -20
- data/lib/seven_api/resources/rcs.rb +3 -3
- data/lib/seven_api/resources/sms.rb +29 -20
- data/lib/seven_api/resources/status.rb +20 -20
- data/lib/seven_api/resources/subaccounts.rb +65 -65
- data/lib/seven_api/resources/validate_for_voice.rb +20 -20
- data/lib/seven_api/resources/voice.rb +29 -20
- data/lib/seven_api/sms.rb +9 -9
- data/lib/seven_api/subaccounts.rb +55 -55
- data/lib/seven_api/util.rb +68 -68
- data/lib/seven_api/version.rb +5 -5
- data/lib/seven_api.rb +6 -6
- data/release.sh +4 -4
- data/seven_api.gemspec +0 -0
- data/spec/EnvKeyStore.rb +14 -14
- data/spec/matchers.rb +22 -22
- data/spec/seven_api/analytics_spec.rb +49 -49
- data/spec/seven_api/balance_spec.rb +18 -18
- data/spec/seven_api/client_spec.rb +15 -15
- data/spec/seven_api/contacts_spec.rb +100 -100
- data/spec/seven_api/groups_spec.rb +74 -74
- data/spec/seven_api/hooks_spec.rb +108 -108
- data/spec/seven_api/instance_spec.rb +22 -22
- data/spec/seven_api/journal_spec.rb +86 -86
- data/spec/seven_api/lookup_spec.rb +197 -197
- data/spec/seven_api/numbers_spec.rb +135 -135
- data/spec/seven_api/pricing_spec.rb +76 -76
- data/spec/seven_api/rcs_spec.rb +0 -0
- data/spec/seven_api/sms_spec.rb +103 -103
- data/spec/seven_api/subaccounts_spec.rb +121 -121
- data/spec/seven_api/validate_for_voice_spec.rb +19 -19
- data/spec/seven_api/voice_spec.rb +51 -51
- data/spec/seven_api_spec.rb +9 -9
- metadata +4 -6
@@ -1,49 +1,49 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'seven_api/resources/analytics'
|
5
|
-
|
6
|
-
RSpec.describe SevenApi, 'analytics' do
|
7
|
-
base_stub = {
|
8
|
-
hlr: 0,
|
9
|
-
inbound: 72,
|
10
|
-
mnp: 0,
|
11
|
-
rcs: 1,
|
12
|
-
sms: 145,
|
13
|
-
usage_eur: 0.208,
|
14
|
-
voice: 0
|
15
|
-
}
|
16
|
-
helper = Helper.new(SevenApi::Resources::Analytics)
|
17
|
-
|
18
|
-
it 'returns an array with analytics grouped by country' do
|
19
|
-
stub = [base_stub.merge({ country: "DE" })]
|
20
|
-
params = { country: "DE" }
|
21
|
-
fn = helper.resource.method(:by_country)
|
22
|
-
path = SevenApi::Resources::Analytics.const_get('PATHS')[:by_country]
|
23
|
-
entries = helper.request(fn, stub, params, path)
|
24
|
-
expect(entries).to be_a(Array)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'returns an array with analytics grouped by date' do
|
28
|
-
stub = [base_stub.merge({ date: "2020-05-13" })]
|
29
|
-
fn = helper.resource.method(:by_date)
|
30
|
-
path = SevenApi::Resources::Analytics.const_get('PATHS')[:by_date]
|
31
|
-
entries = helper.request(fn, stub, nil, path)
|
32
|
-
expect(entries).to be_a(Array)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'returns an array with analytics grouped by label' do
|
36
|
-
stub = [base_stub.merge({ label: "Label" })]
|
37
|
-
fn = helper.resource.method(:by_label)
|
38
|
-
path = SevenApi::Resources::Analytics.const_get('PATHS')[:by_label]
|
39
|
-
entries = helper.request(fn, stub, nil, path)
|
40
|
-
expect(entries).to be_a(Array)
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'returns an array with analytics grouped by subaccount' do
|
44
|
-
stub = [base_stub.merge({ account: "Subaccount" })]
|
45
|
-
path = SevenApi::Resources::Analytics.const_get('PATHS')[:by_subaccount]
|
46
|
-
entries = helper.request(helper.resource.method(:by_subaccount), stub, nil, path)
|
47
|
-
expect(entries).to be_a(Array)
|
48
|
-
end
|
49
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'seven_api/resources/analytics'
|
5
|
+
|
6
|
+
RSpec.describe SevenApi, 'analytics' do
|
7
|
+
base_stub = {
|
8
|
+
hlr: 0,
|
9
|
+
inbound: 72,
|
10
|
+
mnp: 0,
|
11
|
+
rcs: 1,
|
12
|
+
sms: 145,
|
13
|
+
usage_eur: 0.208,
|
14
|
+
voice: 0
|
15
|
+
}
|
16
|
+
helper = Helper.new(SevenApi::Resources::Analytics)
|
17
|
+
|
18
|
+
it 'returns an array with analytics grouped by country' do
|
19
|
+
stub = [base_stub.merge({ country: "DE" })]
|
20
|
+
params = { country: "DE" }
|
21
|
+
fn = helper.resource.method(:by_country)
|
22
|
+
path = SevenApi::Resources::Analytics.const_get('PATHS')[:by_country]
|
23
|
+
entries = helper.request(fn, stub, params, path)
|
24
|
+
expect(entries).to be_a(Array)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'returns an array with analytics grouped by date' do
|
28
|
+
stub = [base_stub.merge({ date: "2020-05-13" })]
|
29
|
+
fn = helper.resource.method(:by_date)
|
30
|
+
path = SevenApi::Resources::Analytics.const_get('PATHS')[:by_date]
|
31
|
+
entries = helper.request(fn, stub, nil, path)
|
32
|
+
expect(entries).to be_a(Array)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns an array with analytics grouped by label' do
|
36
|
+
stub = [base_stub.merge({ label: "Label" })]
|
37
|
+
fn = helper.resource.method(:by_label)
|
38
|
+
path = SevenApi::Resources::Analytics.const_get('PATHS')[:by_label]
|
39
|
+
entries = helper.request(fn, stub, nil, path)
|
40
|
+
expect(entries).to be_a(Array)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'returns an array with analytics grouped by subaccount' do
|
44
|
+
stub = [base_stub.merge({ account: "Subaccount" })]
|
45
|
+
path = SevenApi::Resources::Analytics.const_get('PATHS')[:by_subaccount]
|
46
|
+
entries = helper.request(helper.resource.method(:by_subaccount), stub, nil, path)
|
47
|
+
expect(entries).to be_a(Array)
|
48
|
+
end
|
49
|
+
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'seven_api/resources/balance'
|
5
|
-
|
6
|
-
RSpec.describe SevenApi, 'balance' do
|
7
|
-
it 'returns the account balance' do
|
8
|
-
helper = Helper.new(SevenApi::Resources::Balance)
|
9
|
-
stub = {
|
10
|
-
amount: 44.631,
|
11
|
-
currency: "EUR"
|
12
|
-
}
|
13
|
-
balance = helper.request(helper.resource.method(:retrieve), stub)
|
14
|
-
expect(balance).to be_a(Hash)
|
15
|
-
expect(balance[:amount]).to be_a(Float)
|
16
|
-
expect(balance[:currency]).to be_a(String)
|
17
|
-
end
|
18
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'seven_api/resources/balance'
|
5
|
+
|
6
|
+
RSpec.describe SevenApi, 'balance' do
|
7
|
+
it 'returns the account balance' do
|
8
|
+
helper = Helper.new(SevenApi::Resources::Balance)
|
9
|
+
stub = {
|
10
|
+
amount: 44.631,
|
11
|
+
currency: "EUR"
|
12
|
+
}
|
13
|
+
balance = helper.request(helper.resource.method(:retrieve), stub)
|
14
|
+
expect(balance).to be_a(Hash)
|
15
|
+
expect(balance[:amount]).to be_a(Float)
|
16
|
+
expect(balance[:currency]).to be_a(String)
|
17
|
+
end
|
18
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'seven_api/client'
|
5
|
-
require 'seven_api/resource'
|
6
|
-
|
7
|
-
RSpec.describe SevenApi, 'client' do
|
8
|
-
it 'should contain all resource modules' do
|
9
|
-
client = SevenApi::Client.new(SevenApi::Resource.new('x'))
|
10
|
-
|
11
|
-
client.instance_variables.each do |var|
|
12
|
-
expect(SevenApi::Resources.const_get(client.instance_variable_get(var).class.name)).to be_truthy
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'seven_api/client'
|
5
|
+
require 'seven_api/resource'
|
6
|
+
|
7
|
+
RSpec.describe SevenApi, 'client' do
|
8
|
+
it 'should contain all resource modules' do
|
9
|
+
client = SevenApi::Client.new(SevenApi::Resource.new('x'))
|
10
|
+
|
11
|
+
client.instance_variables.each do |var|
|
12
|
+
expect(SevenApi::Resources.const_get(client.instance_variable_get(var).class.name)).to be_truthy
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,100 +1,100 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'seven_api/contacts'
|
5
|
-
require 'seven_api/resources/contacts'
|
6
|
-
|
7
|
-
dummy_contact = {
|
8
|
-
"id": 12876882,
|
9
|
-
"avatar": "https://static.seven.io/uploads/contact_images/4A000c0d4e9431F483090dE8D13F3806.jpg",
|
10
|
-
"validation": {
|
11
|
-
"state": nil,
|
12
|
-
"timestamp": nil
|
13
|
-
},
|
14
|
-
"initials": {
|
15
|
-
"initials": "",
|
16
|
-
"color": "EEE0C9"
|
17
|
-
},
|
18
|
-
"properties": {
|
19
|
-
"address": nil,
|
20
|
-
"birthday": nil,
|
21
|
-
"city": nil,
|
22
|
-
"email": nil,
|
23
|
-
"firstname": nil,
|
24
|
-
"home_number": nil,
|
25
|
-
"lastname": nil,
|
26
|
-
"mobile_number": nil,
|
27
|
-
"notes": nil,
|
28
|
-
"postal_code": nil,
|
29
|
-
},
|
30
|
-
"groups": [
|
31
|
-
],
|
32
|
-
"created": "2024-01-09 13:12:48"
|
33
|
-
}
|
34
|
-
|
35
|
-
RSpec.describe SevenApi, 'contacts' do
|
36
|
-
$new_number_id = nil
|
37
|
-
|
38
|
-
def assert_new(response_body)
|
39
|
-
if response_body.is_a?(String)
|
40
|
-
code, $new_number_id = response_body.split("\n")
|
41
|
-
$new_number_id = $new_number_id.to_i
|
42
|
-
else
|
43
|
-
code = response_body[:return]
|
44
|
-
$new_number_id = response_body[:id]
|
45
|
-
end
|
46
|
-
|
47
|
-
expect(code).to be_numeric
|
48
|
-
expect($new_number_id).to be_an_instance_of(Integer)
|
49
|
-
end
|
50
|
-
|
51
|
-
def assert_contact(contact)
|
52
|
-
expect(contact[:id]).to be_numeric
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'returns all contacts' do
|
56
|
-
stub = {
|
57
|
-
data: [
|
58
|
-
dummy_contact,
|
59
|
-
dummy_contact
|
60
|
-
],
|
61
|
-
pagingMetadata: {
|
62
|
-
count: 30,
|
63
|
-
has_more: true,
|
64
|
-
offset: 0,
|
65
|
-
total: 20013
|
66
|
-
},
|
67
|
-
}
|
68
|
-
|
69
|
-
helper = Helper.new(SevenApi::Resources::Contacts)
|
70
|
-
body = helper.request(helper.resource.method(:all), stub)
|
71
|
-
|
72
|
-
expect(body).to be_a(Array)
|
73
|
-
|
74
|
-
body.each do |contact|
|
75
|
-
assert_contact(contact)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'creates a contact and returns its ID as JSON' do
|
80
|
-
stub = dummy_contact
|
81
|
-
helper = Helper.new(SevenApi::Resources::Contacts)
|
82
|
-
body = helper.request(helper.resource.method(:create), stub)
|
83
|
-
|
84
|
-
expect(body).to be_a(Hash)
|
85
|
-
|
86
|
-
assert_new(body)
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'deletes a contact with given ID and return code as JSON' do
|
90
|
-
helper = Helper.new(SevenApi::Resources::Contacts)
|
91
|
-
body = helper.request(
|
92
|
-
helper.resource.method(:delete),
|
93
|
-
nil,
|
94
|
-
0
|
95
|
-
)
|
96
|
-
|
97
|
-
expect(body).to be_a(Hash)
|
98
|
-
expect(body[:return]).to be_a(String)
|
99
|
-
end
|
100
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'seven_api/contacts'
|
5
|
+
require 'seven_api/resources/contacts'
|
6
|
+
|
7
|
+
dummy_contact = {
|
8
|
+
"id": 12876882,
|
9
|
+
"avatar": "https://static.seven.io/uploads/contact_images/4A000c0d4e9431F483090dE8D13F3806.jpg",
|
10
|
+
"validation": {
|
11
|
+
"state": nil,
|
12
|
+
"timestamp": nil
|
13
|
+
},
|
14
|
+
"initials": {
|
15
|
+
"initials": "",
|
16
|
+
"color": "EEE0C9"
|
17
|
+
},
|
18
|
+
"properties": {
|
19
|
+
"address": nil,
|
20
|
+
"birthday": nil,
|
21
|
+
"city": nil,
|
22
|
+
"email": nil,
|
23
|
+
"firstname": nil,
|
24
|
+
"home_number": nil,
|
25
|
+
"lastname": nil,
|
26
|
+
"mobile_number": nil,
|
27
|
+
"notes": nil,
|
28
|
+
"postal_code": nil,
|
29
|
+
},
|
30
|
+
"groups": [
|
31
|
+
],
|
32
|
+
"created": "2024-01-09 13:12:48"
|
33
|
+
}
|
34
|
+
|
35
|
+
RSpec.describe SevenApi, 'contacts' do
|
36
|
+
$new_number_id = nil
|
37
|
+
|
38
|
+
def assert_new(response_body)
|
39
|
+
if response_body.is_a?(String)
|
40
|
+
code, $new_number_id = response_body.split("\n")
|
41
|
+
$new_number_id = $new_number_id.to_i
|
42
|
+
else
|
43
|
+
code = response_body[:return]
|
44
|
+
$new_number_id = response_body[:id]
|
45
|
+
end
|
46
|
+
|
47
|
+
expect(code).to be_numeric
|
48
|
+
expect($new_number_id).to be_an_instance_of(Integer)
|
49
|
+
end
|
50
|
+
|
51
|
+
def assert_contact(contact)
|
52
|
+
expect(contact[:id]).to be_numeric
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'returns all contacts' do
|
56
|
+
stub = {
|
57
|
+
data: [
|
58
|
+
dummy_contact,
|
59
|
+
dummy_contact
|
60
|
+
],
|
61
|
+
pagingMetadata: {
|
62
|
+
count: 30,
|
63
|
+
has_more: true,
|
64
|
+
offset: 0,
|
65
|
+
total: 20013
|
66
|
+
},
|
67
|
+
}
|
68
|
+
|
69
|
+
helper = Helper.new(SevenApi::Resources::Contacts)
|
70
|
+
body = helper.request(helper.resource.method(:all), stub)
|
71
|
+
|
72
|
+
expect(body).to be_a(Array)
|
73
|
+
|
74
|
+
body.each do |contact|
|
75
|
+
assert_contact(contact)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'creates a contact and returns its ID as JSON' do
|
80
|
+
stub = dummy_contact
|
81
|
+
helper = Helper.new(SevenApi::Resources::Contacts)
|
82
|
+
body = helper.request(helper.resource.method(:create), stub)
|
83
|
+
|
84
|
+
expect(body).to be_a(Hash)
|
85
|
+
|
86
|
+
assert_new(body)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'deletes a contact with given ID and return code as JSON' do
|
90
|
+
helper = Helper.new(SevenApi::Resources::Contacts)
|
91
|
+
body = helper.request(
|
92
|
+
helper.resource.method(:delete),
|
93
|
+
nil,
|
94
|
+
0
|
95
|
+
)
|
96
|
+
|
97
|
+
expect(body).to be_a(Hash)
|
98
|
+
expect(body[:return]).to be_a(String)
|
99
|
+
end
|
100
|
+
end
|
@@ -1,74 +1,74 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'seven_api/resources/groups'
|
5
|
-
|
6
|
-
dummy_group = {
|
7
|
-
"created": "2023-12-21 21:59:53",
|
8
|
-
"id": 17923,
|
9
|
-
"members_count": 543,
|
10
|
-
"name": "Group 1",
|
11
|
-
}
|
12
|
-
|
13
|
-
RSpec.describe SevenApi, 'groups' do
|
14
|
-
$new_number_id = nil
|
15
|
-
|
16
|
-
def assert_new(response_body)
|
17
|
-
code = response_body[:return]
|
18
|
-
$new_number_id = response_body[:id]
|
19
|
-
|
20
|
-
expect(code).to be_numeric
|
21
|
-
expect($new_number_id).to be_an_instance_of(Integer)
|
22
|
-
end
|
23
|
-
|
24
|
-
def assert_group(group)
|
25
|
-
expect(group[:id]).to be_numeric
|
26
|
-
expect(group[:name]).to be_an_instance_of(String)
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'returns all groups' do
|
30
|
-
stub = {
|
31
|
-
data: [
|
32
|
-
dummy_group,
|
33
|
-
dummy_group
|
34
|
-
],
|
35
|
-
pagingMetadata: {
|
36
|
-
count: 30,
|
37
|
-
has_more: true,
|
38
|
-
offset: 0,
|
39
|
-
total: 20013
|
40
|
-
},
|
41
|
-
}
|
42
|
-
|
43
|
-
helper = Helper.new(SevenApi::Resources::Groups)
|
44
|
-
body = helper.request(helper.resource.method(:all), stub)
|
45
|
-
|
46
|
-
expect(body).to be_a(Array)
|
47
|
-
|
48
|
-
body.each do |group|
|
49
|
-
assert_group(group)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'creates a group and returns its ID' do
|
54
|
-
stub = dummy_group
|
55
|
-
helper = Helper.new(SevenApi::Resources::Groups)
|
56
|
-
body = helper.request(helper.resource.method(:create), stub)
|
57
|
-
|
58
|
-
expect(body).to be_a(Hash)
|
59
|
-
|
60
|
-
assert_new(body)
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'deletes a group with given ID' do
|
64
|
-
helper = Helper.new(SevenApi::Resources::Groups)
|
65
|
-
body = helper.request(
|
66
|
-
helper.resource.method(:delete),
|
67
|
-
nil,
|
68
|
-
0
|
69
|
-
)
|
70
|
-
|
71
|
-
expect(body).to be_a(Hash)
|
72
|
-
expect(body[:return]).to be_a(String)
|
73
|
-
end
|
74
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'seven_api/resources/groups'
|
5
|
+
|
6
|
+
dummy_group = {
|
7
|
+
"created": "2023-12-21 21:59:53",
|
8
|
+
"id": 17923,
|
9
|
+
"members_count": 543,
|
10
|
+
"name": "Group 1",
|
11
|
+
}
|
12
|
+
|
13
|
+
RSpec.describe SevenApi, 'groups' do
|
14
|
+
$new_number_id = nil
|
15
|
+
|
16
|
+
def assert_new(response_body)
|
17
|
+
code = response_body[:return]
|
18
|
+
$new_number_id = response_body[:id]
|
19
|
+
|
20
|
+
expect(code).to be_numeric
|
21
|
+
expect($new_number_id).to be_an_instance_of(Integer)
|
22
|
+
end
|
23
|
+
|
24
|
+
def assert_group(group)
|
25
|
+
expect(group[:id]).to be_numeric
|
26
|
+
expect(group[:name]).to be_an_instance_of(String)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'returns all groups' do
|
30
|
+
stub = {
|
31
|
+
data: [
|
32
|
+
dummy_group,
|
33
|
+
dummy_group
|
34
|
+
],
|
35
|
+
pagingMetadata: {
|
36
|
+
count: 30,
|
37
|
+
has_more: true,
|
38
|
+
offset: 0,
|
39
|
+
total: 20013
|
40
|
+
},
|
41
|
+
}
|
42
|
+
|
43
|
+
helper = Helper.new(SevenApi::Resources::Groups)
|
44
|
+
body = helper.request(helper.resource.method(:all), stub)
|
45
|
+
|
46
|
+
expect(body).to be_a(Array)
|
47
|
+
|
48
|
+
body.each do |group|
|
49
|
+
assert_group(group)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'creates a group and returns its ID' do
|
54
|
+
stub = dummy_group
|
55
|
+
helper = Helper.new(SevenApi::Resources::Groups)
|
56
|
+
body = helper.request(helper.resource.method(:create), stub)
|
57
|
+
|
58
|
+
expect(body).to be_a(Hash)
|
59
|
+
|
60
|
+
assert_new(body)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'deletes a group with given ID' do
|
64
|
+
helper = Helper.new(SevenApi::Resources::Groups)
|
65
|
+
body = helper.request(
|
66
|
+
helper.resource.method(:delete),
|
67
|
+
nil,
|
68
|
+
0
|
69
|
+
)
|
70
|
+
|
71
|
+
expect(body).to be_a(Hash)
|
72
|
+
expect(body[:return]).to be_a(String)
|
73
|
+
end
|
74
|
+
end
|