UNPKG

@mytmpvpn/mytmpvpn-client

Version:

MyTmpVpn Client Library

53 lines (52 loc) 2.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const src_1 = require("../src"); const common_1 = require("./common"); const auth_1 = require("../src/__mocks__/auth"); describe('Auth', () => { let auth; const appConfig = src_1.appconfig.loadDefaultAppConfig(); beforeAll(async () => { const userProfile = (0, common_1.createUserProfile)(); auth = (0, src_1.getAuthModule)(appConfig, userProfile); }, 600000); afterAll(async () => { (0, src_1.clear)(); }, 600000); describe('authenticate', () => { it('should not successfully authenticate if not registered', async () => { await expect(auth.authenticate()).rejects.toThrow('User does not exist.'); }); it('should successfully authenticate after being registered', async () => { await auth.register(); const client = await auth.authenticate(); expect(client).toBeDefined(); expect(auth.getUser()).toBeDefined(); expect(auth.getSession()).toBeDefined(); }); it('mock should fail authentication when configured', async () => { auth = new auth_1.AuthMock('testUser', false); await expect(auth.authenticate()).rejects.toThrow('User does not exist.'); }); }); describe('register', () => { it('should successfully register', async () => { (0, src_1.clear)(); const userProfile = (0, common_1.createUserProfile)(); auth = (0, src_1.getAuthModule)(appConfig, userProfile); const user = await auth.register(); expect(user.getUsername()).toBe(userProfile.username); }); }); describe('confirmRegistration', () => { it('should confirm with valid code', async () => { auth = new auth_1.AuthMock('testUser', true); const result = await auth.confirmRegistration('valid-code'); expect(result).toBe('SUCCESS'); }); it('should reject invalid code', async () => { auth = new auth_1.AuthMock('testUser', true); await expect(auth.confirmRegistration('invalid-code')).rejects.toThrow(); }); }); });