UNPKG

auth0-event-exporter

Version:

A Node.js module for making authenticated API calls using Auth0 Machine-to-Machine JWT tokens

77 lines (64 loc) 2.69 kB
const { WebDataExporter, EventType, Auth0Event } = require('./index'); describe('WebDataExporter', () => { test('should throw error for missing config', () => { expect(() => { new WebDataExporter({}); }).toThrow('Missing required configuration'); }); test('should create instance with valid config', () => { const config = { auth0Domain: 'test.auth0.com', auth0ClientId: 'test-client-id', auth0ClientSecret: 'test-client-secret', auth0Audience: 'https://test-api', apiBaseUrl: 'https://api.example.com' }; const client = new WebDataExporter(config); expect(client).toBeInstanceOf(WebDataExporter); }); test('should validate required config fields', () => { const configs = [ { auth0ClientId: 'test', auth0ClientSecret: 'test', auth0Audience: 'test', apiBaseUrl: 'test' }, { auth0Domain: 'test', auth0ClientSecret: 'test', auth0Audience: 'test', apiBaseUrl: 'test' }, { auth0Domain: 'test', auth0ClientId: 'test', auth0Audience: 'test', apiBaseUrl: 'test' }, { auth0Domain: 'test', auth0ClientId: 'test', auth0ClientSecret: 'test', apiBaseUrl: 'test' }, { auth0Domain: 'test', auth0ClientId: 'test', auth0ClientSecret: 'test', auth0Audience: 'test' } ]; configs.forEach((config, index) => { expect(() => { new WebDataExporter(config); }).toThrow('Missing required configuration'); }); }); }); describe('Auth0Event', () => { test('should create event with correct properties', () => { const message = 'Test message'; const timestamp = new Date(); const eventType = EventType.LOGIN; const event = new Auth0Event(message, timestamp, eventType); expect(event.message).toBe(message); expect(event.timestamp).toBe(timestamp); expect(event.eventType).toBe(eventType); }); test('should convert to JSON correctly', () => { const message = 'Test message'; const timestamp = new Date('2023-01-01T00:00:00Z'); const eventType = EventType.LOGOUT; const event = new Auth0Event(message, timestamp, eventType); const json = event.toJSON(); expect(json.message).toBe(message); expect(json.timestamp).toBe(timestamp.toISOString()); expect(json.eventType).toBe(eventType); }); }); describe('EventType', () => { test('should have all required event types', () => { expect(EventType.LOGIN).toBe('login'); expect(EventType.LOGOUT).toBe('logout'); expect(EventType.SIGNUP).toBe('signup'); expect(EventType.PASSWORD_CHANGE).toBe('password_change'); expect(EventType.PROFILE_UPDATE).toBe('profile_update'); expect(EventType.API_ACCESS).toBe('api_access'); }); });