|
1 | 1 | var expect = require('chai').expect; |
2 | 2 | var Backend = require('../../lib/backend'); |
3 | 3 | var Connection = require('../../lib/client/connection'); |
| 4 | +var LegacyConnection = require('sharedb-legacy/lib/client').Connection; |
| 5 | +var StreamSocket = require('../../lib/stream-socket'); |
4 | 6 |
|
5 | 7 | describe('client connection', function() { |
6 | 8 | beforeEach(function() { |
@@ -217,6 +219,31 @@ describe('client connection', function() { |
217 | 219 | }); |
218 | 220 | }); |
219 | 221 |
|
| 222 | + it('still connects to legacy clients, whose ID changes on reconnection', function(done) { |
| 223 | + var currentBackend = this.backend; |
| 224 | + var socket = new StreamSocket(); |
| 225 | + var legacyClient = new LegacyConnection(socket); |
| 226 | + currentBackend.connect(legacyClient); |
| 227 | + |
| 228 | + var doc = legacyClient.get('test', '123'); |
| 229 | + doc.create({foo: 'bar'}, function(error) { |
| 230 | + if (error) return done(error); |
| 231 | + var initialId = legacyClient.id; |
| 232 | + expect(initialId).to.equal(legacyClient.agent.clientId); |
| 233 | + expect(legacyClient.agent.src).to.be.null; |
| 234 | + legacyClient.close(); |
| 235 | + currentBackend.connect(legacyClient); |
| 236 | + doc.submitOp({p: ['baz'], oi: 'qux'}, function(error) { |
| 237 | + if (error) return done(error); |
| 238 | + var newId = legacyClient.id; |
| 239 | + expect(newId).not.to.equal(initialId); |
| 240 | + expect(newId).to.equal(legacyClient.agent.clientId); |
| 241 | + expect(legacyClient.agent.src).to.be.null; |
| 242 | + done(); |
| 243 | + }); |
| 244 | + }); |
| 245 | + }); |
| 246 | + |
220 | 247 | it('errors when submitting an op with a very large seq', function(done) { |
221 | 248 | this.backend.connect(null, null, function(connection) { |
222 | 249 | var doc = connection.get('test', '123'); |
|
0 commit comments