JoinProjectTests.coffee 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. chai = require("chai")
  2. expect = chai.expect
  3. chai.should()
  4. RealTimeClient = require "./helpers/RealTimeClient"
  5. MockWebServer = require "./helpers/MockWebServer"
  6. FixturesManager = require "./helpers/FixturesManager"
  7. describe "joinProject", ->
  8. describe "when authorized", ->
  9. before (done) ->
  10. FixturesManager.setUpProject {
  11. privilegeLevel: "owner"
  12. project: {
  13. name: "Test Project"
  14. }
  15. }, (error, data) =>
  16. throw error if error?
  17. {@user_id, @project_id} = data
  18. @client = RealTimeClient.connect()
  19. @client.emit "joinProject", {
  20. project_id: @project_id
  21. }, (error, @project, @privilegeLevel, @protocolVersion) =>
  22. throw error if error?
  23. done()
  24. it "should get the project from web", ->
  25. MockWebServer.joinProject
  26. .calledWith(@project_id, @user_id)
  27. .should.equal true
  28. it "should return the project", ->
  29. @project.should.deep.equal {
  30. name: "Test Project"
  31. }
  32. it "should return the privilege level", ->
  33. @privilegeLevel.should.equal "owner"
  34. it "should return the protocolVersion", ->
  35. @protocolVersion.should.equal 2
  36. it "should have joined the project room", (done) ->
  37. RealTimeClient.getConnectedClient @client.socket.sessionid, (error, client) =>
  38. expect(@project_id in client.rooms).to.equal true
  39. done()
  40. it "should have marked the user as connected", (done) ->
  41. @client.emit "clientTracking.getConnectedUsers", (error, users) =>
  42. connected = false
  43. for user in users
  44. if user.client_id == @client.socket.sessionid and user.user_id == @user_id
  45. connected = true
  46. break
  47. expect(connected).to.equal true
  48. done()
  49. describe "when not authorized", ->
  50. before (done) ->
  51. FixturesManager.setUpProject {
  52. privilegeLevel: null
  53. project: {
  54. name: "Test Project"
  55. }
  56. }, (error, data) =>
  57. throw error if error?
  58. {@user_id, @project_id} = data
  59. @client = RealTimeClient.connect()
  60. @client.emit "joinProject", {
  61. project_id: @project_id
  62. }, (@error, @project, @privilegeLevel, @protocolVersion) =>
  63. done()
  64. it "should return an error", ->
  65. # We don't return specific errors
  66. @error.message.should.equal "Something went wrong"
  67. it "should not have joined the project room", (done) ->
  68. RealTimeClient.getConnectedClient @client.socket.sessionid, (error, client) =>
  69. expect(@project_id in client.rooms).to.equal false
  70. done()