|
| 1 | +import { expect } from "chai"; |
| 2 | +import { ConnectionTarget } from "../../src/database/api/test_access"; |
| 3 | +import { TEST_PROJECT } from "./helpers/util"; |
| 4 | +import { Connection } from "../../src/database/realtime/Connection"; |
| 5 | + |
| 6 | +describe('Connection', () => { |
| 7 | + function testRepoInfo(url) { |
| 8 | + const regex = /https:\/\/(.*).firebaseio.com/; |
| 9 | + const match = url.match(regex); |
| 10 | + if (!match) throw new Error('Couldnt get Namespace from passed URL'); |
| 11 | + const [,ns] = match; |
| 12 | + return new ConnectionTarget(`${ns}.firebaseio.com`, false, ns, false); |
| 13 | + } |
| 14 | + it('return the session id', function(done) { |
| 15 | + new Connection('1', |
| 16 | + testRepoInfo(TEST_PROJECT.databaseURL), |
| 17 | + message => {}, |
| 18 | + (timestamp, sessionId) => { |
| 19 | + expect(sessionId).not.to.be.null; |
| 20 | + expect(sessionId).not.to.equal(''); |
| 21 | + done(); |
| 22 | + }, |
| 23 | + () => {}, |
| 24 | + reason => {}); |
| 25 | + }); |
| 26 | + |
| 27 | + // TODO(koss) - Flakey Test. When Dev Tools is closed on my Mac, this test |
| 28 | + // fails about 20% of the time (open - it never fails). In the failing |
| 29 | + // case a long-poll is opened first. |
| 30 | + // https://app.asana.com/0/58926111402292/101921715724749 |
| 31 | + it('disconnect old session on new connection', function(done) { |
| 32 | + const info = testRepoInfo(TEST_PROJECT.databaseURL); |
| 33 | + new Connection('1', info, |
| 34 | + message => {}, |
| 35 | + (timestamp, sessionId) => { |
| 36 | + new Connection('2', info, |
| 37 | + message => {}, |
| 38 | + (timestamp, sessionId) => {}, |
| 39 | + () => {}, |
| 40 | + reason => {}, |
| 41 | + sessionId); |
| 42 | + }, |
| 43 | + () => { |
| 44 | + done(); // first connection was disconnected |
| 45 | + }, |
| 46 | + reason => {}); |
| 47 | + }); |
| 48 | +}); |
0 commit comments