Added tests, moved some functions into module.exports

This commit is contained in:
Michael Schmatz 2014-01-31 11:09:15 -08:00
parent 4d1c772719
commit 563c442e81
2 changed files with 28 additions and 13 deletions

View file

@ -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

View file

@ -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()
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()