@@ -5,6 +5,37 @@ Client = require('../src/client')
5
5
6
6
describe ' Usage report tests for 3Scale::Client' , ->
7
7
it ' should parse the response of the Authorize call' , (done ) ->
8
+ xml_body = " <status>\
9
+ <authorized>true</authorized>\
10
+ <plan>Ultimate</plan>\
11
+ <usage_reports>\
12
+ <usage_report metric=\" hits\" period=\" day\" exceeded=\" false\" >\
13
+ <period_start>2010-04-26 00:00:00 +0000</period_start>\
14
+ <period_end>2010-04-27 00:00:00 +0000</period_end>\
15
+ <current_value>10002</current_value>\
16
+ <max_value>50000</max_value>\
17
+ </usage_report>\
18
+ </usage_reports>\
19
+ </status>"
20
+
21
+ nock (' https://su1.3scale.net' )
22
+ .get (' /transactions/authorize.xml?app_id=foo&provider_key=1234abcd' )
23
+ .reply (200 , xml_body, { ' Content-Type' : ' application/xml' })
24
+
25
+ client = new Client ' 1234abcd'
26
+ client .authorize { app_id : ' foo' }, (response ) ->
27
+ assert .equal response .is_success (), true
28
+ assert .equal response .status_code , 200
29
+ assert .equal response .plan , ' Ultimate'
30
+ assert .equal response .usage_reports [0 ].metric , ' hits'
31
+ assert .equal response .usage_reports [0 ].period , ' day'
32
+ assert .equal response .usage_reports [0 ].period_start , ' 2010-04-26 00:00:00 +0000'
33
+ assert .equal response .usage_reports [0 ].period_end , ' 2010-04-27 00:00:00 +0000'
34
+ assert .equal response .usage_reports [0 ].current_value , ' 10002'
35
+ assert .equal response .usage_reports [0 ].max_value , ' 50000'
36
+ done ()
37
+
38
+ it ' should parse the response of the Authorize call, when limit is exceeded' , (done ) ->
8
39
xml_body = " <status>\
9
40
<authorized>false</authorized>\
10
41
<reason>usage limits are exceeded</reason>\
@@ -28,6 +59,7 @@ describe 'Usage report tests for 3Scale::Client', ->
28
59
assert .equal response .is_success (), false
29
60
assert .equal response .status_code , 409
30
61
assert .equal response .error_message , ' usage limits are exceeded'
62
+ assert .equal response .plan , ' Ultimate'
31
63
assert .equal response .usage_reports [0 ].metric , ' hits'
32
64
assert .equal response .usage_reports [0 ].period , ' day'
33
65
assert .equal response .usage_reports [0 ].period_start , ' 2010-04-26 00:00:00 +0000'
@@ -58,6 +90,7 @@ describe 'Usage report tests for 3Scale::Client', ->
58
90
assert .equal response .is_success (), false
59
91
assert .equal response .status_code , 409
60
92
assert .equal response .error_message , ' usage limits are exceeded'
93
+ assert .equal response .plan , ' Ultimate'
61
94
assert .equal response .usage_reports [0 ].metric , ' hits'
62
95
assert .equal response .usage_reports [0 ].period , ' eternity'
63
96
assert .equal response .usage_reports [0 ].period_start , undefined
0 commit comments