Test/firebase coverage#19
Merged
Merged
Conversation
…ation Unit tests: - Add full test suite for editorServices.ts (162 tests, 100% coverage) - Expand services.test.ts to cover all read functions — getSiteSettings, getPublishedContentByType, getContentBySlug, getPublishedEvents, getCategories, getTags, getPublicMediaAssets, getActiveCampaigns, getPublicIbanEntries, getPublicSupporters (61 tests total) - Add isDbAvailable() tests to getDefaultDb.test.ts to cover lines 27-28 Integration tests: - Fix concurrent clearFirestore() race condition by giving each test file its own emulator namespace via a suite suffix in newEnv(); prevents one file's beforeEach from wiping staff docs seeded by a parallel file, which caused Null value error in isEditor() security rule evaluation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add comprehensive unit test suites for editorServices.ts and services.ts, covering all previously uncovered functions (lines 67–699 and 28–181 respectively)
Add missing isDbAvailable() coverage in getDefaultDb.test.ts (lines 27–28)
Fix a race condition in integration tests that caused 6 intermittent failures when running the full suite
Changes
New / expanded unit tests
editorServices.test.ts — 162 tests, 100% statement/function/line coverage across all CRUD operations for blogs, events, media, announcements, notifications, campaigns, categories, and tags; covers all partial-update field branches, status mappings, Timestamp conversion paths, and unauthenticated uid fallbacks
services.test.ts — rewrote the partial file (was only covering submitContactMessage + submitVolunteerApplication) to cover all 12 exported functions; 61 tests total including ?? default branches for getPublicIbanEntries / getPublicSupporters, navigator undefined path for userAgent, and fromDoc id injection
getDefaultDb.test.ts — added two tests for isDbAvailable() covering the truthy and falsy env var branches
Integration test isolation fix
All 5 integration test files shared the same emulator PROJECT_ID, so parallel clearFirestore() calls in beforeEach would wipe staff documents seeded by a concurrently running file; isEditor() then called get(staff/uid) on a missing document, .data.role threw Null value error inside the rules evaluator, and legitimate editor writes were denied
newEnv() in helpers/emulator.ts now accepts an optional suite string appended to the project ID, giving each file its own isolated namespace
Test plan
npm run test:unit — 458 tests, all pass
npm run test:integration — 27 tests, all pass
npm test — 464 tests, 18 test files, all pass