Skip to content

Comments

refactor: improve type safety and DRY up codebase#6

Merged
akisma merged 4 commits intomainfrom
feature/refactor
Jan 7, 2026
Merged

refactor: improve type safety and DRY up codebase#6
akisma merged 4 commits intomainfrom
feature/refactor

Conversation

@akisma
Copy link
Owner

@akisma akisma commented Jan 7, 2026

Remove index signatures from 16 interfaces, extract shared utils (datetime, validation), add mock client factory, delete deprecated createOAuthClientFromEnv

Remove index signatures from 16 interfaces, extract shared utils (datetime, validation), add mock client factory, delete deprecated createOAuthClientFromEnv
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves code quality and type safety by removing index signatures from 16 interfaces, extracting shared utilities (datetime and validation), adding a mock client factory for testing, and deleting the deprecated createOAuthClientFromEnv function. The changes reduce code duplication and make the codebase more maintainable with explicit type definitions.

Key changes:

  • Replaced [key: string]: unknown index signatures with explicit extra?: Record<string, unknown> fields in 16 interfaces
  • Extracted localTimeToUtc utility function to src/utils/datetime.ts (used in 2 locations)
  • Created validateTourId utility function in src/utils/validation.ts (used in 4 tool functions)
  • Added createMockClient factory and mock response helpers in src/testing/mockClient.ts
  • Removed deprecated createOAuthClientFromEnv function and its tests
  • Updated createScheduleItem return type to include syncId field

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/utils/validation.ts New utility for tour ID validation with comprehensive test coverage
src/utils/datetime.ts New utility extracting timezone conversion logic from multiple files
src/testing/mockClient.ts New mock client factory for test utilities with response builders
tests/unit/validation.test.ts Complete test coverage for validateTourId utility (4 test cases)
tests/unit/datetime.test.ts Complete test coverage for localTimeToUtc utility (7 test cases)
tests/unit/mockClient.test.ts Complete test coverage for mock utilities (7 test cases)
src/api/client.ts Removed index signatures from 16 interfaces, added explicit fields and extra property for type safety
src/tools/addScheduleItem.ts Updated to use shared localTimeToUtc utility
src/tools/updateScheduleItem.ts Updated to use shared localTimeToUtc utility
src/tools/getTourHotels.ts Updated to use shared validateTourId utility
src/tools/getTourEvents.ts Updated to use shared validateTourId utility
src/tools/getTourCrew.ts Updated to use shared validateTourId utility
src/tools/getTodaySchedule.ts Updated to use shared validateTourId utility
src/auth/oauth.ts Removed deprecated createOAuthClientFromEnv function
tests/unit/auth.test.ts Removed tests for deprecated function
tests/unit/addScheduleItem.test.ts Updated mock return value to include syncId field
src/types/mastertour.ts Deleted unused legacy type definitions file
src/types/index.ts Updated export to point to outputs.js instead of mastertour.js
docs/TECHNICAL_DOCUMENTATION.md Updated project structure documentation
docs/PROJECT_STATUS_EXPANDED.md Updated status with completion of code quality refactoring

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +39 to +52
export function createMockClient(overrides?: Partial<Record<keyof MasterTourClient, MockFn>>): MockClient {
return {
listTours: vi.fn(),
getDay: vi.fn(),
getTourSummary: vi.fn(),
getTourHotels: vi.fn(),
getTourCrew: vi.fn(),
getTourEvents: vi.fn(),
createScheduleItem: vi.fn(),
updateScheduleItem: vi.fn(),
deleteScheduleItem: vi.fn(),
updateDayNotes: vi.fn(),
...overrides,
} as MockClient;
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The createMockClient function is missing mock implementations for getTourAll and getDayEvents methods that are defined in the MasterTourClient interface. While these may not be used in current tests, for completeness and to avoid potential runtime errors, all interface methods should be mocked.

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Comment on lines +16 to +27
export type MockClient = MasterTourClient & {
listTours: MockFn;
getDay: MockFn;
getTourSummary: MockFn;
getTourHotels: MockFn;
getTourCrew: MockFn;
getTourEvents: MockFn;
createScheduleItem: MockFn;
updateScheduleItem: MockFn;
deleteScheduleItem: MockFn;
updateDayNotes: MockFn;
};
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MockClient type definition is missing getTourAll and getDayEvents method signatures. These methods are part of the MasterTourClient interface and should be included in the MockClient type to maintain type consistency.

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

akisma and others added 2 commits January 6, 2026 18:49
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI commented Jan 7, 2026

@akisma I've opened a new pull request, #7, to work on those changes. Once the pull request is ready, I'll request review from you.

[WIP] Address feedback on type safety and DRY refactor improvements
@akisma akisma merged commit 2b250b5 into main Jan 7, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants