-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathresponse_test.coffee
61 lines (48 loc) · 1.96 KB
/
response_test.coffee
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
assert = require 'assert'
Response = require('../src/response')
describe 'Basic test for the 3Scale::Response', ->
describe 'a response', ->
it 'should have a success method', ->
response = new Response()
assert.equal typeof response.success, 'function'
it 'should have a code & message null after a success', ->
response = new Response()
response.success()
assert.equal response.error_code, null
assert.equal response.error_message, null
it 'should have a error method', ->
response = new Response()
assert.equal typeof response.error, 'function'
it 'should have a custom code and message after error', ->
response = new Response()
response.error(403, 'Error message', 'error_code')
assert.equal response.error_message, 'Error message'
assert.equal response.error_code, 'error_code'
it 'should have a custom code and null message after error', ->
response = new Response()
response.error(403, 'Error message')
assert.equal response.error_message, 'Error message'
assert.equal response.error_code, null
it 'have a is_success method', ->
response = new Response()
assert.equal typeof response.is_success, 'function'
it 'be true after a call to success method', ->
response = new Response()
response.success()
assert response.is_success()
it 'should have a status_code of 200 after a call to success method', ->
response = new Response()
response.success(200)
assert.equal response.status_code, 200
it 'be false after a error method', ->
response = new Response()
response.error(403, 'Error message', 'error_code')
assert.equal response.is_success(), false
it 'should have a field for the status code', ->
response = new Response()
response.error(
409,
'user key "badkey" is invalid',
'user_key_invalid'
)
assert.equal response.status_code, 409