Navigation Menu

Skip to content

Commit

Permalink
MORE tests!
Browse files Browse the repository at this point in the history
  • Loading branch information
seebees committed Jan 28, 2012
1 parent b437d19 commit b39fd11
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 15 deletions.
37 changes: 37 additions & 0 deletions tests/test_ironmq.options.js
@@ -0,0 +1,37 @@
var ironmq = require('../')

var nock = require('nock')
var test = require('tap').test

var con = require('./constants.js')
var token = con.token
var proj_id = con.project
var q_name = con.q_name

if (con.proxy) {
var req = nock('http://host.name')
.matchHeader('authorization','OAuth ' + token)
.matchHeader('content-type','application/json')
.matchHeader('user-agent','IronMQ Node Client')
.get(
'/3/projects/' + proj_id + '/queues')
.reply(200
,[{ Timestamper : {updated_at: 1327083607064000000 }
, project_id : 'test_worked'
, name : 'test_worked'}])
}


test('ironmq.options', function(t) {
ironmq(token
,{host : 'host.name'
, protocol : 'http'
, ver : 3})(proj_id)
.list(function(err, obj) {

t.equal(obj[0].name(), 'test_worked')
t.end()
})

})

10 changes: 2 additions & 8 deletions tests/test_projects.js
Expand Up @@ -20,12 +20,6 @@ test('client', function(t) {

t.end()
})
//TODO how do I test options? list?
//
// 'token'
// no token gives error
// 'token' {protocol:, host:, port:, ver:}


test('projects', function(t) {
var projects = ironmq(token)
Expand All @@ -49,7 +43,8 @@ if (con.proxy) {
'/2/projects')
.reply(200
,{ projects: [{ id: '4e25e1d35c0dd2780100048d'
, timestamps: [Object]
, timestamps: { "created_at":1308800463000000000
, "updated_at":1311105491000000000}
, user_id: '4e25e1cf5c0dd2780100022a'
, name: 'test'
, type: 'free'
Expand All @@ -59,7 +54,6 @@ if (con.proxy) {

test('projects.list', function(t) {
ironmq(token).list(function(err, obj) {

t.equal(obj.length, 1)
t.equal(obj[0].id(), proj_id)
t.ok(typeof obj[0].list === 'function')
Expand Down
45 changes: 45 additions & 0 deletions tests/test_queue.get.1.js
@@ -0,0 +1,45 @@
var ironmq = require('../')

var nock = require('nock')
var test = require('tap').test

var con = require('./constants.js')
var token = con.token
var project = con.project
var q_name = con.queue

if (con.proxy) {
var req = nock('https://mq-aws-us-east-1.iron.io')
.matchHeader('authorization','OAuth ' + token)
.matchHeader('content-type','application/json')
.matchHeader('user-agent','IronMQ Node Client')
.get(
'/1/projects/' + project + '/queues/' + q_name
+ '/messages?n=1')
.reply(200
, { body: 'this is a test'
, id: '4f1752cd52549a7435005a6b'
, messages: [{ id: '4f1752cd52549a7435005a6b'
, timeout: 60
, body: 'this is a test'}]
, timeout: 60 })
}

test('queue.get', function(t) {

var queue = ironmq(token)
.projects(project)
.queues(q_name)

queue.get(1
, function(err, obj) {
t.deepEqual(obj
, [{id: '4f1752cd52549a7435005a6b'
, timeout: 60
, body: 'this is a test'
, del: obj[0].del}])

t.end()
})
})

1 change: 0 additions & 1 deletion tests/test_queue.get.js
Expand Up @@ -44,7 +44,6 @@ test('queue.get', function(t) {
})

//TODO
// 1, cb
// '1', cb (will not work, real message id's parseInt into a number :(
// msg_id not exist, cb //{ msg: 'Method not allowed', status_code: 405 }
// # more then in queue, cb
Expand Down
12 changes: 8 additions & 4 deletions tests/test_queue.info.js
Expand Up @@ -19,17 +19,21 @@ if (con.proxy) {
}

test('queue.info', function(t) {
ironmq(token)(project)(q_name).info(function(err, obj) {
var queue = ironmq(token)(project)(q_name).info(function(err, obj) {

t.ok(obj.name(), q_name)
t.ok(obj.size, 36)
t.ok(obj.time, new Date())
t.equal(obj.name(), q_name)
t.equal(obj.size, 36)
t.ok(typeof obj.get === 'function')
t.ok(typeof obj.put === 'function')
t.ok(typeof obj.del === 'function')
t.ok(typeof obj.info === 'function')

// I update the same variable. So everyone get's the new size!
t.equal(queue.size, 36)
t.end()
})

// the queue returned should not yet have a size
t.type(queue.size, 'undefined')
})

51 changes: 51 additions & 0 deletions tests/test_queue.put.array with options.js
@@ -0,0 +1,51 @@
var ironmq = require('../')

var nock = require('nock')
var test = require('tap').test

var con = require('./constants.js')
var token = con.token
var project = con.project
var q_name = con.queue

if (con.proxy) {
var req = nock('https://mq-aws-us-east-1.iron.io')
.matchHeader('authorization','OAuth ' + token)
.matchHeader('content-type','application/json')
.matchHeader('user-agent','IronMQ Node Client')
.post(
'/1/projects/' + project + '/queues/' + q_name + '/messages'
, {"messages" : [ { some: 'option', body: 'this is a test' }
, { some: 'option', body: 'another test' }
, { some: 'option', body: 'one last test' }]})
.reply(200
, { ids: ['4f231f0fef05207255008f4a'
, '4f231f0fef05207255008f4b'
, '4f231f0fef05207255008f4c']
, msg: 'Messages put on queue.' })
}


test('queue.put([], func)', function(t) {

var client = ironmq(token)
var queue = client
.projects(project)
.queues(q_name)

queue.put([
'this is a test'
, 'another test'
, 'one last test']
, {some: 'option'}
, function(err, obj) {
t.deepEqual(obj
, { ids: ['4f231f0fef05207255008f4a'
, '4f231f0fef05207255008f4b'
, '4f231f0fef05207255008f4c']
, msg: 'Messages put on queue.'})
t.end()
})

})

50 changes: 50 additions & 0 deletions tests/test_queue.put.array.js
@@ -0,0 +1,50 @@
var ironmq = require('../')

var nock = require('nock')
var test = require('tap').test

var con = require('./constants.js')
var token = con.token
var project = con.project
var q_name = con.queue

if (con.proxy) {
var req = nock('https://mq-aws-us-east-1.iron.io')
.matchHeader('authorization','OAuth ' + token)
.matchHeader('content-type','application/json')
.matchHeader('user-agent','IronMQ Node Client')
.post(
'/1/projects/' + project + '/queues/' + q_name + '/messages'
, {"messages" : [ { body: 'this is a test' }
, { body: 'another test' }
, { body: 'one last test' }]})
.reply(200
, { ids: ['4f231f0fef05207255008f4a'
, '4f231f0fef05207255008f4b'
, '4f231f0fef05207255008f4c']
, msg: 'Messages put on queue.' })
}


test('queue.put([], func)', function(t) {

var client = ironmq(token)
var queue = client
.projects(project)
.queues(q_name)

queue.put([
'this is a test'
, 'another test'
, 'one last test']
, function(err, obj) {
t.deepEqual(obj
, { ids: ['4f231f0fef05207255008f4a'
, '4f231f0fef05207255008f4b'
, '4f231f0fef05207255008f4c']
, msg: 'Messages put on queue.'})
t.end()
})

})

1 change: 0 additions & 1 deletion tests/test_queue.put.js
Expand Up @@ -40,6 +40,5 @@ test('queue.put(str, {}, func)', function(t) {


//TODO
// [msgs], cb
// msg, not object, cb -> throw error

2 changes: 1 addition & 1 deletion tests/test_queue.put.with options.js
Expand Up @@ -26,7 +26,7 @@ test('queue.put(str, {some:option}, func)', function(t) {

var queue = ironmq(token)(project)(q_name)

queue.put('this is a test', {some:'option'}, function(err, obj) {
queue.put('this is a test', {some: 'option'}, function(err, obj) {
t.deepEqual(obj,
{ ids: ['4f176348ef05202f74005bc6']
, msg: 'Messages put on queue.'})
Expand Down

0 comments on commit b39fd11

Please sign in to comment.