Skip to content
Browse files

Added test cases for oauth_authorize, authorize_with_user_key, authre…

…p, authrep_with_user_key methods
  • Loading branch information...
1 parent 57afc82 commit 85307f8a9abb82fc006ab6aec48e7b3d52246696 @schaitanya schaitanya committed Sep 27, 2012
Showing with 77 additions and 8 deletions.
  1. +77 −8 test/client_test.coffee
View
85 test/client_test.coffee
@@ -5,6 +5,7 @@
provider_key = '05273bcb282d1d4faafffeb01e224db0'
application_key = '3e05c797ef193fee452b1ddf19defa74'
application_id = '75165984'
+user_key = 'abcd'
trans = [
{ "app_id": application_id, "usage": {"hits": 1}},
@@ -22,33 +23,71 @@ Client = require('../src/client')
vows
.describe("Basic test for the 3Scale::Client")
.addBatch
- 'A client Should':
+ 'A client ':
topic: -> Client
- 'to be throw a exception if init without provider_key': (Client) ->
+ 'should throw an exception if init without provider_key': (Client) ->
assert.throws(`function(){ new Client()}`, "missing provider_key")
return
- 'have a default host': (Client) ->
+ 'should have an default host': (Client) ->
client = new Client(123)
assert.equal client.host, "su1.3scale.net"
return
- 'to be can change the default host': (Client) ->
+ 'can change the default host': (Client) ->
client = new Client(123, 'example.com')
assert.equal client.host, "example.com"
return
- 'to be have a authorize method': (Client) ->
+ 'should have an authorize method': (Client) ->
client = new Client(provider_key)
assert.isFunction client.authorize
return
- 'to be throw a exception if authorize method is called without :app_id': (Client) ->
+ 'should throw an exception if authorize method is called without :app_id': (Client) ->
client = new Client(provider_key)
- assert.throws client.authorize({}, ()->), "missing app_id"
+ assert.throws (() -> client.authorize({}, () ->)), "missing app_id"
return
- 'In the authorize method should':
+ 'should have an oauth_authorize method': (Client) ->
+ client = new Client(provider_key)
+ assert.isFunction client.oauth_authorize
+ return
+
+ 'should throw an exception if oauth_authorize method is called without :app_id': (Client) ->
+ client = new Client(provider_key)
+ assert.throws (() -> client.oauth_authorize({}, () ->)), "missing app_id"
+ return
+
+ 'should have an authorize_with_user_key method': (Client) ->
+ client = new Client(provider_key)
+ assert.isFunction client.authorize_with_user_key
+ return
+
+ 'should throw an exception if authorize_with_user_key is called without :user_key': (Client) ->
+ client = new Client(provider_key)
+ assert.throws (() -> client.authorize_with_user_key({}, () ->)), "missing user_key"
+ return
+
+ 'should have an authrep method': (Client) ->
+ client = new Client(provider_key)
+ assert.isFunction client.authrep
+ return
+
+ 'should throw an exception if authrep called without :app_id': (Client) ->
+ client = new Client(provider_key)
+ assert.throws (() -> client.authrep({}, () ->)), "missing app_id"
+ return
+
+ 'should have an authrep_with_user_key method': (Client) ->
+ client = new Client(provider_key)
+ assert.isFunction client.authrep_with_user_key
+
+ 'ahould throw an exception if authrep_with_user_key is called without :user_key': (Client) ->
+ client = new Client(provider_key)
+ assert.throws (() -> client.authrep_with_user_key({}, ()->)), 'missing user_key'
+
+ 'The authorize method should':
topic: ->
promise = new events.EventEmitter
client = new Client provider_key
@@ -63,6 +102,36 @@ vows
'call the callback with the AuthorizeResponse': (response) ->
assert.isTrue response.is_success()
+ 'The oauth_authorize method should':
+ topic: ->
+ promise = new events.EventEmitter
+ client = new Client provider_key
+ client.oauth_authorize {app_id: application_id}, (response) ->
+ if response.is_success
+ promise.emit 'success', response
+ else
+ promise.else 'error', response
+
+ promise
+
+ 'call the callback with the AuthorizeResponse': (response) ->
+ assert.isTrue response.is_success()
+
+ 'The authorize_with_user_key method should':
+ topic: ->
+ promise = new events.EventEmitter
+ client = new Client provider_key
+ client.authorize_with_user_key {user_key: user_key}, (response) ->
+ if response.is_success
+ promise.emit 'success', response
+ else
+ promise.else 'error', response
+
+ promise
+
+ 'call the callback with the AuthorizeResponse': (response) ->
+ assert.isTrue response.is_success()
+
'The Event Emitter':
topic: ->
promise = new events.EventEmitter

0 comments on commit 85307f8

Please sign in to comment.
Something went wrong with that request. Please try again.