Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 1f48b4c

Browse files
authored
Merge pull request #1098 from matrix-org/rav/test_rts_login
Groundwork for tests including a teamserver login
2 parents 13efd62 + 65f351f commit 1f48b4c

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

.eslintignore.errorfiles

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ src/Roles.js
146146
src/RoomListSorter.js
147147
src/RoomNotifs.js
148148
src/Rooms.js
149-
src/RtsClient.js
150149
src/ScalarAuthClient.js
151150
src/ScalarMessaging.js
152151
src/SdkConfig.js

src/Lifecycle.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,11 @@ function _handleRestoreFailure(e) {
265265

266266
let rtsClient = null;
267267
export function initRtsClient(url) {
268-
rtsClient = new RtsClient(url);
268+
if (url) {
269+
rtsClient = new RtsClient(url);
270+
} else {
271+
rtsClient = null;
272+
}
269273
}
270274

271275
/**

src/RtsClient.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'whatwg-fetch';
22

3+
let fetchFunction = fetch;
4+
35
function checkStatus(response) {
46
if (!response.ok) {
57
return response.text().then((text) => {
@@ -31,7 +33,7 @@ const request = (url, opts) => {
3133
opts.body = JSON.stringify(opts.body);
3234
opts.headers['Content-Type'] = 'application/json';
3335
}
34-
return fetch(url, opts)
36+
return fetchFunction(url, opts)
3537
.then(checkStatus)
3638
.then(parseJson);
3739
};
@@ -64,7 +66,7 @@ export default class RtsClient {
6466
client_secret: clientSecret,
6567
},
6668
method: 'POST',
67-
}
69+
},
6870
);
6971
}
7072

@@ -74,7 +76,7 @@ export default class RtsClient {
7476
qs: {
7577
team_token: teamToken,
7678
},
77-
}
79+
},
7880
);
7981
}
8082

@@ -91,7 +93,12 @@ export default class RtsClient {
9193
qs: {
9294
user_id: userId,
9395
},
94-
}
96+
},
9597
);
9698
}
99+
100+
// allow fetch to be replaced, for testing.
101+
static setFetch(fn) {
102+
fetchFunction = fn;
103+
}
97104
}

src/components/structures/MatrixChat.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,8 @@ module.exports = React.createClass({
263263
window.addEventListener('resize', this.handleResize);
264264
this.handleResize();
265265

266-
if (this.props.config.teamServerConfig &&
267-
this.props.config.teamServerConfig.teamServerURL
268-
) {
269-
Lifecycle.initRtsClient(this.props.config.teamServerConfig.teamServerURL);
270-
}
266+
const teamServerConfig = this.props.config.teamServerConfig || {};
267+
Lifecycle.initRtsClient(teamServerConfig.teamServerURL);
271268

272269
// if the user has followed a login or register link, don't reanimate
273270
// the old creds, but rather go straight to the relevant page

src/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ limitations under the License.
1515
*/
1616

1717
import Skinner from './Skinner';
18+
import RtsClient from './RtsClient';
1819

1920
module.exports.loadSkin = function(skinObject) {
2021
Skinner.load(skinObject);
@@ -27,3 +28,7 @@ module.exports.resetSkin = function() {
2728
module.exports.getComponent = function(componentName) {
2829
return Skinner.getComponent(componentName);
2930
};
31+
32+
module.exports.setFetch = function(fetchFunction) {
33+
RtsClient.setFetch(fetchFunction);
34+
};

0 commit comments

Comments
 (0)