mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Added tests, moved some functions into module.exports
This commit is contained in:
parent
4d1c772719
commit
563c442e81
2 changed files with 28 additions and 13 deletions
|
@ -8,13 +8,13 @@ db = require './db'
|
||||||
mongoose = require 'mongoose'
|
mongoose = require 'mongoose'
|
||||||
events = require 'events'
|
events = require 'events'
|
||||||
|
|
||||||
queueClient = unefined
|
queueClient = undefined
|
||||||
module.exports.scoringTaskQueue = undefined
|
module.exports.scoringTaskQueue = undefined
|
||||||
module.exports.sendwithusQueue = undefined
|
module.exports.sendwithusQueue = undefined
|
||||||
|
###
|
||||||
#module.exports.setupRoutes = (app) ->
|
module.exports.setupRoutes = (app) ->
|
||||||
# app.get '/multiplayer/'
|
app.get '/multiplayer/'
|
||||||
###queueClient.registerQueue "simulationQueue", {}, (err,data) ->
|
queueClient.registerQueue "simulationQueue", {}, (err,data) ->
|
||||||
simulationQueue = data
|
simulationQueue = data
|
||||||
simulationQueue.subscribe 'message', (err, data) ->
|
simulationQueue.subscribe 'message', (err, data) ->
|
||||||
if data.Messages?
|
if data.Messages?
|
||||||
|
@ -24,7 +24,7 @@ module.exports.sendwithusQueue = undefined
|
||||||
###
|
###
|
||||||
|
|
||||||
module.exports.initializeScoringTaskQueue = (cb) ->
|
module.exports.initializeScoringTaskQueue = (cb) ->
|
||||||
queueClient = generateQueueClient() unless queueClient?
|
queueClient = module.exports.generateQueueClient() unless queueClient?
|
||||||
queueClient.registerQueue "scoring", {}, (err,data) ->
|
queueClient.registerQueue "scoring", {}, (err,data) ->
|
||||||
if err?
|
if err?
|
||||||
winston.error "There was an error registering the scoring queue."
|
winston.error "There was an error registering the scoring queue."
|
||||||
|
@ -34,7 +34,7 @@ module.exports.initializeScoringTaskQueue = (cb) ->
|
||||||
|
|
||||||
|
|
||||||
module.exports.initializeSendwithusQueue = (cb) ->
|
module.exports.initializeSendwithusQueue = (cb) ->
|
||||||
queueClient = generateQueueClient() unless queueClient?
|
queueClient = module.exports.generateQueueClient() unless queueClient?
|
||||||
queueClient.registerQueue "sendwithus", {}, (err,data) ->
|
queueClient.registerQueue "sendwithus", {}, (err,data) ->
|
||||||
if err?
|
if err?
|
||||||
errorString = "There was an error registering the sendwithus queue."
|
errorString = "There was an error registering the sendwithus queue."
|
||||||
|
@ -47,7 +47,7 @@ module.exports.initializeSendwithusQueue = (cb) ->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
generateQueueClient = ->
|
module.exports.generateQueueClient = ->
|
||||||
if config.isProduction
|
if config.isProduction
|
||||||
queueClient = new SQSQueueClient()
|
queueClient = new SQSQueueClient()
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
queues = require './queue'
|
queues = require './queue'
|
||||||
config = require '../server_config.js'
|
config = require '../server_config.js'
|
||||||
|
winston = require 'winston'
|
||||||
describe 'Queue', ->
|
describe 'Queue', ->
|
||||||
describe 'construction interface', ->
|
describe 'construction interface', ->
|
||||||
it 'should construct a MongoQueueClient if not in production', ->
|
it 'should construct a MongoQueueClient if not in production', ->
|
||||||
|
@ -17,14 +18,28 @@ describe 'Queue', ->
|
||||||
config.isProduction = false
|
config.isProduction = false
|
||||||
mongoQueueClient = queues.generateQueueClient()
|
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) ->
|
mongoQueueClient.registerQueue "TestQueue", {}, (err, data) ->
|
||||||
expect(data.constructor.name).toEqual 'MongoQueue'
|
expect(data.constructor.name).toEqual 'MongoQueue'
|
||||||
describe 'sendMessage', ->
|
done()
|
||||||
|
|
||||||
|
describe 'messages', ->
|
||||||
mongoQueueClient = queues.generateQueueClient()
|
mongoQueueClient = queues.generateQueueClient()
|
||||||
testQueue = null
|
testQueue = null
|
||||||
it 'should send and retrieve a message', (done) ->
|
|
||||||
|
messageIdToDelete = null
|
||||||
|
it 'should send a message', (done) ->
|
||||||
mongoQueueClient.registerQueue "TestQueue", {}, (err, data) ->
|
mongoQueueClient.registerQueue "TestQueue", {}, (err, data) ->
|
||||||
testQueue = data
|
testQueue = data
|
||||||
testQueue.sendMessage {"Body":"WOOOO"} ,0, (err2, data2) ->
|
testQueue.sendMessage {"Body":"This is a test message"} ,0, (err2, data2) ->
|
||||||
done()
|
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()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue