From b39fd11da7a68535d76a064554e5eb6bbe848ed4 Mon Sep 17 00:00:00 2001 From: seebees Date: Fri, 27 Jan 2012 16:32:06 -0800 Subject: [PATCH] MORE tests! --- tests/test_ironmq.options.js | 37 ++++++++++++++++ tests/test_projects.js | 10 +---- tests/test_queue.get.1.js | 45 +++++++++++++++++++ tests/test_queue.get.js | 1 - tests/test_queue.info.js | 12 +++-- tests/test_queue.put.array with options.js | 51 ++++++++++++++++++++++ tests/test_queue.put.array.js | 50 +++++++++++++++++++++ tests/test_queue.put.js | 1 - tests/test_queue.put.with options.js | 2 +- 9 files changed, 194 insertions(+), 15 deletions(-) create mode 100644 tests/test_ironmq.options.js create mode 100644 tests/test_queue.get.1.js create mode 100644 tests/test_queue.put.array with options.js create mode 100644 tests/test_queue.put.array.js diff --git a/tests/test_ironmq.options.js b/tests/test_ironmq.options.js new file mode 100644 index 0000000..8667ddf --- /dev/null +++ b/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() + }) + +}) + diff --git a/tests/test_projects.js b/tests/test_projects.js index 68d8b69..1fe14f8 100644 --- a/tests/test_projects.js +++ b/tests/test_projects.js @@ -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) @@ -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' @@ -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') diff --git a/tests/test_queue.get.1.js b/tests/test_queue.get.1.js new file mode 100644 index 0000000..1255222 --- /dev/null +++ b/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() + }) +}) + diff --git a/tests/test_queue.get.js b/tests/test_queue.get.js index e32c5e3..78d406e 100644 --- a/tests/test_queue.get.js +++ b/tests/test_queue.get.js @@ -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 diff --git a/tests/test_queue.info.js b/tests/test_queue.info.js index f7beb33..9f724a8 100644 --- a/tests/test_queue.info.js +++ b/tests/test_queue.info.js @@ -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') }) diff --git a/tests/test_queue.put.array with options.js b/tests/test_queue.put.array with options.js new file mode 100644 index 0000000..8130029 --- /dev/null +++ b/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() + }) + +}) + diff --git a/tests/test_queue.put.array.js b/tests/test_queue.put.array.js new file mode 100644 index 0000000..54d3997 --- /dev/null +++ b/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() + }) + +}) + diff --git a/tests/test_queue.put.js b/tests/test_queue.put.js index 2cbf163..93af261 100644 --- a/tests/test_queue.put.js +++ b/tests/test_queue.put.js @@ -40,6 +40,5 @@ test('queue.put(str, {}, func)', function(t) { //TODO -// [msgs], cb // msg, not object, cb -> throw error diff --git a/tests/test_queue.put.with options.js b/tests/test_queue.put.with options.js index e99cc90..4cbc382 100644 --- a/tests/test_queue.put.with options.js +++ b/tests/test_queue.put.with options.js @@ -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.'})