Refactor acceptance tests to wait for connection before proceeding

This commit is contained in:
James Allen 2014-11-14 10:21:54 +00:00
parent fef5f6b775
commit b6f51fdafd
4 changed files with 166 additions and 109 deletions

View file

@ -6,27 +6,35 @@ RealTimeClient = require "./helpers/RealTimeClient"
MockWebServer = require "./helpers/MockWebServer"
FixturesManager = require "./helpers/FixturesManager"
async = require "async"
describe "clientTracking", ->
before (done) ->
FixturesManager.setUpProject {
privilegeLevel: "owner"
project: {
name: "Test Project"
}
}, (error, data) =>
throw error if error?
{@user_id, @project_id} = data
@clientA = RealTimeClient.connect()
@clientB = RealTimeClient.connect()
@clientA.emit "joinProject", {
project_id: @project_id
}, (error) =>
throw error if error?
async.series [
(cb) =>
FixturesManager.setUpProject {
privilegeLevel: "owner"
project: { name: "Test Project" }
}, (error, {@user_id, @project_id}) => cb()
(cb) =>
@clientA = RealTimeClient.connect()
@clientA.on "connect", cb
(cb) =>
@clientB = RealTimeClient.connect()
@clientB.on "connect", cb
(cb) =>
@clientA.emit "joinProject", {
project_id: @project_id
}, cb
(cb) =>
@clientB.emit "joinProject", {
project_id: @project_id
}, (error) =>
throw error if error?
done()
}, cb
], done
describe "when a client updates its cursor location", ->
before (done) ->

View file

@ -6,6 +6,8 @@ RealTimeClient = require "./helpers/RealTimeClient"
MockDocUpdaterServer = require "./helpers/MockDocUpdaterServer"
FixturesManager = require "./helpers/FixturesManager"
async = require "async"
describe "joinDoc", ->
before ->
@lines = ["test", "doc", "lines"]
@ -14,20 +16,27 @@ describe "joinDoc", ->
describe "when authorised readAndWrite", ->
before (done) ->
FixturesManager.setUpProject {
privilegeLevel: "readAndWrite"
}, (error, data) =>
throw error if error?
{@project_id, @user_id} = data
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (error, data) =>
throw error if error?
{@doc_id} = data
async.series [
(cb) =>
FixturesManager.setUpProject {
privilegeLevel: "readAndWrite"
}, (e, {@project_id, @user_id}) =>
cb(e)
(cb) =>
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (e, {@doc_id}) =>
cb(e)
(cb) =>
@client = RealTimeClient.connect()
@client.emit "joinProject", project_id: @project_id, (error) =>
throw error if error?
@client.emit "joinDoc", @doc_id, (error, @returnedArgs...) =>
throw error if error?
done()
@client.on "connect", cb
(cb) =>
@client.emit "joinProject", project_id: @project_id, cb
(cb) =>
@client.emit "joinDoc", @doc_id, (error, @returnedArgs...) => cb(error)
], done
it "should get the doc from the doc updater", ->
MockDocUpdaterServer.getDocument
@ -44,20 +53,27 @@ describe "joinDoc", ->
describe "when authorised readOnly", ->
before (done) ->
FixturesManager.setUpProject {
privilegeLevel: "readOnly"
}, (error, data) =>
throw error if error?
{@project_id, @user_id} = data
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (error, data) =>
throw error if error?
{@doc_id} = data
async.series [
(cb) =>
FixturesManager.setUpProject {
privilegeLevel: "readOnly"
}, (e, {@project_id, @user_id}) =>
cb(e)
(cb) =>
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (e, {@doc_id}) =>
cb(e)
(cb) =>
@client = RealTimeClient.connect()
@client.emit "joinProject", project_id: @project_id, (error) =>
throw error if error?
@client.emit "joinDoc", @doc_id, (error, @returnedArgs...) =>
throw error if error?
done()
@client.on "connect", cb
(cb) =>
@client.emit "joinProject", project_id: @project_id, cb
(cb) =>
@client.emit "joinDoc", @doc_id, (error, @returnedArgs...) => cb(error)
], done
it "should get the doc from the doc updater", ->
MockDocUpdaterServer.getDocument
@ -74,20 +90,27 @@ describe "joinDoc", ->
describe "when authorised as owner", ->
before (done) ->
FixturesManager.setUpProject {
privilegeLevel: "owner"
}, (error, data) =>
throw error if error?
{@project_id, @user_id} = data
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (error, data) =>
throw error if error?
{@doc_id} = data
async.series [
(cb) =>
FixturesManager.setUpProject {
privilegeLevel: "owner"
}, (e, {@project_id, @user_id}) =>
cb(e)
(cb) =>
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (e, {@doc_id}) =>
cb(e)
(cb) =>
@client = RealTimeClient.connect()
@client.emit "joinProject", project_id: @project_id, (error) =>
throw error if error?
@client.emit "joinDoc", @doc_id, (error, @returnedArgs...) =>
throw error if error?
done()
@client.on "connect", cb
(cb) =>
@client.emit "joinProject", project_id: @project_id, cb
(cb) =>
@client.emit "joinDoc", @doc_id, (error, @returnedArgs...) => cb(error)
], done
it "should get the doc from the doc updater", ->
MockDocUpdaterServer.getDocument
@ -109,20 +132,27 @@ describe "joinDoc", ->
describe "with a fromVersion", ->
before (done) ->
@fromVersion = 36
FixturesManager.setUpProject {
privilegeLevel: "readAndWrite"
}, (error, data) =>
throw error if error?
{@project_id, @user_id} = data
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (error, data) =>
throw error if error?
{@doc_id} = data
async.series [
(cb) =>
FixturesManager.setUpProject {
privilegeLevel: "readAndWrite"
}, (e, {@project_id, @user_id}) =>
cb(e)
(cb) =>
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (e, {@doc_id}) =>
cb(e)
(cb) =>
@client = RealTimeClient.connect()
@client.emit "joinProject", project_id: @project_id, (error) =>
throw error if error?
@client.emit "joinDoc", @doc_id, @fromVersion, (error, @returnedArgs...) =>
throw error if error?
done()
@client.on "connect", cb
(cb) =>
@client.emit "joinProject", project_id: @project_id, cb
(cb) =>
@client.emit "joinDoc", @doc_id, @fromVersion, (error, @returnedArgs...) => cb(error)
], done
it "should get the doc from the doc updater with the fromVersion", ->
MockDocUpdaterServer.getDocument

