test: Add comprehensive test suite with fixtures

Establishes testing infrastructure for reliable development.

tests/fixtures/ - GitLab API response samples:
- gitlab_issue.json: Single issue with full metadata
- gitlab_issues_page.json: Paginated issue list response
- gitlab_discussion.json: Discussion thread with notes
- gitlab_discussions_page.json: Paginated discussions response
All fixtures captured from real GitLab API responses with
sensitive data redacted, ensuring tests match actual behavior.

tests/gitlab_types_tests.rs - Type deserialization tests:
- Validates serde parsing of all GitLab API types
- Tests edge cases: null fields, empty arrays, nested objects
- Ensures GitLabIssue, GitLabDiscussion, GitLabNote parse correctly
- Verifies optional fields handle missing data gracefully
- Tests author/assignee extraction from various formats

tests/fixture_tests.rs - Integration with fixtures:
- Loads fixture files and validates parsing
- Tests transformer functions produce correct database rows
- Verifies IssueWithMetadata extracts labels and assignees
- Tests NormalizedDiscussion/NormalizedNote structure
- Validates raw payload preservation logic

tests/migration_tests.rs - Database schema tests:
- Creates in-memory SQLite for isolation
- Runs all migrations and verifies schema
- Tests table creation with expected columns
- Validates foreign key constraints
- Tests index creation for query performance
- Verifies idempotent migration behavior

Test infrastructure uses:
- tempfile for isolated database instances
- wiremock for HTTP mocking (available for future API tests)
- Standard Rust #[test] attributes

Run with: cargo test
Run single: cargo test test_name
Run with output: cargo test -- --nocapture

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Taylor Eernisse
2026-01-26 11:29:06 -05:00
parent 8fb890c528
commit f53645790a
7 changed files with 1228 additions and 0 deletions

117
tests/fixtures/gitlab_issues_page.json vendored Normal file
View File

@@ -0,0 +1,117 @@
[
{
"id": 12345,
"iid": 42,
"project_id": 100,
"title": "First test issue",
"description": "Description for first issue",
"state": "opened",
"created_at": "2024-01-15T10:00:00.000Z",
"updated_at": "2024-01-20T15:30:00.000Z",
"closed_at": null,
"author": {
"id": 1,
"username": "testuser",
"name": "Test User"
},
"assignees": [
{
"id": 2,
"username": "assignee1",
"name": "Assignee One"
}
],
"labels": ["bug", "priority::high"],
"milestone": {
"id": 500,
"iid": 5,
"project_id": 100,
"title": "v1.0",
"state": "active",
"due_date": "2024-02-01"
},
"due_date": "2024-01-31",
"web_url": "https://gitlab.example.com/group/project/-/issues/42"
},
{
"id": 12346,
"iid": 43,
"project_id": 100,
"title": "Second test issue with empty labels",
"description": null,
"state": "closed",
"created_at": "2024-01-16T09:00:00.000Z",
"updated_at": "2024-01-21T12:00:00.000Z",
"closed_at": "2024-01-21T12:00:00.000Z",
"author": {
"id": 2,
"username": "anotheruser",
"name": "Another User"
},
"assignees": [],
"labels": [],
"milestone": null,
"due_date": null,
"web_url": "https://gitlab.example.com/group/project/-/issues/43"
},
{
"id": 12347,
"iid": 44,
"project_id": 100,
"title": "Third test issue",
"description": "This issue has multiple labels for testing",
"state": "opened",
"created_at": "2024-01-17T14:30:00.000Z",
"updated_at": "2024-01-22T08:45:00.000Z",
"closed_at": null,
"author": {
"id": 1,
"username": "testuser",
"name": "Test User"
},
"assignees": [
{
"id": 1,
"username": "testuser",
"name": "Test User"
},
{
"id": 3,
"username": "thirduser",
"name": "Third User"
}
],
"labels": ["feature", "frontend", "needs-review", "priority::medium"],
"milestone": {
"id": 501,
"iid": 6,
"project_id": 100,
"title": "v1.1",
"state": "active",
"due_date": "2024-03-01"
},
"due_date": null,
"web_url": "https://gitlab.example.com/group/project/-/issues/44"
},
{
"id": 12348,
"iid": 45,
"project_id": 100,
"title": "Fourth test issue for pagination",
"description": "Extra issue to ensure we have enough for pagination tests",
"state": "opened",
"created_at": "2024-01-18T11:00:00.000Z",
"updated_at": "2024-01-23T16:20:00.000Z",
"closed_at": null,
"author": {
"id": 3,
"username": "thirduser",
"name": "Third User"
},
"assignees": [],
"labels": ["documentation"],
"milestone": null,
"due_date": "2024-02-28",
"web_url": "https://gitlab.example.com/group/project/-/issues/45"
}
]