1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00

Refactor for barrels. Utils service to jslib

This commit is contained in:
Kyle Spearrin
2018-01-06 22:13:48 -05:00
parent c018f096b4
commit 03258e50f7
56 changed files with 270 additions and 433 deletions

View File

@@ -1,32 +1,32 @@
import UtilsService from './utils.service';
import { Services } from '@bitwarden/jslib';
describe('Utils Service', () => {
describe('getHostname', () => {
it('should fail for invalid urls', () => {
expect(UtilsService.getHostname(null)).toBeNull();
expect(UtilsService.getHostname(undefined)).toBeNull();
expect(UtilsService.getHostname(' ')).toBeNull();
expect(UtilsService.getHostname('https://bit!:"_&ward.com')).toBeNull();
expect(UtilsService.getHostname('bitwarden')).toBeNull();
expect(Services.UtilsService.getHostname(null)).toBeNull();
expect(Services.UtilsService.getHostname(undefined)).toBeNull();
expect(Services.UtilsService.getHostname(' ')).toBeNull();
expect(Services.UtilsService.getHostname('https://bit!:"_&ward.com')).toBeNull();
expect(Services.UtilsService.getHostname('bitwarden')).toBeNull();
});
it('should handle valid urls', () => {
expect(UtilsService.getHostname('https://bitwarden.com')).toBe('bitwarden.com');
expect(UtilsService.getHostname('http://bitwarden.com')).toBe('bitwarden.com');
expect(UtilsService.getHostname('http://vault.bitwarden.com')).toBe('vault.bitwarden.com');
expect(UtilsService.getHostname('https://user:password@bitwarden.com:8080/password/sites?and&query#hash')).toBe('bitwarden.com');
expect(Services.UtilsService.getHostname('https://bitwarden.com')).toBe('bitwarden.com');
expect(Services.UtilsService.getHostname('http://bitwarden.com')).toBe('bitwarden.com');
expect(Services.UtilsService.getHostname('http://vault.bitwarden.com')).toBe('vault.bitwarden.com');
expect(Services.UtilsService.getHostname('https://user:password@bitwarden.com:8080/password/sites?and&query#hash')).toBe('bitwarden.com');
});
it('should support localhost and IP', () => {
expect(UtilsService.getHostname('https://localhost')).toBe('localhost');
expect(UtilsService.getHostname('https://192.168.1.1')).toBe('192.168.1.1');
expect(Services.UtilsService.getHostname('https://localhost')).toBe('localhost');
expect(Services.UtilsService.getHostname('https://192.168.1.1')).toBe('192.168.1.1');
});
});
describe('newGuid', () => {
it('should create a valid guid', () => {
const validGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
expect(UtilsService.newGuid()).toMatch(validGuid);
expect(Services.UtilsService.newGuid()).toMatch(validGuid);
});
});
});