Skip to content

Commit

Permalink
adds test to check service id
Browse files Browse the repository at this point in the history
  • Loading branch information
avilatusell committed Feb 1, 2017
1 parent 87c0de6 commit f127996
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
14 changes: 7 additions & 7 deletions test/client_test.coffee
Expand Up @@ -5,7 +5,7 @@ trans = [
{ 'app_id': 'foo', 'usage': { 'hits': 1 } },
{ 'app_id': 'foo', 'usage': { 'hits': 1000 } }
]
report_test = {transactions: trans, provider_key: '1234abcd'}
report_test = {service_id: '1234567890987', transactions: trans, provider_key: '1234abcd'}

Client = require('../src/client')

Expand Down Expand Up @@ -67,23 +67,23 @@ describe 'Basic test for the 3Scale::Client', ->
it 'should call the callback with a successful response', (done) ->
nock('https://su1.3scale.net')
.get('/transactions/authorize.xml')
.query({ app_key: 'bar', app_id: 'foo', provider_key: '1234abcd' })
.query({ service_id: '1234567890987', app_key: 'bar', app_id: 'foo', provider_key: '1234abcd' })
.reply(200, '<status><authorized>true</authorized><plan>Basic</plan></status>')

client = new Client '1234abcd'
client.authorize {app_key: 'bar', app_id: 'foo'}, (response) ->
client.authorize {service_id: '1234567890987', app_key: 'bar', app_id: 'foo'}, (response) ->
assert response.is_success()
assert.equal response.status_code, 200
done()

it 'should call the callback with a error response if app_id was wrong', (done) ->
nock('https://su1.3scale.net')
.get('/transactions/authorize.xml')
.query({ app_key: 'bar', app_id: 'ERROR', provider_key: '1234abcd' })
.query({ service_id: '1234567890987', app_key: 'bar', app_id: 'ERROR', provider_key: '1234abcd' })
.reply(403, '<error code="application_not_found">application with id="ERROR" was not found</error>')

client = new Client '1234abcd'
client.authorize {app_key: 'bar', app_id: 'ERROR'}, (response) ->
client.authorize {service_id: '1234567890987', app_key: 'bar', app_id: 'ERROR'}, (response) ->
assert.equal response.is_success(), false
assert.equal response.status_code, 403
done()
Expand Down Expand Up @@ -113,11 +113,11 @@ describe 'Basic test for the 3Scale::Client', ->
'X-3scale-User-Agent': 'plugin-node-v' + require('../package.json').version

match = nock('https://su1.3scale.net', opts)
.get('/transactions/authorize.xml?app_id=foo&provider_key=1234abcd')
.get('/transactions/authorize.xml?service_id=1234567890987&app_id=foo&provider_key=1234abcd')
.reply(200, '<status><authorized>true</authorized><plan>Basic</plan></status>')

client = new Client '1234abcd'
client.authorize { app_id: 'foo' }, (response) ->
client.authorize { service_id: '1234567890987', app_id: 'foo' }, (response) ->
assert match.isDone()
done()

Expand Down
7 changes: 4 additions & 3 deletions test/integration_test.coffee
Expand Up @@ -5,27 +5,28 @@ assert = require 'assert'
provider_key = process.env.TEST_3SCALE_PROVIDER_KEY
application_key = process.env.TEST_3SCALE_APP_KEY
application_id = process.env.TEST_3SCALE_APP_ID
service_id = process.env.TEST_3SCALE_SERVICE_ID

trans = [
{ 'app_id': application_id, 'usage': { 'hits': 1 } },
{ 'app_id': application_id, 'usage': { 'hits': 1000 } }
]
report_test = {transactions: trans, provider_key: provider_key}
report_test = {service_id: service_id, transactions: trans, provider_key: provider_key}

Client = require('../src/client')

describe 'Integration tests for the 3Scale::Client', ->
describe 'The authorize method', ->
it 'should call the callback with a successful response', (done) ->
client = new Client provider_key
client.authorize {app_key: application_key, app_id: application_id}, (response) ->
client.authorize {service_id: service_id, app_key: application_key, app_id: application_id}, (response) ->
assert response.is_success()
assert.equal response.status_code, 200
done()

it 'should call the callback with a error response if app_id was wrong', (done) ->
client = new Client provider_key
client.authorize {app_key: application_key, app_id: 'ERROR'}, (response) ->
client.authorize {service_id: service_id, app_key: application_key, app_id: 'ERROR'}, (response) ->
assert.equal response.is_success(), false
assert.equal response.status_code, 404
done()
Expand Down

0 comments on commit f127996

Please sign in to comment.