import { OAuthToken } from '../../types' import { Session } from '../../utils/session' const token: OAuthToken = { access_token: 'access_token', refresh_token: 'refresh_token', token_type: 'undefined', created_at: 0, expires_in: 0, scope: '', } describe('Session', () => { describe('constructor', () => { it('should track the environment', () => { const session = new Session() expect(session.env).toBe('production') expect(session.isAuthenticated).toBe(false) }) it('should track the token', () => { const session = new Session({ token }) expect(session.token).toEqual(token) expect(session.isAuthenticated).toEqual(true) }) }) describe('hydrate', () => { describe('success', () => { it('should return a hydrated Session instance', () => { const session = new Session({ token }) expect(session.token).toEqual(token) expect(session.isAuthenticated).toEqual(true) const sessionString = session.toString() const hydratedSession = Session.hydrate(sessionString) expect(hydratedSession.token).toEqual(token) expect(hydratedSession.isAuthenticated).toEqual(true) }) it('should store the environment of hydrated Session instance', () => { const env = 'production' const session = new Session({ token, env }) const sessionString = session.toString() const hydratedSession = Session.hydrate(sessionString) expect(hydratedSession.env).toEqual(env) expect(hydratedSession.token).toEqual(token) expect(hydratedSession.isAuthenticated).toEqual(true) }) }) describe('failure', () => { it('should return a new Session instance', () => { const session = Session.hydrate('') expect(session.env).toBe('production') expect(session.isAuthenticated).toBe(false) }) }) }) })