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

View file

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

View file

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

View file

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