You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
│ ├── config.test.js # Unit tests for config.js (env loading, defaults, validation)
457
+
│ ├── format-message.test.js # Unit tests for format-message.js (CBOR codec, parsing)
456
458
│ ├── integration.test.js # End-to-end integration test suite (requires .env)
457
459
│ ├── setup.js # Jest setup — silences app console output during tests
458
460
│ ├── streaming-reporter.js # Custom Jest reporter with real-time per-test output
459
-
│ └── unit.test.js # Offline unit tests (no credentials required)
461
+
│ └── unit.test.js # formatMessage unit tests (no credentials required)
460
462
├── .env # Hedera credentials and config (not committed)
461
463
├── .env.example # Example environment file
462
464
├── .gitignore # Git ignore rules
@@ -488,7 +490,17 @@ npm run test:coverage # Run all tests and generate
488
490
489
491
## Testing
490
492
491
-
The project uses [Jest](https://jestjs.io/) as its test runner. There are two test suites:
493
+
The project uses [Jest](https://jestjs.io/) as its test runner. Tests are split into offline unit tests and live integration tests:
494
+
495
+
### All Tests
496
+
497
+
Run with:
498
+
499
+
```bash
500
+
npm test
501
+
```
502
+
503
+
Each test name appears immediately when it starts running (with a `●` indicator), and updates in-place with the result and elapsed time once it finishes. This is handled by [test/streaming-reporter.js](test/streaming-reporter.js).
492
504
493
505
### Unit Tests (offline)
494
506
@@ -498,13 +510,29 @@ Test pure logic with no network connection or credentials required:
498
510
npm run test:unit
499
511
```
500
512
501
-
Covers all four exit paths of `formatMessage` in `src/lib/format-message.js`:
513
+
Spans three test files (`unit.test.js`, `config.test.js`, `format-message.test.js`) and covers:
514
+
515
+
**`unit.test.js`** — four exit paths of `formatMessage`:
502
516
503
517
- Encrypted message that decrypts successfully
504
518
- Encrypted message that cannot be decrypted (wrong key)
- Default values and case normalisations (network, encryption type, RSA data dir, mirror node URL)
527
+
- Required-field validation (throws with a clear message for each missing field)
528
+
529
+
**`format-message.test.js`** — CBOR codec and message formatting (`src/lib/format-message.js`):
530
+
531
+
-`encodeCBOR`/`decodeCBOR` roundtrip for all supported types (primitives, integers, floats, strings, buffers, arrays, objects)
532
+
-`encodeCBOR` and `decodeCBOR` error cases (unsupported types, malformed input)
533
+
-`parseMessageContent` format detection (CBOR, JSON, plain)
534
+
-`formatMessage` with CBOR-encoded messages and public-key output branches
535
+
508
536
### Integration Tests (live Hedera)
509
537
510
538
End-to-end tests that require a configured `.env` file and HBAR balance:
@@ -526,50 +554,6 @@ Covers:
526
554
- Link ownership validation (rejects attempts to link a topic to the wrong account)
527
555
- Sending messages to a re-linked message box
528
556
529
-
### All Tests
530
-
531
-
Run with:
532
-
533
-
```bash
534
-
npm test
535
-
```
536
-
537
-
Example output:
538
-
539
-
```text
540
-
formatMessage
541
-
✓ Encrypted message decrypted successfully (3 ms)
542
-
✓ Encrypted message cannot be decrypted (60 ms)
543
-
✓ Public key announcement message correctly decoded (17 ms)
544
-
✓ Plain text / unrecognised message correctly handled (1 ms)
545
-
546
-
Test Suites: 1 passed, 1 total
547
-
Tests: 4 passed, 4 total
548
-
Snapshots: 0 total
549
-
Time: 0.234 s
550
-
551
-
Message Box Integration
552
-
✓ Setup Message Box (9757 ms)
553
-
✓ Send Message (6520 ms)
554
-
✓ Send Message (CBOR) (5816 ms)
555
-
✓ Check Messages (187 ms)
556
-
✓ Message Box Reuse (Idempotency) (95 ms)
557
-
✓ Signature Verification (2532 ms)
558
-
✓ Remove Message Box (5519 ms)
559
-
✓ Link Message Box (re-attach existing topic) (6562 ms)
560
-
✓ Link Message Box (idempotent – already linked) (132 ms)
561
-
✓ Link Message Box (rejects wrong account) (122 ms)
562
-
✓ Send Message After Re-link (4391 ms)
563
-
✓ Remove Message Box (final cleanup) (6430 ms)
564
-
565
-
Test Suites: 1 passed, 1 total
566
-
Tests: 12 passed, 12 total
567
-
Snapshots: 0 total
568
-
Time: 48.353 s
569
-
```
570
-
571
-
Each test name appears immediately when it starts running (with a `●` indicator), and updates in-place with the result and elapsed time once it finishes. This is handled by [test/streaming-reporter.js](test/streaming-reporter.js).
0 commit comments