View file

@ -6,24 +6,29 @@ RealTimeClient = require "./helpers/RealTimeClient"
MockWebServer = require "./helpers/MockWebServer"
FixturesManager = require "./helpers/FixturesManager"
async = require "async"
describe "joinProject", ->
describe "when authorized", ->
before (done) ->
FixturesManager.setUpProject {
privilegeLevel: "owner"
project: {
name: "Test Project"
}
}, (error, data) =>
throw error if error?
{@user_id, @project_id} = data
@client = RealTimeClient.connect()
@client.emit "joinProject", {
project_id: @project_id
}, (error, @project, @privilegeLevel, @protocolVersion) =>
throw error if error?
done()
async.series [
(cb) =>
FixturesManager.setUpProject {
privilegeLevel: "owner"
project: {
name: "Test Project"
}
}, (e, {@project_id, @user_id}) =>
cb(e)
(cb) =>
@client = RealTimeClient.connect()
@client.on "connect", cb
(cb) =>
@client.emit "joinProject", project_id: @project_id, (error, @project, @privilegeLevel, @protocolVersion) =>
cb(error)
], done
it "should get the project from web", ->
MockWebServer.joinProject
@ -58,19 +63,24 @@ describe "joinProject", ->
describe "when not authorized", ->
before (done) ->
FixturesManager.setUpProject {
privilegeLevel: null
project: {
name: "Test Project"
}
}, (error, data) =>
throw error if error?
{@user_id, @project_id} = data
@client = RealTimeClient.connect()
@client.emit "joinProject", {
project_id: @project_id
}, (@error, @project, @privilegeLevel, @protocolVersion) =>
done()
async.series [
(cb) =>
FixturesManager.setUpProject {
privilegeLevel: null
project: {
name: "Test Project"
}
}, (e, {@project_id, @user_id}) =>
cb(e)
(cb) =>
@client = RealTimeClient.connect()
@client.on "connect", cb
(cb) =>
@client.emit "joinProject", project_id: @project_id, (@error, @project, @privilegeLevel, @protocolVersion) =>
cb()
], done
it "should return an error", ->
# We don't return specific errors

View file

@ -6,6 +6,8 @@ RealTimeClient = require "./helpers/RealTimeClient"
MockDocUpdaterServer = require "./helpers/MockDocUpdaterServer"
FixturesManager = require "./helpers/FixturesManager"
async = require "async"
describe "leaveDoc", ->
before ->
@lines = ["test", "doc", "lines"]
@ -14,20 +16,27 @@ describe "leaveDoc", ->
describe "when joined to a doc", ->
before (done) ->
FixturesManager.setUpProject {
privilegeLevel: "readAndWrite"
}, (error, data) =>
throw error if error?
{@project_id, @user_id} = data
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (error, data) =>
throw error if error?
{@doc_id} = data
async.series [
(cb) =>
FixturesManager.setUpProject {
privilegeLevel: "readAndWrite"
}, (e, {@project_id, @user_id}) =>
cb(e)
(cb) =>
FixturesManager.setUpDoc @project_id, {@lines, @version, @ops}, (e, {@doc_id}) =>
cb(e)
(cb) =>
@client = RealTimeClient.connect()
@client.emit "joinProject", project_id: @project_id, (error) =>
throw error if error?
@client.emit "joinDoc", @doc_id, (error, @returnedArgs...) =>
throw error if error?
done()
@client.on "connect", cb
(cb) =>
@client.emit "joinProject", project_id: @project_id, cb
(cb) =>
@client.emit "joinDoc", @doc_id, (error, @returnedArgs...) => cb(error)
], done
describe "then leaving the doc", ->
before (done) ->