auth0-lock
Version:
Auth0 Lock
64 lines (62 loc) • 2.6 kB
JavaScript
;
var _web_api = _interopRequireDefault(require("../../core/web_api"));
var _testUtils = require("../testUtils");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
describe('Auth0WebApi', function () {
var originalWindow;
var originalLocation;
var LOCK_ID = 'lock-id';
var CLIENT_ID = 'client-id';
var DEFAULT_DOMAIN = 'test.com';
var client = function client() {
return _web_api.default.clients[LOCK_ID];
};
beforeEach(function () {
originalWindow = window.window;
originalLocation = window.location;
});
afterEach(function () {
window.window = originalWindow;
delete window.location;
window.location = originalLocation;
});
describe('setupClient', function () {
it('sets the correct options when is on the hosted login page', function () {
(0, _testUtils.setURL)("https://".concat(DEFAULT_DOMAIN, "/"));
_web_api.default.setupClient(LOCK_ID, CLIENT_ID, DEFAULT_DOMAIN, {
redirect: true
});
expect(client()).toEqual(expect.objectContaining({
isUniversalLogin: true,
domain: DEFAULT_DOMAIN,
authOpt: {
popup: false
}
}));
});
it('sets redirect: true when on the same origin as the specified domain', function () {
(0, _testUtils.setURL)("https://".concat(DEFAULT_DOMAIN, "/"));
_web_api.default.setupClient(LOCK_ID, CLIENT_ID, DEFAULT_DOMAIN, {});
expect(client().authOpt.popup).toBe(false);
});
it('sets redirect: false when on a different origin as the specified domain', function () {
(0, _testUtils.setURL)('https://test-other.com/');
_web_api.default.setupClient(LOCK_ID, CLIENT_ID, DEFAULT_DOMAIN, {});
expect(client().authOpt.popup).toBe(true);
});
it('forces popup and sso mode for cordova, only when not running in the hosted environment', function () {
(0, _testUtils.setURL)("https://".concat(DEFAULT_DOMAIN, "/"));
window.cordova = true;
_web_api.default.setupClient(LOCK_ID, CLIENT_ID, DEFAULT_DOMAIN, {});
expect(client().authOpt.popup).toBe(false);
expect(client().authOpt.sso).toBeUndefined();
});
it('forces popup and sso mode for electron, only when not running in the hosted environment', function () {
(0, _testUtils.setURL)("https://".concat(DEFAULT_DOMAIN, "/"));
window.electron = true;
_web_api.default.setupClient(LOCK_ID, CLIENT_ID, DEFAULT_DOMAIN, {});
expect(client().authOpt.popup).toBe(false);
expect(client().authOpt.sso).toBeUndefined();
});
});
});