From 563c442e81ec10d17a5b7a9caf1fa703616f0828 Mon Sep 17 00:00:00 2001 From: Michael Schmatz Date: Fri, 31 Jan 2014 11:09:15 -0800 Subject: [PATCH] Added tests, moved some functions into module.exports --- server/queue.coffee | 16 ++++++++-------- server/queue.spec.coffee | 25 ++++++++++++++++++++----- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/server/queue.coffee b/server/queue.coffee index c904f9914..da63dc55b 100644 --- a/server/queue.coffee +++ b/server/queue.coffee @@ -8,13 +8,13 @@ db = require './db' mongoose = require 'mongoose' events = require 'events' -queueClient = unefined +queueClient = undefined module.exports.scoringTaskQueue = undefined module.exports.sendwithusQueue = undefined - -#module.exports.setupRoutes = (app) -> -# app.get '/multiplayer/' - ###queueClient.registerQueue "simulationQueue", {}, (err,data) -> +### +module.exports.setupRoutes = (app) -> + app.get '/multiplayer/' + queueClient.registerQueue "simulationQueue", {}, (err,data) -> simulationQueue = data simulationQueue.subscribe 'message', (err, data) -> if data.Messages? @@ -24,7 +24,7 @@ module.exports.sendwithusQueue = undefined ### module.exports.initializeScoringTaskQueue = (cb) -> - queueClient = generateQueueClient() unless queueClient? + queueClient = module.exports.generateQueueClient() unless queueClient? queueClient.registerQueue "scoring", {}, (err,data) -> if err? winston.error "There was an error registering the scoring queue." @@ -34,7 +34,7 @@ module.exports.initializeScoringTaskQueue = (cb) -> module.exports.initializeSendwithusQueue = (cb) -> - queueClient = generateQueueClient() unless queueClient? + queueClient = module.exports.generateQueueClient() unless queueClient? queueClient.registerQueue "sendwithus", {}, (err,data) -> if err? errorString = "There was an error registering the sendwithus queue." @@ -47,7 +47,7 @@ module.exports.initializeSendwithusQueue = (cb) -> -generateQueueClient = -> +module.exports.generateQueueClient = -> if config.isProduction queueClient = new SQSQueueClient() else diff --git a/server/queue.spec.coffee b/server/queue.spec.coffee index ca1ca76de..052fb3c79 100644 --- a/server/queue.spec.coffee +++ b/server/queue.spec.coffee @@ -1,5 +1,6 @@ queues = require './queue' config = require '../server_config.js' +winston = require 'winston' describe 'Queue', -> describe 'construction interface', -> it 'should construct a MongoQueueClient if not in production', -> @@ -17,14 +18,28 @@ describe 'Queue', -> config.isProduction = false mongoQueueClient = queues.generateQueueClient() - it 'should generate the correct type of queue', -> + it 'should generate the correct type of queue', (done) -> mongoQueueClient.registerQueue "TestQueue", {}, (err, data) -> expect(data.constructor.name).toEqual 'MongoQueue' - describe 'sendMessage', -> + done() + + describe 'messages', -> mongoQueueClient = queues.generateQueueClient() testQueue = null - it 'should send and retrieve a message', (done) -> + + messageIdToDelete = null + it 'should send a message', (done) -> mongoQueueClient.registerQueue "TestQueue", {}, (err, data) -> testQueue = data - testQueue.sendMessage {"Body":"WOOOO"} ,0, (err2, data2) -> - done() \ No newline at end of file + testQueue.sendMessage {"Body":"This is a test message"} ,0, (err2, data2) -> + done() + it 'should receieve a message', (done) -> + testQueue.receieveMessage (err,data) -> + winston.info "Data body is #{data.Body}" + expect(data.Body).toBe "This is a test message" + messageIdToDelete = data._id + done() + it 'should delete a message', (done) -> + expect(true).toBeTruthy() + done() +