Mocks Governor
The Mocks Governor provides methods for anonymizing and modifying tournament records. For generating tournaments, participants, and outcomes, see the comprehensive mocksEngine documentation.
Overview
The mocksGovernor contains two specialized methods:
- anonymizeTournamentRecord - Replace personal information with mock data
- modifyTournamentRecord - Add draws to existing tournaments
For all other testing needs, use the mocksEngine:
- Tournament Generation -
generateTournamentRecord() - Outcome Generation -
generateOutcome(),generateOutcomeFromScoreString() - Participant Generation -
generateParticipants() - Advanced Patterns - Common testing patterns
Import
import { mocksGovernor } from 'tods-competition-factory';
// Governor methods
const { anonymizeTournamentRecord, modifyTournamentRecord } = mocksGovernor;
anonymizeTournamentRecord
Replace personal information in a tournament record with generated mock data while preserving tournament structure.
Purpose
- Privacy compliance - Remove PII before sharing tournament data
- Test data creation - Create realistic test data from production tournaments
- Public examples - Share tournament structures without exposing participant identities
- Debugging - Anonymize production data for support investigations
Basic Usage
const anonymizedRecord = mocksGovernor.anonymizeTournamentRecord({
tournamentRecord, // Original tournament with real participant data
});
Complete Options
const anonymizedRecord = mocksGovernor.anonymizeTournamentRecord({
tournamentRecord, // Required - tournament to anonymize
// Optional - Override tournament identification
tournamentId, // New UUID for tournament (default: generates new)
tournamentName, // New name (default: generates name)
// Optional - Controlled mock person generation
personIds: [], // Array of UUIDs to use for replacement persons
// If not provided, new UUIDs are generated
// Optional - Extension handling
keepExtensions: [], // Array of extension names to preserve
// Use true to keep ALL extensions
// Use [] or false to remove all except internal extensions
// Optional - Name anonymization control
anonymizeParticipantNames: true, // Whether to replace participant names
// true = replace with mock names (default)
// false = preserve original names
});
What Gets Anonymized
Person information:
person.personId- New UUID generated (or from personIds array)person.standardFamilyName- Mock last nameperson.standardGivenName- Mock first nameperson.nationalityCode- Randomized
What's preserved:
- Tournament structure (events, draws, matchUps)
- Match results (scores, outcomes, winners)
- Seedings and rankings (numerical values)
- Scheduling and venues
- All IDs and references (updated consistently)
Example: Anonymize Production Data
import { tournamentEngine, mocksGovernor } from 'tods-competition-factory';
// Load production tournament
const productionTournament = await fetchTournamentData();
tournamentEngine.setState(productionTournament);
// Anonymize for public sharing
const anonymized = mocksGovernor.anonymizeTournamentRecord({
tournamentRecord: productionTournament,
tournamentName: 'Example Tournament 2024',
});
// Now safe to share - all personal info replaced
console.log(anonymized.participants[0].person.standardFamilyName); // 'Smith' (mocked)
Example: Create Test Fixture from Real Data
// Start with real tournament that had interesting edge case
const realTournament = loadRealTournamentWithEdgeCase();
// Anonymize and save as test fixture
const testFixture = mocksGovernor.anonymizeTournamentRecord({
tournamentRecord: realTournament,
tournamentId: 'edge-case-test-fixture',
tournamentName: 'Edge Case Test',
});
// Save for future tests
fs.writeFileSync('fixtures/edge-case.tods.json', JSON.stringify(testFixture));
Example: Preserve Specific Extensions
// Tournament with custom extensions
const { tournamentRecord } = mocksEngine.generateTournamentRecord({
drawProfiles: [{ drawSize: 16 }],
});
// Add custom extensions to participants
tournamentRecord.participants.forEach((participant) => {
participant.extensions = [
{ name: 'level', value: 'advanced' },
{ name: 'club', value: 'Tennis Club A' },
{ name: 'membershipId', value: '12345' },
];
});
// Anonymize but keep 'level' extension
const anonymized = mocksGovernor.anonymizeTournamentRecord({
tournamentRecord,
keepExtensions: ['level'], // Only 'level' preserved, 'club' and 'membershipId' removed
});
// Result: 'level' extensions intact, all others removed (except internal extensions)
Example: Preserve Names but Replace IDs
// When you want to preserve participant names but still anonymize IDs
const { tournamentRecord } = mocksEngine.generateTournamentRecord({
drawProfiles: [{ drawSize: 8 }],
});
const anonymized = mocksGovernor.anonymizeTournamentRecord({
tournamentRecord,
anonymizeParticipantNames: false, // Keep original names
});
// Result: All IDs changed, but participant names remain the same
// Useful for testing while maintaining recognizable names
Notes
- Deterministic generation: Using the same
personIdsarray produces the same mock names - Referential integrity: All participantIds and personIds are updated consistently throughout the tournament
- TODS compliance: Anonymized record is valid TODS schema
- Non-destructive: Original tournament record is not modified
modifyTournamentRecord
Add events and draws to an existing tournament record. This is useful for:
- Incrementally building complex tournaments in tests
- Adding draws to tournaments after initial generation
- Testing dynamic tournament modifications
- Simulating real-world tournament expansion
Purpose
Unlike generateTournamentRecord() which creates a complete tournament from scratch, modifyTournamentRecord() adds to an existing tournament while:
- Reusing existing participants (no duplication)
- Maintaining tournament context (dates, venues, etc.)
- Preserving existing events and draws
- Updating tournament structure incrementally
Basic Usage
// Start with existing tournament
const { tournamentRecord } = mocksEngine.generateTournamentRecord({
drawProfiles: [{ drawSize: 32, eventType: 'SINGLES' }],
});
// Add a doubles draw
mocksGovernor.modifyTournamentRecord({
tournamentRecord, // Modified in place
drawProfiles: [
{ drawSize: 16, eventType: 'DOUBLES' },
],
});
// Tournament now has both singles and doubles events
Complete Options
mocksGovernor.modifyTournamentRecord({
tournamentRecord, // Required - tournament to modify (modified in place)
// Add participants (if needed)
participantsProfile: {
participantsCount: 16,
participantType: 'PAIR',
},
// Add draws (creates new events)
drawProfiles: [
{
drawSize: 16,
drawType: 'SINGLE_ELIMINATION',
eventType: 'DOUBLES',
completionGoal: 8, // Complete first 8 matchUps
},
],
// Add draws to existing events
eventProfiles: [
{
eventId: 'existing-event-id', // Target specific event
// OR
eventName: 'U18 Singles', // Target by name
// OR
eventIndex: 0, // Target by index
drawProfiles: [
{ drawSize: 8, drawType: 'FEED_IN_CHAMPIONSHIP' },
],
},
],
// Add venues
venueProfiles: [
{ courtsCount: 4, venueName: 'Court Complex B' },
],
// Add scheduling
schedulingProfile: [
{ scheduleDate: '2024-06-02', venues: [/* ... */] },
],
// Match completion options
completeAllMatchUps: false,
randomWinningSide: false,
// IDs for generation
uuids: [], // Pre-defined UUIDs for new entities
});
Targeting Existing Events
Three ways to identify events for modification:
// 1. By eventId
eventProfiles: [
{
eventId: 'abc-123-def-456',
drawProfiles: [{ drawSize: 8 }],
},
]
// 2. By eventName
eventProfiles: [
{
eventName: 'U18 Singles',
drawProfiles: [{ drawSize: 8 }],
},
]
// 3. By eventIndex (zero-based)
eventProfiles: [
{
eventIndex: 0, // First event
drawProfiles: [{ drawSize: 8 }],
},
]
Example: Add Qualifying Draw
import { mocksEngine, mocksGovernor } from 'tods-competition-factory';
// Generate main tournament
const { tournamentRecord, eventIds } = mocksEngine.generateTournamentRecord({
eventProfiles: [
{
eventName: 'Singles',
drawProfiles: [{ drawSize: 32, drawName: 'Main Draw' }],
},
],
});
// Add qualifying draw to same event
mocksGovernor.modifyTournamentRecord({
tournamentRecord,
eventProfiles: [
{
eventId: eventIds[0], // Target existing event
drawProfiles: [
{
drawSize: 16,
drawName: 'Qualifying',
stage: 'QUALIFYING',
},
],
},
],
});
// Tournament now has Main Draw and Qualifying in same event
Example: Add Doubles to Singles Tournament
// Start with singles-only tournament
const { tournamentRecord } = mocksEngine.generateTournamentRecord({
drawProfiles: [{ drawSize: 32, eventType: 'SINGLES' }],
});
// Add doubles event
mocksGovernor.modifyTournamentRecord({
tournamentRecord,
participantsProfile: {
participantsCount: 16,
participantType: 'PAIR',
},
drawProfiles: [
{ drawSize: 16, eventType: 'DOUBLES' },
],
});
// Tournament now has both singles and doubles
console.log(tournamentRecord.events.length); // 2 events
Example: Progressive Tournament Building
// Build tournament incrementally
const { tournamentRecord } = mocksEngine.generateTournamentRecord({
tournamentName: 'Weekend Tournament',
startDate: '2024-06-01',
endDate: '2024-06-02',
});
// Day 1: Add singles
mocksGovernor.modifyTournamentRecord({
tournamentRecord,
drawProfiles: [
{ drawSize: 16, eventType: 'SINGLES', eventName: 'Saturday Singles' },
],
});
// Day 2: Add doubles
mocksGovernor.modifyTournamentRecord({
tournamentRecord,
participantsProfile: { participantType: 'PAIR', participantsCount: 8 },
drawProfiles: [
{ drawSize: 8, eventType: 'DOUBLES', eventName: 'Sunday Doubles' },
],
});
// Weekend tournament complete with progressive additions
Notes
- In-place modification: The supplied
tournamentRecordis directly modified (not copied) - Participant reuse: Existing participants are used when possible
- Event creation:
drawProfilescreates new events;eventProfilescan target existing events - No duplication: Won't create duplicate participants if they already exist
- Schema compliance: Modified tournament maintains TODS schema validity
Related Documentation
mocksEngine Documentation
For comprehensive testing capabilities, see:
- mocksEngine Overview - Introduction and capabilities
- Getting Started - Basic usage patterns
- Tournament Generation - Complete
generateTournamentRecord()documentation - Participant Generation - All participant generation options
- Outcome Generation - Match outcome and score generation
- Advanced Patterns - Common testing patterns and techniques