UNPKG

dl

Version:

DreamLab Libs

61 lines (55 loc) 2.79 kB
var UidProfile = require('../../lib/uid/UidProfile.js').UidProfile; describe('UidProfile', function () { describe('isLogged', function () { it('should return true', function () { expect(new UidProfile({usr_uuid: 'test'}).isLogged()).toBeTruthy(); }); it('should return false', function () { expect(new UidProfile({usr_email: 'test'}).isLogged()).toBeFalsy(); expect(new UidProfile({usr_uuid: null}).isLogged()).toBeFalsy(); expect(new UidProfile({uuid: 'test'}).isLogged()).toBeFalsy(); expect(new UidProfile({}).isLogged()).toBeFalsy(); expect(new UidProfile().isLogged()).toBeFalsy(); }); }); describe('isAnonymous', function () { it('should return true', function () { expect(new UidProfile({usr_uuid: 'test'}).isAnonymous()).toBeTruthy(); expect(new UidProfile({usr_email: '', usr_phone: ''}).isAnonymous()).toBeTruthy(); expect(new UidProfile({usr_email: null, usr_phone: null}).isAnonymous()).toBeTruthy(); expect(new UidProfile({email: 'test', phone: 'test'}).isLogged()).toBeFalsy(); expect(new UidProfile({}).isAnonymous()).toBeTruthy(); expect(new UidProfile().isAnonymous()).toBeTruthy(); }); it('should return false', function () { expect(new UidProfile({usr_email: 'test', usr_phone: 'test'}).isAnonymous()).toBeFalsy(); expect(new UidProfile({usr_email: ' ', usr_phone: ' '}).isAnonymous()).toBeFalsy(); }); }); describe('toJSON', function () { it('should stringify to empty JSON Object', function () { expect(JSON.stringify(new UidProfile({}))).toEqual('{}'); expect(JSON.stringify(new UidProfile())).toEqual('{}'); expect(JSON.stringify(new UidProfile({id: 'test', usr_id: 'test'}))).toEqual('{}'); }); it('should stringify to nonempty JSON Object', function () { var lastLogin = new Date().toISOString(), data = JSON.parse(JSON.stringify(new UidProfile({ usr_uuid: 'uuid', usr_email: 'email', usr_phone: 'phone', usr_name: 'name', usr_surname: 'surname', usr_last_login: lastLogin, test: 'test' }))); expect(data.id).toEqual('uuid'); expect(data.email).toEqual('email'); expect(data.phone).toEqual('phone'); expect(data.name).toEqual('name'); expect(data.surname).toEqual('surname'); expect(data.lastLogin).toEqual(lastLogin); expect(data.test).not.toBeDefined(); }); }); });