fix(#2): inject ITableauTokenProvider into WorkbookService#20
Conversation
WorkbookService previously declared `private readonly string _token` which was never assigned, causing every Tableau API call (GetAll, GetById, Publish, Delete) to send a null X-Tableau-Auth header and receive 401 Unauthorized. - Inject ITableauTokenProvider via constructor (matches ViewService, DataSourceService, PermissionService pattern) - Replace CreateClient(string token) with parameterless CreateClient() that calls _tokenProvider.GetToken() at request time - Remove the dead _token field Tests: 10 new unit tests in WorkbookServiceTests verify - Auth token is read from ITableauTokenProvider on each call - Correct X-Tableau-Auth header value is sent - 401 from the API surfaces as HttpRequestException - InvalidOperationException from an unset token propagates correctly Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughWorkbookService is refactored to inject ChangesToken Provider Injection and Testing
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
Closes #2
WorkbookServicedeclaredprivate readonly string _tokenwhich was never assigned. Every method calledCreateClient(_token)withnull, so theX-Tableau-Authheader was always empty — every workbook API call returned 401 Unauthorized.Root cause
The service was written without
ITableauTokenProviderinjection, unlikeViewService,DataSourceService, andPermissionServicewhich already use it correctly.Changes
WorkbookService.csprivate readonly string _tokenfieldITableauTokenProvidervia constructorCreateClient(string token)with parameterlessCreateClient()that calls_tokenProvider.GetToken()at request time — matches the pattern inViewServiceWorkbookServiceTests.cs(new — 10 tests)ITableauTokenProvideron every call (GetAll,GetById,Delete)X-Tableau-Authheader value is sent in each requestHttpRequestExceptionInvalidOperationExceptionfrom an unset token provider propagates correctly404from the API surfaces asHttpRequestExceptionTest results
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
Refactor
Tests