UNPKG

@ringcentral/sdk

Version:

- [Installation](#installation) - [Getting Started](#getting-started) - [API Calls](#api-calls) - [Advanced SDK Configuration & Polyfills](#advanced-sdk-configuration--polyfills) - [Making telephony calls](#making-telephony-calls) - [Call management using

732 lines 38.4 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; var _this = this; Object.defineProperty(exports, "__esModule", { value: true }); var test_1 = require("../test/test"); var globalAny = global; var windowAny = typeof window !== 'undefined' ? window : global; describe('RingCentral.platform.Platform', function () { describe('isTokenValid', function () { it('is not authenticated when token has expired', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform, _a; return __generator(this, function (_b) { switch (_b.label) { case 0: platform = sdk.platform(); return [4 /*yield*/, platform.auth().cancelAccessToken()]; case 1: _b.sent(); _a = test_1.expect; return [4 /*yield*/, platform.auth().accessTokenValid()]; case 2: _a.apply(void 0, [_b.sent()]).to.equal(false); return [2 /*return*/]; } }); }); })); it('is not authenticated after logout', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform, _a; return __generator(this, function (_b) { switch (_b.label) { case 0: test_1.logout(); platform = sdk.platform(); return [4 /*yield*/, platform.logout()]; case 1: _b.sent(); _a = test_1.expect; return [4 /*yield*/, platform.auth().accessTokenValid()]; case 2: _a.apply(void 0, [_b.sent()]).to.equal(false); return [2 /*return*/]; } }); }); })); }); describe('authorized', function () { it('initiates refresh if not authorized', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform, _a, _b; return __generator(this, function (_c) { switch (_c.label) { case 0: test_1.tokenRefresh(); platform = sdk.platform(); _a = test_1.expect; return [4 /*yield*/, platform.auth().data()]; case 1: _a.apply(void 0, [(_c.sent()).access_token]).to.not.equal('ACCESS_TOKEN_FROM_REFRESH'); return [4 /*yield*/, platform.auth().cancelAccessToken()]; case 2: _c.sent(); return [4 /*yield*/, platform.loggedIn()]; case 3: _c.sent(); _b = test_1.expect; return [4 /*yield*/, platform.auth().data()]; case 4: _b.apply(void 0, [(_c.sent()).access_token]).to.equal('ACCESS_TOKEN_FROM_REFRESH'); return [2 /*return*/]; } }); }); })); }); describe('login', function () { it('login with code', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform, _a; return __generator(this, function (_b) { switch (_b.label) { case 0: platform = sdk.platform(); return [4 /*yield*/, platform.auth().cancelAccessToken()]; case 1: _b.sent(); test_1.authentication(); return [4 /*yield*/, platform.login({ code: 'foo', access_token_ttl: 100, refresh_token_ttl: 100, })]; case 2: _b.sent(); _a = test_1.expect; return [4 /*yield*/, platform.auth().data()]; case 3: _a.apply(void 0, [(_b.sent()).access_token]).to.equal('ACCESS_TOKEN'); return [2 /*return*/]; } }); }); })); it('login with access_token', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform, _a; return __generator(this, function (_b) { switch (_b.label) { case 0: platform = sdk.platform(); return [4 /*yield*/, platform.auth().cancelAccessToken()]; case 1: _b.sent(); test_1.authentication(); return [4 /*yield*/, platform.login({ access_token: 'foo' })]; case 2: _b.sent(); _a = test_1.expect; return [4 /*yield*/, platform.auth().data()]; case 3: _a.apply(void 0, [(_b.sent()).access_token]).to.equal('foo'); return [2 /*return*/]; } }); }); })); it('login error', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: platform = sdk.platform(); return [4 /*yield*/, platform.auth().cancelAccessToken()]; case 1: _a.sent(); test_1.apiCall('POST', '/restapi/oauth/token', { message: 'expected' }, 400); return [4 /*yield*/, test_1.expectThrows(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, platform.login({ code: 'foo' })]; }); }); }, 'expected')]; case 2: _a.sent(); return [2 /*return*/]; } }); }); })); }); describe('loggedIn', function () { it('returns false if refresh failed', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform, res; return __generator(this, function (_a) { switch (_a.label) { case 0: platform = sdk.platform(); return [4 /*yield*/, platform.auth().cancelAccessToken()]; case 1: _a.sent(); test_1.apiCall('POST', '/restapi/oauth/token', { message: 'expected' }, 400); return [4 /*yield*/, platform.loggedIn()]; case 2: res = _a.sent(); test_1.expect(res).to.equal(false); return [2 /*return*/]; } }); }); })); }); describe('sendRequest', function () { it('refreshes token when token was expired', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform, path, refreshSpy, _a, _b; return __generator(this, function (_c) { switch (_c.label) { case 0: platform = sdk.platform(); path = '/restapi/xxx'; refreshSpy = test_1.spy(function () { }); test_1.tokenRefresh(); test_1.apiCall('GET', path, {}); _a = test_1.expect; return [4 /*yield*/, platform.auth().data()]; case 1: _a.apply(void 0, [(_c.sent()).access_token]).to.not.equal('ACCESS_TOKEN_FROM_REFRESH'); return [4 /*yield*/, platform.auth().cancelAccessToken()]; case 2: _c.sent(); return [4 /*yield*/, platform.on(platform.events.refreshSuccess, refreshSpy).get(path)]; case 3: _c.sent(); test_1.expect(refreshSpy.calledOnce).to.be.true; _b = test_1.expect; return [4 /*yield*/, platform.auth().data()]; case 4: _b.apply(void 0, [(_c.sent()).access_token]).to.equal('ACCESS_TOKEN_FROM_REFRESH'); return [2 /*return*/]; } }); }); })); it('tries to refresh the token if Platform returns 401 Unauthorized and re-executes the request', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform, path, response, refreshSpy, res, _a, _b; return __generator(this, function (_c) { switch (_c.label) { case 0: platform = sdk.platform(); path = '/restapi/xxx'; response = { foo: 'bar' }; refreshSpy = test_1.spy(function () { test_1.apiCall('GET', path, response, 200); }); test_1.apiCall('GET', path, { message: 'time not in sync' }, 401, 'Time Not In Sync'); test_1.tokenRefresh(); platform.on(platform.events.refreshSuccess, refreshSpy); return [4 /*yield*/, platform.get(path)]; case 1: res = _c.sent(); test_1.expect(refreshSpy.calledOnce).to.be.true; _a = test_1.expect; return [4 /*yield*/, res.json()]; case 2: _a.apply(void 0, [_c.sent()]).to.deep.equal(response); _b = test_1.expect; return [4 /*yield*/, platform.auth().data()]; case 3: _b.apply(void 0, [(_c.sent()).access_token]).to.equal('ACCESS_TOKEN_FROM_REFRESH'); return [2 /*return*/]; } }); }); })); it('fails if ajax has status other than 2xx', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform, path; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: platform = sdk.platform(); path = '/restapi/xxx'; test_1.apiCall('GET', path, { description: 'Fail' }, 400, 'Bad Request'); return [4 /*yield*/, test_1.expectThrows(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, platform.get(path)]; }); }); }, 'Fail')]; case 1: _a.sent(); return [2 /*return*/]; } }); }); })); it('handles rate limit 429', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform, path, response, rateLimitSpy, res, e, _a; return __generator(this, function (_b) { switch (_b.label) { case 0: platform = sdk.platform(); path = '/restapi/xxx'; response = { foo: 'bar' }; rateLimitSpy = test_1.spy(function () { test_1.apiCall('GET', path, response, 200); }); test_1.apiCall('GET', path, { message: 'expected' }, 429, 'Rate Limit Exceeded'); platform.on(platform.events.rateLimitError, rateLimitSpy); return [4 /*yield*/, platform.get(path, null, { handleRateLimit: 0.01 })]; case 1: res = _b.sent(); test_1.expect(rateLimitSpy.calledOnce).to.be.true; e = rateLimitSpy.getCalls()[0].args[0]; test_1.expect(e.message).to.equal('expected'); test_1.expect(e.retryAfter).to.equal(10); _a = test_1.expect; return [4 /*yield*/, res.json()]; case 2: _a.apply(void 0, [_b.sent()]).to.deep.equal(response); return [2 /*return*/]; } }); }); })); it('emits rate limit 429 errors if they are not handled', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform, path, rateLimitSpy; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: platform = sdk.platform(); path = '/restapi/xxx'; rateLimitSpy = test_1.spy(function () { }); test_1.apiCall('GET', path, { message: 'expected' }, 429, 'Rate Limit Exceeded'); platform.on(platform.events.rateLimitError, rateLimitSpy); return [4 /*yield*/, test_1.expectThrows(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, platform.get(path)]; }); }); }, '', function (err) { test_1.expect(rateLimitSpy.calledOnce).to.be.true; var e = rateLimitSpy.getCalls()[0].args[0]; test_1.expect(e.message).to.equal('expected'); test_1.expect(e.retryAfter).to.equal(60000); test_1.expect(err).to.equal(e); })]; case 1: _a.sent(); return [2 /*return*/]; } }); }); })); }); describe('refresh', function () { it('handles error in queued AJAX after unsuccessful refresh when token is killed', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform, path, successSpy, errorSpy; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: platform = sdk.platform(); path = '/restapi/xxx'; successSpy = test_1.spy(function () { }); errorSpy = test_1.spy(function () { }); test_1.tokenRefresh(true); return [4 /*yield*/, platform.auth().cancelAccessToken()]; case 1: _a.sent(); return [4 /*yield*/, test_1.expectThrows(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, platform .on(platform.events.refreshSuccess, successSpy) .on(platform.events.refreshError, errorSpy) .get(path)]; }); }); }, 'Wrong token')]; case 2: _a.sent(); test_1.expect(errorSpy.calledOnce).to.be.true; test_1.expect(successSpy.calledOnce).to.be.false; return [2 /*return*/]; } }); }); })); it('handles subsequent refreshes', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform; return __generator(this, function (_a) { switch (_a.label) { case 0: platform = sdk.platform(); test_1.tokenRefresh(); test_1.tokenRefresh(); test_1.tokenRefresh(); return [4 /*yield*/, platform.refresh()]; case 1: _a.sent(); // first return [4 /*yield*/, platform.refresh()]; case 2: _a.sent(); // second return [4 /*yield*/, Promise.all([ platform.refresh(), platform.refresh(), ])]; case 3: _a.sent(); return [2 /*return*/]; } }); }); })); it('returns error if response is malformed', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: platform = sdk.platform(); test_1.apiCall('POST', '/restapi/oauth/token', { message: 'Wrong token', error_description: 'Wrong token', description: 'Wrong token', }, 240); // This weird status was caught on client's machine return [4 /*yield*/, platform.auth().cancelAccessToken()]; case 1: _a.sent(); return [4 /*yield*/, test_1.expectThrows(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, platform.refresh()]; }); }); }, 'Wrong token', function (e) { test_1.expect(e.originalMessage).to.equal('Malformed OAuth response'); })]; case 2: _a.sent(); return [2 /*return*/]; } }); }); })); it('issues only one refresh request', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform, res, _a, _b, _c; return __generator(this, function (_d) { switch (_d.label) { case 0: test_1.tokenRefresh(); test_1.apiCall('GET', '/restapi/v1.0/foo/1', { increment: 1 }); test_1.apiCall('GET', '/restapi/v1.0/foo/2', { increment: 2 }); test_1.apiCall('GET', '/restapi/v1.0/foo/3', { increment: 3 }); platform = sdk.platform(); return [4 /*yield*/, platform.auth().cancelAccessToken()]; case 1: _d.sent(); _b = (_a = Promise).all; return [4 /*yield*/, Promise.all([ platform.get('/restapi/v1.0/foo/1'), platform.get('/restapi/v1.0/foo/2'), platform.get('/restapi/v1.0/foo/3'), ])]; case 2: return [4 /*yield*/, _b.apply(_a, [(_d.sent()).map(function (r) { return r.json(); })])]; case 3: res = _d.sent(); _c = test_1.expect; return [4 /*yield*/, platform.auth().data()]; case 4: _c.apply(void 0, [(_d.sent()).access_token]).to.equal('ACCESS_TOKEN_FROM_REFRESH'); test_1.expect(res[0].increment).to.equal(1); test_1.expect(res[1].increment).to.equal(2); test_1.expect(res[2].increment).to.equal(3); return [2 /*return*/]; } }); }); })); }); describe('get, post, put, delete', function () { it('sends request using appropriate method', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform, test; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: platform = sdk.platform(); test = function (method) { return __awaiter(_this, void 0, void 0, function () { var path, res, _a; return __generator(this, function (_b) { switch (_b.label) { case 0: path = "/restapi/v1.0/foo/" + method; test_1.apiCall(method, path, { foo: 'bar' }); return [4 /*yield*/, platform[method](path)]; case 1: res = _b.sent(); _a = test_1.expect; return [4 /*yield*/, res.json()]; case 2: _a.apply(void 0, [(_b.sent()).foo]).to.equal('bar'); return [2 /*return*/]; } }); }); }; return [4 /*yield*/, test('get')]; case 1: _a.sent(); return [4 /*yield*/, test('post')]; case 2: _a.sent(); return [4 /*yield*/, test('put')]; case 3: _a.sent(); return [4 /*yield*/, test('delete')]; case 4: _a.sent(); return [2 /*return*/]; } }); }); })); }); describe('createUrl', function () { it('builds the URL', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform, _a, _b, _c, _d; return __generator(this, function (_e) { switch (_e.label) { case 0: platform = sdk.platform(); test_1.expect(platform.createUrl('/restapi/v1.0/foo')).to.equal('/restapi/v1.0/foo'); test_1.expect(platform.createUrl('/restapi/v1.0/foo', { addServer: true })).to.equal('http://whatever/restapi/v1.0/foo'); _a = test_1.expect; return [4 /*yield*/, platform.signUrl(platform.createUrl('/restapi/v1.0/foo', { addServer: true, }))]; case 1: _a.apply(void 0, [_e.sent()]).to.equal('http://whatever/restapi/v1.0/foo?access_token=ACCESS_TOKEN'); _b = test_1.expect; return [4 /*yield*/, platform.signUrl(platform.createUrl('/restapi/v1.0/foo?bar', { addServer: true, }))]; case 2: _b.apply(void 0, [_e.sent()]).to.equal('http://whatever/restapi/v1.0/foo?bar&access_token=ACCESS_TOKEN'); _c = test_1.expect; return [4 /*yield*/, platform.signUrl(platform.createUrl('/restapi/v1.0/foo?bar', { addServer: true, addMethod: 'POST', }))]; case 3: _c.apply(void 0, [_e.sent()]).to.equal('http://whatever/restapi/v1.0/foo?bar&_method=POST&access_token=ACCESS_TOKEN'); _d = test_1.expect; return [4 /*yield*/, platform.signUrl(platform.createUrl('/rcvideo/v1/foo?bar', { addServer: true, }))]; case 4: _d.apply(void 0, [_e.sent()]).to.equal('http://whatever/rcvideo/v1/foo?bar&access_token=ACCESS_TOKEN'); return [2 /*return*/]; } }); }); })); }); describe('parseLoginRedirect', function () { describe('Authorization Code Flow', function () { it('parses url correctly', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform; return __generator(this, function (_a) { platform = sdk.platform(); test_1.expect(platform.parseLoginRedirect('?code=foo')).to.deep.equal({ code: 'foo' }); return [2 /*return*/]; }); }); })); }); describe('Implicit Grant Flow', function () { it('parses url correctly', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform; return __generator(this, function (_a) { platform = sdk.platform(); test_1.expect(platform.parseLoginRedirect('#access_token=foo')).to.deep.equal({ access_token: 'foo' }); return [2 /*return*/]; }); }); })); }); }); describe('loginUrl', function () { it('simple usage', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform; return __generator(this, function (_a) { platform = sdk.platform(); test_1.expect(platform.loginUrl({ implicit: true, state: 'foo', brandId: 'foo', display: 'foo', prompt: 'foo', })).to.equal('http://whatever/restapi/oauth/authorize?response_type=token&redirect_uri=http%3A%2F%2Ffoo&client_id=whatever&state=foo&brand_id=foo&display=foo&prompt=foo&ui_options=&ui_locales=&localeId='); test_1.expect(platform.loginUrl({ implicit: false, state: 'foo', brandId: 'foo', display: 'foo', prompt: 'foo', })).to.equal('http://whatever/restapi/oauth/authorize?response_type=code&redirect_uri=http%3A%2F%2Ffoo&client_id=whatever&state=foo&brand_id=foo&display=foo&prompt=foo&ui_options=&ui_locales=&localeId='); test_1.expect(platform.loginUrl({ implicit: false, })).to.equal('http://whatever/restapi/oauth/authorize?response_type=code&redirect_uri=http%3A%2F%2Ffoo&client_id=whatever&state=&brand_id=&display=&prompt=&ui_options=&ui_locales=&localeId='); return [2 /*return*/]; }); }); })); }); describe('loginWindow', function () { var isNode = typeof window !== 'undefined'; if (!isNode) { globalAny.window = { screenLeft: 0, screenTop: 0, location: { origin: '', }, }; globalAny.screen = { left: 0, top: 0, width: 0, height: 0, }; globalAny.document = { documentElement: { clientWidth: 0, clientHeight: 0, }, }; } window.addEventListener = function (eventName, cb, bubble) { windowAny.triggerEvent = function (mock) { cb(mock); }; }; it('simple usage', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform, close, focus, openSpy, res; return __generator(this, function (_a) { switch (_a.label) { case 0: platform = sdk.platform(); close = test_1.spy(); focus = test_1.spy(); openSpy = test_1.spy(function () { return ({ close: close, focus: focus, }); }); window.open = openSpy; window.removeEventListener = test_1.spy(); setTimeout(function () { windowAny.triggerEvent({ origin: 'bar' }); windowAny.triggerEvent({ origin: 'foo', data: { foo: 'bar' } }); windowAny.triggerEvent({ origin: 'foo', data: { RCAuthorizationResponse: '#access_token=foo' } }); }, 10); return [4 /*yield*/, platform.loginWindow({ url: 'foo', origin: 'foo', })]; case 1: res = _a.sent(); test_1.expect(res.access_token).to.equal('foo'); test_1.expect(close.calledOnce).to.be.true; test_1.expect(focus.calledOnce).to.be.true; test_1.expect(openSpy.calledOnce).to.be.true; return [2 /*return*/]; } }); }); })); it('throws an exception if no code and token', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform, openSpy; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: platform = sdk.platform(); openSpy = test_1.spy(function () { return ({ close: test_1.spy() }); }); window.open = openSpy; setTimeout(function () { windowAny.triggerEvent({ origin: 'foo', data: { RCAuthorizationResponse: '#bar=foo' } }); }, 10); return [4 /*yield*/, test_1.expectThrows(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, platform.loginWindow({ url: 'foo', origin: 'foo', })]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }, 'No authorization code or token')]; case 1: _a.sent(); test_1.expect(openSpy.calledOnce).to.be.true; return [2 /*return*/]; } }); }); })); it('throws an exception if window cannot be open', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform, openSpy; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: platform = sdk.platform(); openSpy = test_1.spy(function () { return null; }); window.open = openSpy; return [4 /*yield*/, test_1.expectThrows(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, platform.loginWindow({ url: 'foo', origin: 'foo', })]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }, 'Could not open login window. Please allow popups for this site')]; case 1: _a.sent(); test_1.expect(openSpy.calledOnce).to.be.true; return [2 /*return*/]; } }); }); })); }); describe('parseLoginRedirect', function () { it('parses redirect URIs with hash', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform; return __generator(this, function (_a) { platform = sdk.platform(); test_1.expect(platform.parseLoginRedirect('#access_token=foo').access_token).to.equal('foo'); return [2 /*return*/]; }); }); })); it('parses redirect URIs with query', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform; return __generator(this, function (_a) { platform = sdk.platform(); test_1.expect(platform.parseLoginRedirect('?access_token=foo').access_token).to.equal('foo'); return [2 /*return*/]; }); }); })); it('parses redirect URIs with errors', test_1.asyncTest(function (sdk) { return __awaiter(_this, void 0, void 0, function () { var platform; return __generator(this, function (_a) { platform = sdk.platform(); test_1.expect(function () { platform.parseLoginRedirect('?error_description=foo'); }).to.throw('foo'); test_1.expect(function () { platform.parseLoginRedirect('?error=foo'); }).to.throw('foo'); test_1.expect(function () { platform.parseLoginRedirect('xxx'); }).to.throw('Unable to parse response'); return [2 /*return*/]; }); }); })); }); }); //# sourceMappingURL=Platform-spec.js.map