Skip to content

Commit 98e6946

Browse files
committed
Add a test for the login flow when there is a teamserver
- just to check it keeps working.
1 parent 5ff59b0 commit 98e6946

2 files changed

Lines changed: 68 additions & 4 deletions

File tree

‎test/app-tests/loading.js‎

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,17 @@ describe('loading:', function () {
135135

136136
const MatrixChat = sdk.getComponent('structures.MatrixChat');
137137
const fragParts = parseQsFromFragment(windowLocation);
138+
139+
const config = Object.assign({
140+
default_hs_url: DEFAULT_HS_URL,
141+
default_is_url: DEFAULT_IS_URL,
142+
}, opts.config || {});
143+
138144
var params = parseQs(windowLocation);
139145
matrixChat = ReactDOM.render(
140146
<MatrixChat
141147
onNewScreen={onNewScreen}
142-
config={{
143-
default_hs_url: DEFAULT_HS_URL,
144-
default_is_url: DEFAULT_IS_URL,
145-
}}
148+
config={config}
146149
realQueryParams={params}
147150
startingFragmentQueryParams={fragParts.params}
148151
enableGuest={true}
@@ -343,6 +346,40 @@ describe('loading:', function () {
343346
}).done(done, done);
344347
});
345348

349+
it("registers correctly with a Riot Team Server", function() {
350+
sdk.setFetch(httpBackend.fetchFn); // XXX: ought to restore this!
351+
352+
httpBackend.when('GET', '/pushrules').respond(200, {});
353+
httpBackend.when('POST', '/filter').respond(200, { filter_id: 'fid' });
354+
355+
loadApp({
356+
config: {
357+
teamServerConfig: {
358+
teamServerURL: 'http://my_team_server',
359+
},
360+
},
361+
});
362+
363+
return q.delay(1).then(() => {
364+
// we expect a loading spinner while we log into the RTS
365+
assertAtLoadingSpinner(matrixChat);
366+
367+
httpBackend.when('GET', 'my_team_server/login').respond(200, {
368+
team_token: 'nom',
369+
});
370+
return httpBackend.flush();
371+
}).then(() => {
372+
return awaitSyncingSpinner(matrixChat)
373+
}).then(() => {
374+
// we got a sync spinner - let the sync complete
375+
return expectAndAwaitSync();
376+
}).then(() => {
377+
// once the sync completes, we should have a home page
378+
ReactTestUtils.findRenderedComponentWithType(
379+
matrixChat, sdk.getComponent('structures.HomePage'));
380+
});
381+
});
382+
346383
describe('/#/login link:', function() {
347384
beforeEach(function() {
348385
loadApp({

‎test/mock-request.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,33 @@ function HttpBackend() {
3030
abort: abort,
3131
};
3232
};
33+
34+
// very simplistic mapping from the whatwg fetch interface onto the request
35+
// interface, so we can use the same mock backend for both.
36+
this.fetchFn = function(input, init) {
37+
init = init || {};
38+
const requestOpts = {
39+
uri: input,
40+
method: init.method || 'GET',
41+
body: init.body,
42+
};
43+
44+
return new Promise((resolve, reject) => {
45+
function callback(err, response, body) {
46+
if (err) {
47+
reject(err);
48+
}
49+
resolve({
50+
ok: response.statusCode >= 200 && response.statusCode < 300,
51+
json: () => body,
52+
});
53+
};
54+
55+
const req = new Request(requestOpts, callback);
56+
console.log(`HTTP backend received request: ${req}`);
57+
self.requests.push(req);
58+
});
59+
};
3360
}
3461
HttpBackend.prototype = {
3562
/**

0 commit comments

Comments
 (0)