You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-28 15:22:05 +03:00
Merge remote-tracking branch 'origin/t3chguy/jest' into travis/sourcemaps
This commit is contained in:
@ -14,43 +14,41 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import expect from 'expect';
|
||||
|
||||
import sinon from 'sinon';
|
||||
|
||||
import ScalarAuthClient from '../src/ScalarAuthClient';
|
||||
import {MatrixClientPeg} from '../src/MatrixClientPeg';
|
||||
import { stubClient } from './test-utils';
|
||||
|
||||
describe('ScalarAuthClient', function() {
|
||||
let clientSandbox;
|
||||
|
||||
beforeEach(function() {
|
||||
sinon.stub(window.localStorage, 'getItem').withArgs('mx_scalar_token').returns('brokentoken');
|
||||
clientSandbox = stubClient();
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
clientSandbox.restore();
|
||||
sinon.restore();
|
||||
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();
|
||||
|
||||
sac._getAccountName = sinon.stub();
|
||||
sac._getAccountName.withArgs('brokentoken').rejects({
|
||||
message: "Invalid token",
|
||||
sac._getAccountName = jest.fn((arg) => {
|
||||
switch (arg) {
|
||||
case "brokentoken":
|
||||
return Promise.reject({
|
||||
message: "Invalid token",
|
||||
});
|
||||
case "wokentoken":
|
||||
return Promise.resolve(MatrixClientPeg.get().getUserId());
|
||||
}
|
||||
});
|
||||
sac._getAccountName.withArgs('wokentoken').resolves(MatrixClientPeg.get().getUserId());
|
||||
|
||||
MatrixClientPeg.get().getOpenIdToken = sinon.stub().resolves('this is your openid token');
|
||||
MatrixClientPeg.get().getOpenIdToken = jest.fn().mockResolvedValue('this is your openid token');
|
||||
|
||||
sac.exchangeForScalarToken = sinon.stub().withArgs('this is your openid token').resolves('wokentoken');
|
||||
sac.exchangeForScalarToken = jest.fn((arg) => {
|
||||
if (arg === "this is your openid token") return Promise.resolve("wokentoken");
|
||||
});
|
||||
|
||||
await sac.connect();
|
||||
|
||||
expect(sac.exchangeForScalarToken.calledWith('this is your openid token')).toBeTruthy();
|
||||
expect(sac.exchangeForScalarToken).toBeCalledWith('this is your openid token');
|
||||
expect(sac.scalarToken).toEqual('wokentoken');
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user