|
| 1 | +import { describe, expect, it, jest } from '@jest/globals'; |
| 2 | + |
| 3 | +describe('History analytics wrappers (mocked)', () => { |
| 4 | + afterEach(() => { |
| 5 | + jest.resetModules(); |
| 6 | + jest.clearAllMocks(); |
| 7 | + }); |
| 8 | + |
| 9 | + it('wraps platform helpers and unifies histories', () => { |
| 10 | + jest.isolateModules(() => { |
| 11 | + jest.doMock('../src/processors/gridset/helpers', () => ({ |
| 12 | + readGrid3History: jest.fn(() => [ |
| 13 | + { id: 'g1', content: 'grid single', occurrences: [{ timestamp: new Date() }] }, |
| 14 | + ]), |
| 15 | + readGrid3HistoryForUser: jest.fn(() => [ |
| 16 | + { id: 'g-user', content: 'grid user', occurrences: [{ timestamp: new Date() }] }, |
| 17 | + ]), |
| 18 | + readAllGrid3History: jest.fn(() => [ |
| 19 | + { id: 'g-all', content: 'grid all', occurrences: [{ timestamp: new Date() }] }, |
| 20 | + ]), |
| 21 | + findGrid3Users: jest.fn(() => [ |
| 22 | + { userName: 'alice', langCode: 'en', basePath: 'p', historyDbPath: 'p/db' }, |
| 23 | + ]), |
| 24 | + })); |
| 25 | + |
| 26 | + jest.doMock('../src/processors/snap/helpers', () => ({ |
| 27 | + readSnapUsage: jest.fn(() => [ |
| 28 | + { |
| 29 | + id: 's1', |
| 30 | + content: 'snap single', |
| 31 | + occurrences: [{ timestamp: new Date() }], |
| 32 | + platform: { buttonId: 'b1' }, |
| 33 | + }, |
| 34 | + ]), |
| 35 | + readSnapUsageForUser: jest.fn(() => [ |
| 36 | + { id: 's-user', content: 'snap user', occurrences: [{ timestamp: new Date() }] }, |
| 37 | + ]), |
| 38 | + findSnapUsers: jest.fn(() => [{ userId: 'u1', userPath: 'p', vocabPaths: [] }]), |
| 39 | + })); |
| 40 | + |
| 41 | + // Import after mocks are in place |
| 42 | + const history = require('../src/analytics/history'); |
| 43 | + |
| 44 | + const gridUserEntries = history.readGrid3HistoryForUser('alice'); |
| 45 | + expect(gridUserEntries[0].source).toBe('Grid'); |
| 46 | + expect(gridUserEntries[0].content).toBe('grid user'); |
| 47 | + |
| 48 | + const gridAllEntries = history.readAllGrid3History(); |
| 49 | + expect(gridAllEntries[0].source).toBe('Grid'); |
| 50 | + |
| 51 | + const snapEntries = history.readSnapUsageForUser('u1'); |
| 52 | + expect(snapEntries[0].source).toBe('Snap'); |
| 53 | + |
| 54 | + expect(history.listGrid3Users()).toHaveLength(1); |
| 55 | + expect(history.listSnapUsers()).toHaveLength(1); |
| 56 | + |
| 57 | + const unified = history.collectUnifiedHistory(); |
| 58 | + expect(unified.map((e: any) => e.source).sort()).toEqual(['Grid', 'Snap']); |
| 59 | + }); |
| 60 | + }); |
| 61 | +}); |
0 commit comments