Test typescriptification - Terms/ScalarAuthClient (#8480)
* test/Terms-test.js -> test/Terms-test.tsx Signed-off-by: Kerry Archibald <kerrya@element.io> * fix ts issues in Terms-test Signed-off-by: Kerry Archibald <kerrya@element.io> * test/ScalarAuthClient-test.js -> test/ScalarAuthClient-test.ts Signed-off-by: Kerry Archibald <kerrya@element.io> * ts fixes in ScalarAuthClient-test Signed-off-by: Kerry Archibald <kerrya@element.io> * comment Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
parent
4d122db7cf
commit
3d0045dab5
2 changed files with 61 additions and 33 deletions
60
test/ScalarAuthClient-test.ts
Normal file
60
test/ScalarAuthClient-test.ts
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import ScalarAuthClient from '../src/ScalarAuthClient';
|
||||
import { MatrixClientPeg } from '../src/MatrixClientPeg';
|
||||
import { stubClient } from './test-utils';
|
||||
|
||||
describe('ScalarAuthClient', function() {
|
||||
const apiUrl = 'test.com/api';
|
||||
const uiUrl = 'test.com/app';
|
||||
beforeEach(function() {
|
||||
window.localStorage.getItem = jest.fn((arg) => {
|
||||
if (arg === "mx_scalar_token") return "brokentoken";
|
||||
});
|
||||
stubClient();
|
||||
});
|
||||
|
||||
it('should request a new token if the old one fails', async function() {
|
||||
const sac = new ScalarAuthClient(apiUrl, uiUrl);
|
||||
|
||||
// @ts-ignore unhappy with Promise calls
|
||||
jest.spyOn(sac, 'getAccountName').mockImplementation((arg: string) => {
|
||||
switch (arg) {
|
||||
case "brokentoken":
|
||||
return Promise.reject({
|
||||
message: "Invalid token",
|
||||
});
|
||||
case "wokentoken":
|
||||
default:
|
||||
return Promise.resolve(MatrixClientPeg.get().getUserId());
|
||||
}
|
||||
});
|
||||
|
||||
MatrixClientPeg.get().getOpenIdToken = jest.fn().mockResolvedValue('this is your openid token');
|
||||
|
||||
sac.exchangeForScalarToken = jest.fn((arg) => {
|
||||
if (arg === "this is your openid token") return Promise.resolve("wokentoken");
|
||||
});
|
||||
|
||||
await sac.connect();
|
||||
|
||||
expect(sac.exchangeForScalarToken).toBeCalledWith('this is your openid token');
|
||||
expect(sac.hasCredentials).toBeTruthy();
|
||||
// @ts-ignore private property
|
||||
expect(sac.scalarToken).toEqual('wokentoken');
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue