@bsv/overlay-express 0.9.1 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,105 @@
1
+ # Unit Tests for @bsv/overlay-express
2
+
3
+ This directory contains comprehensive unit tests for the overlay-express library.
4
+
5
+ ## Test Structure
6
+
7
+ - **InMemoryMigrationSource.test.ts** - Tests for the internal migration source (tested through integration)
8
+ - **makeUserInterface.test.ts** - Tests for the web UI generation function
9
+ - **JanitorService.test.ts** - Tests for the janitor health check service
10
+ - **OverlayExpress.test.ts** - Tests for the main OverlayExpress class
11
+
12
+ ## Running Tests
13
+
14
+ ```bash
15
+ # Run all tests
16
+ npm test
17
+
18
+ # Run tests in watch mode
19
+ npm run test:watch
20
+
21
+ # Run tests with coverage
22
+ npm run test:coverage
23
+ ```
24
+
25
+ ## Test Coverage
26
+
27
+ The test suite covers:
28
+
29
+ ### makeUserInterface
30
+ - Default configuration generation
31
+ - Custom UI configuration
32
+ - Color customization
33
+ - Font customization
34
+ - Responsive design
35
+ - JavaScript function inclusion
36
+ - External links
37
+
38
+ ### JanitorService
39
+ - Constructor and initialization
40
+ - Health check execution
41
+ - Domain validation (valid domains, localhost, IP addresses)
42
+ - URL extraction from various field types
43
+ - Output health status management
44
+ - Down counter increment/decrement
45
+ - Output deletion on threshold
46
+ - Timeout handling
47
+ - Error handling
48
+
49
+ ### OverlayExpress
50
+ - Constructor with various parameter combinations
51
+ - Admin token generation and retrieval
52
+ - Port configuration
53
+ - Web UI configuration
54
+ - Janitor configuration
55
+ - Logger configuration
56
+ - Network configuration (main/test)
57
+ - ChainTracker configuration
58
+ - ARC API key configuration
59
+ - GASP sync configuration
60
+ - Verbose logging configuration
61
+ - Knex (SQL) database configuration
62
+ - MongoDB configuration
63
+ - Topic Manager configuration
64
+ - Lookup Service configuration
65
+ - Engine configuration
66
+ - Error handling for missing dependencies
67
+ - Full integration scenarios
68
+
69
+ ## Mocking Strategy
70
+
71
+ The tests use Jest mocks for external dependencies:
72
+ - `knex` - Database client
73
+ - `mongodb` - MongoDB client
74
+ - `@bsv/overlay` - Overlay services
75
+ - `@bsv/sdk` - BSV SDK
76
+ - `@bsv/overlay-discovery-services` - Discovery services
77
+ - `chalk` - Console coloring (suppressed in tests)
78
+ - `fetch` - HTTP requests (for JanitorService)
79
+
80
+ ## Test Environment
81
+
82
+ - **Test Framework**: Jest 29+
83
+ - **TypeScript**: ts-jest preset
84
+ - **Environment**: Node.js
85
+ - **Coverage Tool**: Jest built-in coverage
86
+
87
+ ## Writing New Tests
88
+
89
+ When adding new features:
90
+
91
+ 1. Create test file in `__tests__` directory
92
+ 2. Follow the naming convention: `FeatureName.test.ts`
93
+ 3. Use descriptive test names with `describe` and `it` blocks
94
+ 4. Mock external dependencies
95
+ 5. Test both success and error paths
96
+ 6. Include edge cases
97
+ 7. Update this README with new test coverage
98
+
99
+ ## CI/CD Integration
100
+
101
+ These tests are designed to run in CI/CD pipelines:
102
+ - Fast execution
103
+ - No external dependencies required
104
+ - Comprehensive coverage
105
+ - Clear error messages
@@ -0,0 +1,192 @@
1
+ import { describe, it, expect } from '@jest/globals'
2
+ import makeUserInterface, { type UIConfig } from '../makeUserInterface.js'
3
+
4
+ describe('makeUserInterface', () => {
5
+ describe('default configuration', () => {
6
+ it('should generate HTML with default values', () => {
7
+ const html = makeUserInterface()
8
+
9
+ expect(html).toContain('<!DOCTYPE html>')
10
+ expect(html).toContain('<title>Overlay Services</title>')
11
+ expect(html).toContain('https://bsvblockchain.org/favicon.ico')
12
+ expect(html).toContain('--background-color: #191919')
13
+ expect(html).toContain('--primary-color: #3b6efb')
14
+ })
15
+
16
+ it('should include necessary scripts', () => {
17
+ const html = makeUserInterface()
18
+
19
+ expect(html).toContain('showdown')
20
+ expect(html).toContain('highlight.min.js')
21
+ })
22
+
23
+ it('should include main UI structure', () => {
24
+ const html = makeUserInterface()
25
+
26
+ expect(html).toContain('class="main"')
27
+ expect(html).toContain('class="column_left"')
28
+ expect(html).toContain('class="column_right"')
29
+ expect(html).toContain('id="manager_list"')
30
+ expect(html).toContain('id="provider_list"')
31
+ expect(html).toContain('id="external_list"')
32
+ })
33
+
34
+ it('should include external links', () => {
35
+ const html = makeUserInterface()
36
+
37
+ expect(html).toContain('https://github.com/bsv-blockchain/overlay-services')
38
+ expect(html).toContain('https://bsv.brc.dev/transactions/0076')
39
+ expect(html).toContain('https://fast.brc.dev')
40
+ })
41
+ })
42
+
43
+ describe('custom configuration', () => {
44
+ it('should use custom host', () => {
45
+ const config: UIConfig = {
46
+ host: 'https://custom-host.com'
47
+ }
48
+ const html = makeUserInterface(config)
49
+
50
+ expect(html).toContain('https://custom-host.com/listTopicManagers')
51
+ expect(html).toContain('https://custom-host.com/listLookupServiceProviders')
52
+ expect(html).toContain('https://custom-host.com/getDocumentationForTopicManager')
53
+ })
54
+
55
+ it('should use custom favicon URL', () => {
56
+ const config: UIConfig = {
57
+ faviconUrl: 'https://example.com/favicon.ico'
58
+ }
59
+ const html = makeUserInterface(config)
60
+
61
+ expect(html).toContain('https://example.com/favicon.ico')
62
+ expect(html).toContain('const faviconUrl = \'https://example.com/favicon.ico\'')
63
+ })
64
+
65
+ it('should use custom colors', () => {
66
+ const config: UIConfig = {
67
+ backgroundColor: '#000000',
68
+ primaryColor: '#ff0000',
69
+ secondaryColor: '#00ff00',
70
+ primaryTextColor: '#ffffff'
71
+ }
72
+ const html = makeUserInterface(config)
73
+
74
+ expect(html).toContain('--background-color: #000000')
75
+ expect(html).toContain('--primary-color: #ff0000')
76
+ expect(html).toContain('--secondary-color: #00ff00')
77
+ expect(html).toContain('--primary-text-color: #ffffff')
78
+ })
79
+
80
+ it('should use custom fonts', () => {
81
+ const config: UIConfig = {
82
+ fontFamily: 'Comic Sans MS, cursive',
83
+ headingFontFamily: 'Impact, fantasy'
84
+ }
85
+ const html = makeUserInterface(config)
86
+
87
+ expect(html).toContain('--font-family: Comic Sans MS, cursive')
88
+ expect(html).toContain('--heading-font-family: Impact, fantasy')
89
+ })
90
+
91
+ it('should include additional styles', () => {
92
+ const config: UIConfig = {
93
+ additionalStyles: '.custom-class { color: red; }'
94
+ }
95
+ const html = makeUserInterface(config)
96
+
97
+ expect(html).toContain('.custom-class { color: red; }')
98
+ })
99
+
100
+ it('should use custom section background color', () => {
101
+ const config: UIConfig = {
102
+ sectionBackgroundColor: '#123456'
103
+ }
104
+ const html = makeUserInterface(config)
105
+
106
+ expect(html).toContain('--section-background-color: #123456')
107
+ })
108
+
109
+ it('should use custom link and hover colors', () => {
110
+ const config: UIConfig = {
111
+ linkColor: '#ff00ff',
112
+ hoverColor: '#00ffff'
113
+ }
114
+ const html = makeUserInterface(config)
115
+
116
+ expect(html).toContain('--link-color: #ff00ff')
117
+ expect(html).toContain('--hover-color: #00ffff')
118
+ })
119
+
120
+ it('should use custom border color', () => {
121
+ const config: UIConfig = {
122
+ borderColor: '#abcdef'
123
+ }
124
+ const html = makeUserInterface(config)
125
+
126
+ expect(html).toContain('--border-color: #abcdef')
127
+ })
128
+
129
+ it('should use custom secondary background and text colors', () => {
130
+ const config: UIConfig = {
131
+ secondaryBackgroundColor: '#f0f0f0',
132
+ secondaryTextColor: '#111111'
133
+ }
134
+ const html = makeUserInterface(config)
135
+
136
+ expect(html).toContain('--secondary-background-color: #f0f0f0')
137
+ expect(html).toContain('--secondary-text-color: #111111')
138
+ })
139
+
140
+ it('should use custom default content', () => {
141
+ const config: UIConfig = {
142
+ defaultContent: '`"# Custom Content\\n\\nThis is custom."`'
143
+ }
144
+ const html = makeUserInterface(config)
145
+
146
+ expect(html).toContain('# Custom Content')
147
+ expect(html).toContain('This is custom.')
148
+ })
149
+ })
150
+
151
+ describe('responsive design', () => {
152
+ it('should include responsive media queries', () => {
153
+ const html = makeUserInterface()
154
+
155
+ expect(html).toContain('@media screen and (max-width: 850px)')
156
+ })
157
+ })
158
+
159
+ describe('JavaScript functions', () => {
160
+ it('should include returnHome function', () => {
161
+ const html = makeUserInterface()
162
+
163
+ expect(html).toContain('window.returnHome')
164
+ })
165
+
166
+ it('should include managerDocumentation function', () => {
167
+ const html = makeUserInterface()
168
+
169
+ expect(html).toContain('window.managerDocumentation')
170
+ })
171
+
172
+ it('should include topicDocumentation function', () => {
173
+ const html = makeUserInterface()
174
+
175
+ expect(html).toContain('window.topicDocumentation')
176
+ })
177
+
178
+ it('should include syntax highlighting setup', () => {
179
+ const html = makeUserInterface()
180
+
181
+ expect(html).toContain('window.hljs')
182
+ expect(html).toContain('applyHighlighting')
183
+ })
184
+
185
+ it('should include URL hash handling', () => {
186
+ const html = makeUserInterface()
187
+
188
+ expect(html).toContain('handleUrlHash')
189
+ expect(html).toContain('window.location.hash')
190
+ })
191
+ })
192
+ })
@@ -0,0 +1,36 @@
1
+ // Jest setup file for global test configuration
2
+
3
+ // Mock uuid to avoid ES module issues
4
+ jest.mock('uuid', () => ({
5
+ v4: jest.fn(() => 'test-uuid-1234')
6
+ }))
7
+
8
+ // Mock chalk to avoid ANSI color codes in test output
9
+ jest.mock('chalk', () => {
10
+ const mockChalk = (str: string): string => str
11
+
12
+ return {
13
+ default: Object.assign(mockChalk, {
14
+ green: Object.assign((str: string) => str, { bold: (str: string) => str }),
15
+ blue: (str: string) => str,
16
+ yellow: (str: string) => str,
17
+ red: (str: string) => str,
18
+ magenta: Object.assign((str: string) => str, { bold: (str: string) => str }),
19
+ cyan: (str: string) => str
20
+ }),
21
+ green: Object.assign((str: string) => str, { bold: (str: string) => str }),
22
+ blue: (str: string) => str,
23
+ yellow: (str: string) => str,
24
+ red: (str: string) => str,
25
+ magenta: Object.assign((str: string) => str, { bold: (str: string) => str }),
26
+ cyan: (str: string) => str
27
+ }
28
+ })
29
+
30
+ // Suppress console output during tests unless explicitly testing it
31
+ global.console = {
32
+ ...console,
33
+ log: jest.fn(),
34
+ warn: jest.fn(),
35
+ error: jest.fn()
36
+ }