Skip to content

Commit a633693

Browse files
Jonas Saabelclaude
andcommitted
fix: resolve unit test performance issue and update documentation
## Critical Fixes ### Unit Test Performance (src/main/kotlin/it/saabel/kotlinnotionclient/NotionClient.kt) - Fixed critical bug where unit tests timed out (2+ minutes → 400ms) - Root cause: `createWithClient()` used reflection and created real HTTP client before replacing with mock - Solution: Refactored to use constructor-based dependency injection - Removed reflection hack, now uses clean `@JvmOverloads` constructor pattern - Tests now complete in ~400ms as expected for mocked tests ### Client Instantiation Pattern - Made primary constructor public with optional HttpClient parameter - Supports both patterns: - `NotionClient(apiToken)` - Direct constructor (idiomatic Kotlin) - `NotionClient.create(apiToken)` - Factory method (also supported) - No deprecation - both are first-class citizens ## Documentation Updates ### Updated All Documentation to Constructor Pattern - README.md: Added client initialization section, shows both patterns - QUICKSTART.md: Updated examples, fixed old package name (no.saabelit → it.saabel) - docs/*.md: Updated 6 API doc files (blocks, error-handling, notebooks, search, testing, users) - All examples now use `NotionClient(token)` as primary pattern - Clearly documents that both patterns are fully supported ### Integration Tests - Updated 13 integration test files to use constructor pattern - Files: All pagination tests, DataSourcesIntegrationTest, DatabaseQueryIntegrationTest, EnhancedFileUploadIntegrationTest, NotionClientIntegrationTest, RateLimitVerificationTest - Pattern: `NotionClient.create(NotionConfig(...))` → `NotionClient(NotionConfig(...))` ## Developer Experience Improvements - Added journal entry documenting DX exploration session findings - Removed obsolete phase completion files (PHASE1_COMPLETE.md, PRE_PUBLICATION_SECURITY_REVIEW.md, README-DRAFT.md) - Added docs/notebooks.md for Jupyter notebook integration examples ## Verification - ✅ All unit tests pass (~400ms execution time) - ✅ Build succeeds - ✅ Documentation consistent across all files - ✅ Both instantiation patterns work correctly 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 3229147 commit a633693

40 files changed

+1021
-863
lines changed

PHASE1_COMPLETE.md

Lines changed: 0 additions & 149 deletions
This file was deleted.

PRE_PUBLICATION_SECURITY_REVIEW.md

Lines changed: 0 additions & 123 deletions
This file was deleted.

QUICKSTART.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ Get started with the Kotlin Notion Client in under 5 minutes.
1717
1818
```kotlin
1919
dependencies {
20-
implementation("no.saabelit:kotlin-notion-client:0.1.0")
20+
implementation("it.saabel:kotlin-notion-client:0.1.0")
2121
}
2222
```
2323

2424
## Your First API Call
2525

2626
```kotlin
27-
import no.saabelit.kotlinnotionclient.NotionClient
27+
import it.saabel.kotlinnotionclient.NotionClient
2828

2929
fun main() = runBlocking {
3030
// Initialize the client
31-
val notion = NotionClient.create("your-api-token")
31+
val notion = NotionClient("your-api-token")
3232

3333
// Get current user (verifies token works)
3434
val user = notion.users.getCurrentUser()
@@ -39,6 +39,26 @@ fun main() = runBlocking {
3939
}
4040
```
4141

42+
### Client Initialization
43+
44+
You can create a `NotionClient` instance using either pattern:
45+
46+
```kotlin
47+
// 1. Direct constructor (recommended - idiomatic Kotlin)
48+
val notion = NotionClient("your-api-token")
49+
50+
// 2. Factory method (also supported)
51+
val notion = NotionClient.create("your-api-token")
52+
53+
// With custom configuration
54+
val notion = NotionClient(
55+
NotionConfig(
56+
apiToken = "your-api-token",
57+
logLevel = LogLevel.INFO
58+
)
59+
)
60+
```
61+
4262
## Understanding the 2025-09-03 API
4363

4464
**Important**: Before going further, understand this key concept:
@@ -226,7 +246,7 @@ notion.close()
226246
Or use `.use` for automatic cleanup:
227247

228248
```kotlin
229-
NotionClient.create("token").use { notion ->
249+
NotionClient("token").use { notion ->
230250
// Your code here
231251
}
232252
```

0 commit comments

Comments
 (0)