mxhero-api 0.1.11 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/communication.rb +35 -0
- data/lib/groups.rb +178 -0
- data/lib/mxhero-api.rb +288 -312
- data/lib/urls.rb +19 -0
- data/mxhero-api.gemspec +4 -4
- data/test/fixtures/api/account_properties.yml +12 -13
- data/test/fixtures/api/account_properties_not_found.yml +9 -9
- data/test/fixtures/api/accounts.yml +39 -0
- data/test/fixtures/api/accounts_filtered.yml +57 -42
- data/test/fixtures/api/accounts_from_domain.yml +10 -10
- data/test/fixtures/api/accounts_from_domain_paginated.yml +10 -10
- data/test/fixtures/api/accounts_without_group.yml +75 -0
- data/test/fixtures/api/add_an_inexistent_account_to_group.yml +39 -0
- data/test/fixtures/api/add_and_remove_account.yml +219 -0
- data/test/fixtures/api/all_groups.yml +39 -0
- data/test/fixtures/api/create_rule_for_domain.yml +95 -21
- data/test/fixtures/api/delete_group.yml +75 -0
- data/test/fixtures/api/delete_rule.yml +21 -61
- data/test/fixtures/api/domain_by_id.yml +10 -10
- data/test/fixtures/api/domain_by_id_not_found.yml +9 -9
- data/test/fixtures/api/domain_rule.yml +62 -76
- data/test/fixtures/api/domains.yml +10 -10
- data/test/fixtures/api/remove_account_from_group_twice.yml +150 -0
- data/test/fixtures/api/remove_inexistente_account_from_group.yml +39 -0
- data/test/fixtures/api/rules_for_domain.yml +11 -57
- data/test/fixtures/api/rules_for_domain_by_component.yml +6 -8
- data/test/fixtures/api/save_group.yml +119 -0
- data/test/fixtures/api/update_account_properties.yml +35 -33
- data/test/fixtures/api/update_rule.yml +35 -76
- data/test/helper.rb +1 -1
- data/test/test_groups.rb +104 -0
- data/test/test_mxhero_api.rb +49 -27
- metadata +26 -7
- data/test/fixtures/api/create_rule_alredy_exist.yml +0 -81
- data/test/fixtures/api/create_rule_success.yml +0 -41
@@ -2,7 +2,7 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri: http://admin:password@
|
5
|
+
uri: http://admin:password@test.mxhero.com/webapi/api/v1/domains/tesla.com/accounts/test/properties
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: ''
|
@@ -19,34 +19,33 @@ http_interactions:
|
|
19
19
|
message: !binary |-
|
20
20
|
T0s=
|
21
21
|
headers:
|
22
|
+
!binary "RGF0ZQ==":
|
23
|
+
- !binary |-
|
24
|
+
VGh1LCAxMiBTZXAgMjAxMyAyMToyMToxMyBHTVQ=
|
22
25
|
!binary "U2VydmVy":
|
23
26
|
- !binary |-
|
24
|
-
|
27
|
+
QXBhY2hlLzIuMi4xNCAoVWJ1bnR1KQ==
|
28
|
+
!binary "Q29udGVudC1MZW5ndGg=":
|
29
|
+
- !binary |-
|
30
|
+
MzM3
|
25
31
|
!binary "Q29udGVudC1UeXBl":
|
26
32
|
- !binary |-
|
27
33
|
YXBwbGljYXRpb24vanNvbg==
|
28
|
-
!binary "VHJhbnNmZXItRW5jb2Rpbmc=":
|
29
|
-
- !binary |-
|
30
|
-
Y2h1bmtlZA==
|
31
|
-
!binary "RGF0ZQ==":
|
32
|
-
- !binary |-
|
33
|
-
RnJpLCAwOSBBdWcgMjAxMyAxNzozNTo1MCBHTVQ=
|
34
34
|
body:
|
35
35
|
encoding: US-ASCII
|
36
|
-
string: ! '[{"name":"email","value":"
|
37
|
-
|
38
|
-
|
39
|
-
2"},{"name":"opt3","value":""},{"name":"telephone","value":"3333-3333"}]'
|
36
|
+
string: ! '[{"name":"email","value":""},{"name":"fax","value":null},{"name":"lastname","value":"
|
37
|
+
CHANGED CHANGED CHANGED CHANGED CHANGED"},{"name":"mobile","value":""},{"name":"name","value":"
|
38
|
+
CHANGED CHANGED CHANGED CHANGED CHANGED"},{"name":"opt1","value":""},{"name":"opt2","value":""},{"name":"opt3","value":""},{"name":"telephone","value":""}]'
|
40
39
|
http_version:
|
41
|
-
recorded_at:
|
40
|
+
recorded_at: Thu, 12 Sep 2013 21:21:12 GMT
|
42
41
|
- request:
|
43
42
|
method: put
|
44
|
-
uri: http://admin:password@
|
43
|
+
uri: http://admin:password@test.mxhero.com/webapi/api/v1/domains/tesla.com/accounts/test/properties
|
45
44
|
body:
|
46
45
|
encoding: UTF-8
|
47
|
-
string: ! '[{"name":"email","value":"
|
48
|
-
|
49
|
-
|
46
|
+
string: ! '[{"name":"email","value":""},{"name":"fax","value":null},{"name":"lastname","value":"
|
47
|
+
CHANGED CHANGED CHANGED CHANGED CHANGED CHANGED"},{"name":"mobile","value":""},{"name":"name","value":"
|
48
|
+
CHANGED CHANGED CHANGED CHANGED CHANGED CHANGED"},{"name":"opt1","value":""},{"name":"opt2","value":""},{"name":"opt3","value":""},{"name":"telephone","value":""}]'
|
50
49
|
headers:
|
51
50
|
Accept:
|
52
51
|
- application/json
|
@@ -60,23 +59,26 @@ http_interactions:
|
|
60
59
|
message: !binary |-
|
61
60
|
T0s=
|
62
61
|
headers:
|
62
|
+
!binary "RGF0ZQ==":
|
63
|
+
- !binary |-
|
64
|
+
VGh1LCAxMiBTZXAgMjAxMyAyMToyMToxMyBHTVQ=
|
63
65
|
!binary "U2VydmVy":
|
64
66
|
- !binary |-
|
65
|
-
|
67
|
+
QXBhY2hlLzIuMi4xNCAoVWJ1bnR1KQ==
|
66
68
|
!binary "Q29udGVudC1MZW5ndGg=":
|
67
69
|
- !binary |-
|
68
70
|
MA==
|
69
|
-
!binary "
|
71
|
+
!binary "Q29udGVudC1UeXBl":
|
70
72
|
- !binary |-
|
71
|
-
|
73
|
+
dGV4dC9wbGFpbg==
|
72
74
|
body:
|
73
75
|
encoding: US-ASCII
|
74
76
|
string: ''
|
75
77
|
http_version:
|
76
|
-
recorded_at:
|
78
|
+
recorded_at: Thu, 12 Sep 2013 21:21:13 GMT
|
77
79
|
- request:
|
78
80
|
method: get
|
79
|
-
uri: http://admin:password@
|
81
|
+
uri: http://admin:password@test.mxhero.com/webapi/api/v1/domains/tesla.com/accounts/test/properties
|
80
82
|
body:
|
81
83
|
encoding: US-ASCII
|
82
84
|
string: ''
|
@@ -93,23 +95,23 @@ http_interactions:
|
|
93
95
|
message: !binary |-
|
94
96
|
T0s=
|
95
97
|
headers:
|
98
|
+
!binary "RGF0ZQ==":
|
99
|
+
- !binary |-
|
100
|
+
VGh1LCAxMiBTZXAgMjAxMyAyMToyMToxNCBHTVQ=
|
96
101
|
!binary "U2VydmVy":
|
97
102
|
- !binary |-
|
98
|
-
|
103
|
+
QXBhY2hlLzIuMi4xNCAoVWJ1bnR1KQ==
|
104
|
+
!binary "Q29udGVudC1MZW5ndGg=":
|
105
|
+
- !binary |-
|
106
|
+
MzUz
|
99
107
|
!binary "Q29udGVudC1UeXBl":
|
100
108
|
- !binary |-
|
101
109
|
YXBwbGljYXRpb24vanNvbg==
|
102
|
-
!binary "VHJhbnNmZXItRW5jb2Rpbmc=":
|
103
|
-
- !binary |-
|
104
|
-
Y2h1bmtlZA==
|
105
|
-
!binary "RGF0ZQ==":
|
106
|
-
- !binary |-
|
107
|
-
RnJpLCAwOSBBdWcgMjAxMyAxNzozNTo1MCBHTVQ=
|
108
110
|
body:
|
109
111
|
encoding: US-ASCII
|
110
|
-
string: ! '[{"name":"email","value":"
|
111
|
-
|
112
|
-
|
112
|
+
string: ! '[{"name":"email","value":""},{"name":"fax","value":null},{"name":"lastname","value":"
|
113
|
+
CHANGED CHANGED CHANGED CHANGED CHANGED CHANGED"},{"name":"mobile","value":""},{"name":"name","value":"
|
114
|
+
CHANGED CHANGED CHANGED CHANGED CHANGED CHANGED"},{"name":"opt1","value":""},{"name":"opt2","value":""},{"name":"opt3","value":""},{"name":"telephone","value":""}]'
|
113
115
|
http_version:
|
114
|
-
recorded_at:
|
116
|
+
recorded_at: Thu, 12 Sep 2013 21:21:13 GMT
|
115
117
|
recorded_with: VCR 2.5.0
|
@@ -2,7 +2,7 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri: http://admin:password@
|
5
|
+
uri: http://admin:password@test.mxhero.com/webapi/api/v1/domains/tesla.com/rules
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: ''
|
@@ -19,71 +19,33 @@ http_interactions:
|
|
19
19
|
message: !binary |-
|
20
20
|
T0s=
|
21
21
|
headers:
|
22
|
+
!binary "RGF0ZQ==":
|
23
|
+
- !binary |-
|
24
|
+
VGh1LCAxMiBTZXAgMjAxMyAyMToyMToxNyBHTVQ=
|
22
25
|
!binary "U2VydmVy":
|
23
26
|
- !binary |-
|
24
|
-
|
27
|
+
QXBhY2hlLzIuMi4xNCAoVWJ1bnR1KQ==
|
28
|
+
!binary "Q29udGVudC1MZW5ndGg=":
|
29
|
+
- !binary |-
|
30
|
+
Nzg3
|
25
31
|
!binary "Q29udGVudC1UeXBl":
|
26
32
|
- !binary |-
|
27
33
|
YXBwbGljYXRpb24vanNvbg==
|
28
|
-
!binary "VHJhbnNmZXItRW5jb2Rpbmc=":
|
29
|
-
- !binary |-
|
30
|
-
Y2h1bmtlZA==
|
31
|
-
!binary "RGF0ZQ==":
|
32
|
-
- !binary |-
|
33
|
-
RnJpLCAwOSBBdWcgMjAxMyAwNjozNDowNCBHTVQ=
|
34
34
|
body:
|
35
35
|
encoding: US-ASCII
|
36
|
-
string: ! '[{"id":
|
37
|
-
|
38
|
-
|
39
|
-
you are notified that disclosing, copying, distributing or taking any action
|
40
|
-
in reliance on the contents of this information is strictly prohibited.</SPAN>\n </P>\n</BODY>"},{"propertyKey":"return.message.plain","propertyValue":"This
|
41
|
-
message is intended only for ${mxrecipient}. If you are not the intended recipient
|
42
|
-
you are notified that disclosing, copying, distributing or taking any action
|
43
|
-
in reliance on the contents of this information is strictly prohibited."},{"propertyKey":"return.message.rte","propertyValue":"<TextFlow
|
44
|
-
whiteSpaceCollapse=\"preserve\" version=\"2.0.0\" xmlns=\"http://ns.adobe.com/textLayout/2008\"><p><span>This
|
45
|
-
message is intended only for ${mxrecipient}. If you are not the intended recipient
|
46
|
-
you are notified that disclosing, copying, distributing or taking any action
|
47
|
-
in reliance on the contents of this information is strictly prohibited.</span></p></TextFlow>"}]},{"id":116,"domain":"tesla.com","name":"marketing
|
48
|
-
rule","created":1376029996000,"updated":1376029996000,"enabled":true,"twoWays":false,"adminOrder":null,"component":"org.mxhero.feature.disclaimer","fromDirection":{"id":217,"directionType":"domain","freeValue":"tesla.com","domain":"tesla.com","account":null,"group":null},"toDirection":{"id":218,"directionType":"group","freeValue":"marketing","domain":"tesla.com","account":null,"group":"marketing"},"properties":[{"propertyKey":"return.message","propertyValue":"<BODY>\n <P
|
49
|
-
STYLE=\"text-align:left;\">\n <SPAN STYLE=\"letter-spacing:0px;color:#000000;font-size:12px;font-family:''Arial'';\">This
|
50
|
-
message is intended only for ${mxrecipient}. If you are not the intended recipient
|
51
|
-
you are notified that disclosing, copying, distributing or taking any action
|
52
|
-
in reliance on the contents of this information is strictly prohibited.</SPAN>\n </P>\n</BODY>"},{"propertyKey":"return.message.plain","propertyValue":"This
|
53
|
-
message is intended only for ${mxrecipient}. If you are not the intended recipient
|
54
|
-
you are notified that disclosing, copying, distributing or taking any action
|
55
|
-
in reliance on the contents of this information is strictly prohibited."},{"propertyKey":"return.message.rte","propertyValue":"<TextFlow
|
56
|
-
whiteSpaceCollapse=\"preserve\" version=\"2.0.0\" xmlns=\"http://ns.adobe.com/textLayout/2008\"><p><span>This
|
57
|
-
message is intended only for ${mxrecipient}. If you are not the intended recipient
|
58
|
-
you are notified that disclosing, copying, distributing or taking any action
|
59
|
-
in reliance on the contents of this information is strictly prohibited.</span></p></TextFlow>"}]},{"id":117,"domain":"tesla.com","name":"marketing","created":1376030034000,"updated":1376030034000,"enabled":true,"twoWays":false,"adminOrder":null,"component":"org.mxhero.feature.disclaimer","fromDirection":{"id":219,"directionType":"group","freeValue":"marketing","domain":"tesla.com","account":null,"group":"marketing"},"toDirection":{"id":220,"directionType":"anyoneelse","freeValue":"anyoneelse","domain":null,"account":null,"group":null},"properties":[{"propertyKey":"return.message","propertyValue":"<BODY>\n <P
|
60
|
-
STYLE=\"text-align:left;\">\n <SPAN STYLE=\"letter-spacing:0px;color:#000000;font-size:12px;font-family:''Arial'';\">This
|
61
|
-
message is intended only for ${mxrecipient}. If you are not the intended recipient
|
62
|
-
you are notified that disclosing, copying, distributing or taking any action
|
63
|
-
in reliance on the contents of this information is strictly prohibited.</SPAN>\n </P>\n</BODY>"},{"propertyKey":"return.message.plain","propertyValue":"This
|
64
|
-
message is intended only for ${mxrecipient}. If you are not the intended recipient
|
65
|
-
you are notified that disclosing, copying, distributing or taking any action
|
66
|
-
in reliance on the contents of this information is strictly prohibited."},{"propertyKey":"return.message.rte","propertyValue":"<TextFlow
|
67
|
-
whiteSpaceCollapse=\"preserve\" version=\"2.0.0\" xmlns=\"http://ns.adobe.com/textLayout/2008\"><p><span>This
|
68
|
-
message is intended only for ${mxrecipient}. If you are not the intended recipient
|
69
|
-
you are notified that disclosing, copying, distributing or taking any action
|
70
|
-
in reliance on the contents of this information is strictly prohibited.</span></p></TextFlow>"}]}]'
|
36
|
+
string: ! '[{"id":195,"domain":"tesla.com","name":"The rules for sales","created":1379020876000,"updated":1379020876000,"enabled":true,"twoWays":false,"adminOrder":null,"component":"org.mxhero.feature.disclaimer","fromDirection":{"id":378,"directionType":"domain","freeValue":"tesla.com","domain":"tesla.com","account":null,"group":null},"toDirection":{"id":379,"directionType":"anyone","freeValue":"Anyone","domain":"tesla.com","account":null,"group":null},"properties":[{"propertyKey":"return.message","propertyValue":"<hr
|
37
|
+
/><p><em><span style=\"color:green\">Think before you print and save a tree.</span></em></p>"},{"propertyKey":"return.message.plain","propertyValue":"\n----------------\nThink
|
38
|
+
before you print and save a tree.r\n\n"},{"propertyKey":"interParsing","propertyValue":"true"}]}]'
|
71
39
|
http_version:
|
72
|
-
recorded_at:
|
40
|
+
recorded_at: Thu, 12 Sep 2013 21:21:16 GMT
|
73
41
|
- request:
|
74
42
|
method: put
|
75
|
-
uri: http://admin:password@
|
43
|
+
uri: http://admin:password@test.mxhero.com/webapi/api/v1/domains/tesla.com/rules/195
|
76
44
|
body:
|
77
45
|
encoding: UTF-8
|
78
|
-
string: ! '{"id":
|
79
|
-
content"},{"propertyKey":"return.message.plain","propertyValue":"
|
80
|
-
|
81
|
-
you are notified that disclosing, copying, distributing or taking any action
|
82
|
-
in reliance on the contents of this information is strictly prohibited."},{"propertyKey":"return.message.rte","propertyValue":"<TextFlow
|
83
|
-
whiteSpaceCollapse=\"preserve\" version=\"2.0.0\" xmlns=\"http://ns.adobe.com/textLayout/2008\"><p><span>This
|
84
|
-
message is intended only for ${mxrecipient}. If you are not the intended recipient
|
85
|
-
you are notified that disclosing, copying, distributing or taking any action
|
86
|
-
in reliance on the contents of this information is strictly prohibited.</span></p></TextFlow>"}]}'
|
46
|
+
string: ! '{"id":195,"domain":"tesla.com","name":"The rules for sales more name","created":1379020876000,"updated":1379020876000,"enabled":true,"twoWays":false,"adminOrder":null,"component":"org.mxhero.feature.disclaimer","fromDirection":{"id":378,"directionType":"domain","freeValue":"tesla.com","domain":"tesla.com","account":null,"group":null},"toDirection":{"id":379,"directionType":"anyone","freeValue":"Anyone","domain":"tesla.com","account":null,"group":null},"properties":[{"propertyKey":"return.message","propertyValue":"another
|
47
|
+
content"},{"propertyKey":"return.message.plain","propertyValue":"\n----------------\nThink
|
48
|
+
before you print and save a tree.r\n\n"},{"propertyKey":"interParsing","propertyValue":"true"}]}'
|
87
49
|
headers:
|
88
50
|
Accept:
|
89
51
|
- application/json
|
@@ -97,23 +59,26 @@ http_interactions:
|
|
97
59
|
message: !binary |-
|
98
60
|
T0s=
|
99
61
|
headers:
|
62
|
+
!binary "RGF0ZQ==":
|
63
|
+
- !binary |-
|
64
|
+
VGh1LCAxMiBTZXAgMjAxMyAyMToyMToxNyBHTVQ=
|
100
65
|
!binary "U2VydmVy":
|
101
66
|
- !binary |-
|
102
|
-
|
67
|
+
QXBhY2hlLzIuMi4xNCAoVWJ1bnR1KQ==
|
103
68
|
!binary "Q29udGVudC1MZW5ndGg=":
|
104
69
|
- !binary |-
|
105
70
|
MA==
|
106
|
-
!binary "
|
71
|
+
!binary "Q29udGVudC1UeXBl":
|
107
72
|
- !binary |-
|
108
|
-
|
73
|
+
dGV4dC9wbGFpbg==
|
109
74
|
body:
|
110
75
|
encoding: US-ASCII
|
111
76
|
string: ''
|
112
77
|
http_version:
|
113
|
-
recorded_at:
|
78
|
+
recorded_at: Thu, 12 Sep 2013 21:21:17 GMT
|
114
79
|
- request:
|
115
80
|
method: get
|
116
|
-
uri: http://admin:password@
|
81
|
+
uri: http://admin:password@test.mxhero.com/webapi/api/v1/domains/tesla.com/rules/195
|
117
82
|
body:
|
118
83
|
encoding: US-ASCII
|
119
84
|
string: ''
|
@@ -130,29 +95,23 @@ http_interactions:
|
|
130
95
|
message: !binary |-
|
131
96
|
T0s=
|
132
97
|
headers:
|
98
|
+
!binary "RGF0ZQ==":
|
99
|
+
- !binary |-
|
100
|
+
VGh1LCAxMiBTZXAgMjAxMyAyMToyMToxOCBHTVQ=
|
133
101
|
!binary "U2VydmVy":
|
134
102
|
- !binary |-
|
135
|
-
|
103
|
+
QXBhY2hlLzIuMi4xNCAoVWJ1bnR1KQ==
|
104
|
+
!binary "Q29udGVudC1MZW5ndGg=":
|
105
|
+
- !binary |-
|
106
|
+
NzE0
|
136
107
|
!binary "Q29udGVudC1UeXBl":
|
137
108
|
- !binary |-
|
138
109
|
YXBwbGljYXRpb24vanNvbg==
|
139
|
-
!binary "VHJhbnNmZXItRW5jb2Rpbmc=":
|
140
|
-
- !binary |-
|
141
|
-
Y2h1bmtlZA==
|
142
|
-
!binary "RGF0ZQ==":
|
143
|
-
- !binary |-
|
144
|
-
RnJpLCAwOSBBdWcgMjAxMyAwNjozNDowNCBHTVQ=
|
145
110
|
body:
|
146
111
|
encoding: US-ASCII
|
147
|
-
string: ! '{"id":
|
148
|
-
content"},{"propertyKey":"return.message.plain","propertyValue":"
|
149
|
-
|
150
|
-
you are notified that disclosing, copying, distributing or taking any action
|
151
|
-
in reliance on the contents of this information is strictly prohibited."},{"propertyKey":"return.message.rte","propertyValue":"<TextFlow
|
152
|
-
whiteSpaceCollapse=\"preserve\" version=\"2.0.0\" xmlns=\"http://ns.adobe.com/textLayout/2008\"><p><span>This
|
153
|
-
message is intended only for ${mxrecipient}. If you are not the intended recipient
|
154
|
-
you are notified that disclosing, copying, distributing or taking any action
|
155
|
-
in reliance on the contents of this information is strictly prohibited.</span></p></TextFlow>"}]}'
|
112
|
+
string: ! '{"id":195,"domain":"tesla.com","name":"The rules for sales more name","created":1379020876000,"updated":1379020877000,"enabled":true,"twoWays":false,"adminOrder":null,"component":"org.mxhero.feature.disclaimer","fromDirection":{"id":378,"directionType":"domain","freeValue":"tesla.com","domain":"tesla.com","account":null,"group":null},"toDirection":{"id":379,"directionType":"anyone","freeValue":"Anyone","domain":"tesla.com","account":null,"group":null},"properties":[{"propertyKey":"return.message","propertyValue":"another
|
113
|
+
content"},{"propertyKey":"return.message.plain","propertyValue":"\n----------------\nThink
|
114
|
+
before you print and save a tree.r\n\n"},{"propertyKey":"interParsing","propertyValue":"true"}]}'
|
156
115
|
http_version:
|
157
|
-
recorded_at:
|
116
|
+
recorded_at: Thu, 12 Sep 2013 21:21:17 GMT
|
158
117
|
recorded_with: VCR 2.5.0
|
data/test/helper.rb
CHANGED
@@ -10,7 +10,7 @@ require 'minitest/pride'
|
|
10
10
|
Dir['./lib/**/*.rb'].each { |rb| require rb }
|
11
11
|
|
12
12
|
TEST_API_DOMAIN = 'tesla.com'
|
13
|
-
TEST_API_URL = ENV['TEST_API_URL'] || 'http://
|
13
|
+
TEST_API_URL = ENV['TEST_API_URL'] || 'http://test.mxhero.com/webapi/api/v1'
|
14
14
|
TEST_API_USER = 'admin'
|
15
15
|
TEST_API_PASSWORD = 'password'
|
16
16
|
|
data/test/test_groups.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class GroupsTest < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@groups = MxHero::API::Groups.new(domain,
|
6
|
+
username: TEST_API_USER,
|
7
|
+
password: TEST_API_PASSWORD,
|
8
|
+
verbose: false, api_url: TEST_API_URL)
|
9
|
+
end
|
10
|
+
|
11
|
+
def domain
|
12
|
+
TEST_API_DOMAIN
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_all
|
16
|
+
VCR.use_cassette('all_groups') do
|
17
|
+
groups = @groups.all
|
18
|
+
[:total_elements, :total_pages, :actual_page].each do |property|
|
19
|
+
assert groups.respond_to?(property), "Must be contain #{property}"
|
20
|
+
end
|
21
|
+
groups.first.is_a? MxHero::API::Group
|
22
|
+
groups.any? { |group| group.name == 'development' }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_save
|
27
|
+
VCR.use_cassette('save_group') do
|
28
|
+
delete_all_groups
|
29
|
+
group = MxHero::API::Group.new(name: 'test')
|
30
|
+
response = @groups.save(group)
|
31
|
+
assert response.is_a? MxHero::API::Response
|
32
|
+
assert response.success?
|
33
|
+
assert response.content.is_a? MxHero::API::Group
|
34
|
+
assert 'test', response.content.name
|
35
|
+
|
36
|
+
response = @groups.save(group)
|
37
|
+
refute response.success?
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete_all_groups
|
42
|
+
@groups.all.each { |group| @groups.delete(group.name) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_delete
|
46
|
+
VCR.use_cassette('delete_group') do
|
47
|
+
assert @groups.delete('test')
|
48
|
+
groups = @groups.all
|
49
|
+
refute groups.any? { |group| group.name == 'test' }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_accounts
|
54
|
+
VCR.use_cassette('accounts') do
|
55
|
+
accounts = @groups.accounts('development')
|
56
|
+
assert accounts.first.is_a? MxHero::API::Account
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_add_and_remove_account
|
61
|
+
VCR.use_cassette('add_and_remove_account') do
|
62
|
+
account_name = 'john.doe'
|
63
|
+
group = 'development'
|
64
|
+
if @groups.accounts(group).any? { |account| account.account == account_name }
|
65
|
+
@groups.remove_account(group, account_name)
|
66
|
+
end
|
67
|
+
assert @groups.add_account(group, account_name).success?
|
68
|
+
assert @groups.accounts(group).any? { |account| account.account == account_name }
|
69
|
+
assert @groups.remove_account(group, account_name).success?
|
70
|
+
refute @groups.accounts(group).any? { |account| account.account == account_name }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_try_to_add_an_inexistent_account_to_group
|
75
|
+
VCR.use_cassette('add_an_inexistent_account_to_group') do
|
76
|
+
refute @groups.add_account('development', 'account.is.not.exist').success?
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_try_to_remove_account_from_group_twice
|
81
|
+
VCR.use_cassette('remove_account_from_group_twice') do
|
82
|
+
account = @groups.accounts('development').first
|
83
|
+
unless account
|
84
|
+
account = 'john.doe'
|
85
|
+
@groups.add_account('development', 'john.doe')
|
86
|
+
end
|
87
|
+
assert @groups.remove_account('development', account.account).success?
|
88
|
+
remove_again = @groups.remove_account('development', account.account)
|
89
|
+
refute remove_again.success?
|
90
|
+
assert_equal 'domain.group.account.not.in.group', remove_again.content[:developerMessage]
|
91
|
+
@groups.add_account('development', account.account)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_try_to_remove_inexistent_account
|
96
|
+
VCR.use_cassette('remove_inexistente_account_from_group') do
|
97
|
+
response = @groups.remove_account('development', 'non.existent.account')
|
98
|
+
refute response.success?
|
99
|
+
assert_equal 'domain.account.not.found', response.content[:developerMessage]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
data/test/test_mxhero_api.rb
CHANGED
@@ -28,7 +28,7 @@ class MxHeroAPITest < MiniTest::Unit::TestCase
|
|
28
28
|
property[:propertyValue] = 'another content'
|
29
29
|
updated_rule[:name] = updated_rule[:name] + ' more name'
|
30
30
|
|
31
|
-
assert @api.update_rule(updated_rule)
|
31
|
+
assert @api.update_rule(updated_rule), 'the rule not must be updated'
|
32
32
|
|
33
33
|
rule = @api.domain_rule(updated_rule[:domain], updated_rule[:id])
|
34
34
|
assert updated_rule, rule
|
@@ -51,7 +51,7 @@ class MxHeroAPITest < MiniTest::Unit::TestCase
|
|
51
51
|
response = @api.rules_for_domain(domain)
|
52
52
|
assert response.code == 200
|
53
53
|
rules = response.msg
|
54
|
-
|
54
|
+
assert rules.is_a? Array
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -110,15 +110,29 @@ class MxHeroAPITest < MiniTest::Unit::TestCase
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
+
def test_accounts_without_group
|
114
|
+
VCR.use_cassette('accounts_without_group') do
|
115
|
+
response = @api.accounts_by_domain(domain, without_group: true)
|
116
|
+
assert response.key? :elements
|
117
|
+
account = response[:elements].first
|
118
|
+
start_with = account[:account][0..2]
|
119
|
+
|
120
|
+
response = @api.accounts_by_domain(domain, without_group: true, account: start_with)
|
121
|
+
assert response[:totalElements] >= 1
|
122
|
+
find_account = response[:elements].first
|
123
|
+
assert_equal start_with, find_account[:account][0..2]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
113
127
|
def test_accounts_by_domain_filtered
|
114
128
|
VCR.use_cassette('accounts_filtered') do
|
115
129
|
# The test environment have 4 accounts:
|
116
|
-
#
|
117
|
-
response = @api.accounts_by_domain(domain, account: 'user')
|
118
|
-
assert_equal 3, response[:elements].count
|
130
|
+
# agent.smith, john.doe, test, test1, test2
|
119
131
|
response = @api.accounts_by_domain(domain, account: 'test')
|
132
|
+
assert_equal 3, response[:elements].count
|
133
|
+
response = @api.accounts_by_domain(domain, account: 'john.doe')
|
120
134
|
assert_equal 1, response[:elements].count
|
121
|
-
response = @api.accounts_by_domain(domain, account: '
|
135
|
+
response = @api.accounts_by_domain(domain, account: 'test1')
|
122
136
|
assert_equal 1, response[:elements].count
|
123
137
|
end
|
124
138
|
end
|
@@ -140,27 +154,20 @@ class MxHeroAPITest < MiniTest::Unit::TestCase
|
|
140
154
|
assert response
|
141
155
|
end
|
142
156
|
end
|
143
|
-
|
144
157
|
|
145
|
-
def
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
response = @api.create_rule(create_rule_msg)
|
155
|
-
assert_equal 201, response.code
|
156
|
-
new_response = @api.create_rule(create_rule_msg)
|
157
|
-
assert_equal 500, new_response.code
|
158
|
-
assert_equal "rules.already.exists.for.component", new_response.msg[:developerMessage]
|
159
|
-
end
|
160
|
-
end
|
158
|
+
#def test_try_to_create_rule_that_alredy_exist
|
159
|
+
# VCR.use_cassette('create_rule_alredy_exist') do
|
160
|
+
# response = @api.create_rule(create_rule_msg)
|
161
|
+
# #assert_equal 201, response.code
|
162
|
+
# new_response = @api.create_rule(create_rule_msg)
|
163
|
+
# assert_equal 500, new_response.code
|
164
|
+
# assert_equal "rules.already.exists.for.component", new_response.msg[:developerMessage]
|
165
|
+
# end
|
166
|
+
#end
|
161
167
|
|
162
168
|
def test_create_rule_for_domain
|
163
169
|
VCR.use_cassette('create_rule_for_domain') do
|
170
|
+
delete_all_rules
|
164
171
|
response = @api.create_rule_for_domain(domain, rule)
|
165
172
|
assert response.code == 201
|
166
173
|
new_response = @api.create_rule_for_domain(domain, rule)
|
@@ -200,8 +207,8 @@ class MxHeroAPITest < MiniTest::Unit::TestCase
|
|
200
207
|
account = 'test'
|
201
208
|
response = @api.account_properties(domain, account)
|
202
209
|
properties = response.msg
|
203
|
-
properties['lastname'] = properties['lastname'] + ' CHANGED'
|
204
|
-
properties['name'] = properties['name'] + ' CHANGED'
|
210
|
+
properties['lastname'] = ( properties['lastname'] || '' ) + ' CHANGED'
|
211
|
+
properties['name'] = ( properties['name'] || '' ) + ' CHANGED'
|
205
212
|
properties['fax'] = nil
|
206
213
|
response = @api.update_account_properties(domain, account, properties)
|
207
214
|
assert_equal 200, response.code
|
@@ -214,9 +221,20 @@ class MxHeroAPITest < MiniTest::Unit::TestCase
|
|
214
221
|
end
|
215
222
|
|
216
223
|
private
|
224
|
+
|
225
|
+
def delete_all_rules
|
226
|
+
response = @api.rules_for_domain(domain)
|
227
|
+
response.msg.each do |rule|
|
228
|
+
@api.delete_rule(domain, rule[:id])
|
229
|
+
end
|
230
|
+
end
|
217
231
|
|
218
232
|
def obtain_rules(domain)
|
219
233
|
response = @api.rules_for_domain(domain)
|
234
|
+
if response.msg.nil? || response.msg.empty?
|
235
|
+
created = @api.create_rule_for_domain(domain, rule)
|
236
|
+
return [ created.msg ]
|
237
|
+
end
|
220
238
|
response.msg
|
221
239
|
end
|
222
240
|
|
@@ -232,12 +250,16 @@ class MxHeroAPITest < MiniTest::Unit::TestCase
|
|
232
250
|
msg
|
233
251
|
end
|
234
252
|
|
235
|
-
def
|
253
|
+
def random_name
|
254
|
+
(0...15).map{ ('a'..'z').to_a[rand(26)] }.join
|
255
|
+
end
|
256
|
+
|
257
|
+
def create_rule_msg(name = nil)
|
236
258
|
{
|
237
259
|
#"domain" => "tesla.com",
|
238
260
|
twoWays: false,
|
239
261
|
enabled: true,
|
240
|
-
name: "Email footer",
|
262
|
+
name: name || "Email footer",
|
241
263
|
created: 1369682598000,
|
242
264
|
fromDirection: { directionType: "domain", domain: domain, freeValue: domain },
|
243
265
|
toDirection: { directionType: "domain", domain: domain, freeValue: domain },
|