Skip to content

Commit 714f122

Browse files
committed
fix: missing database integration test
1 parent c5e41e9 commit 714f122

File tree

2 files changed

+57
-53
lines changed

2 files changed

+57
-53
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ test-unit: ## Run unit tests
3535
@echo "Running unit tests with race detection..."
3636
CGO_ENABLED=1 go test -short -race -v ./backend/internal/... ./backend/pkg/... ./backend/cmd/...
3737

38-
test-integration: ## Run integration tests (requires PostgreSQL - migrations are applied automatically)
38+
test-integration: ## Run integration tests (DB + admin; requires PostgreSQL - migrations applied automatically)
3939
@echo "Running integration tests with race detection..."
4040
@echo "Note: Migrations are applied automatically by test setup"
4141
@export INTEGRATION_TESTS=1; \
4242
export ACKIFY_DB_DSN="postgres://postgres:testpassword@localhost:5432/ackify_test?sslmode=disable"; \
43-
CGO_ENABLED=1 go test -v -race -tags=integration ./backend/internal/infrastructure/database/...
43+
CGO_ENABLED=1 go test -v -race -tags=integration ./backend/internal/infrastructure/database/... ./backend/internal/presentation/api/admin
4444

4545
test-integration-setup: ## Setup test database for integration tests (migrations applied by tests)
4646
@echo "Setting up test database..."
@@ -66,7 +66,7 @@ coverage-integration: ## Generate integration test coverage report
6666
@mkdir -p $(COVERAGE_DIR)
6767
@export ACKIFY_DB_DSN="postgres://postgres:testpassword@localhost:5432/ackify_test?sslmode=disable"; \
6868
export INTEGRATION_TESTS=1; \
69-
CGO_ENABLED=1 go test -v -race -tags=integration -coverprofile=$(COVERAGE_DIR)/coverage-integration.out ./backend/internal/infrastructure/database/...
69+
CGO_ENABLED=1 go test -v -race -tags=integration -coverprofile=$(COVERAGE_DIR)/coverage-integration.out ./backend/internal/infrastructure/database/... ./backend/internal/presentation/api/admin
7070
go tool cover -html=$(COVERAGE_DIR)/coverage-integration.out -o $(COVERAGE_DIR)/coverage-integration.html
7171
@echo "Integration coverage report generated: $(COVERAGE_DIR)/coverage-integration.html"
7272

@@ -78,7 +78,7 @@ coverage-all: ## Generate full coverage report (unit + integration merged)
7878
@echo "Step 2/3: Running integration tests with coverage..."
7979
@export ACKIFY_DB_DSN="postgres://postgres:testpassword@localhost:5432/ackify_test?sslmode=disable"; \
8080
export INTEGRATION_TESTS=1; \
81-
CGO_ENABLED=1 go test -v -race -tags=integration -coverprofile=$(COVERAGE_DIR)/coverage-integration.out ./backend/internal/infrastructure/database/...
81+
CGO_ENABLED=1 go test -v -race -tags=integration -coverprofile=$(COVERAGE_DIR)/coverage-integration.out ./backend/internal/infrastructure/database/... ./backend/internal/presentation/api/admin
8282
@echo "Step 3/3: Merging coverage files..."
8383
@echo "mode: atomic" > $(COVERAGE_DIR)/coverage-all.out
8484
@grep -h -v "^mode:" $(COVERAGE_DIR)/coverage-unit.out $(COVERAGE_DIR)/coverage-integration.out >> $(COVERAGE_DIR)/coverage-all.out || true

backend/internal/presentation/api/admin/handler_test.go

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -107,25 +107,27 @@ func TestAdminHandler_GetDocumentStatus_WithUnexpectedSignatures(t *testing.T) {
107107
t.Fatalf("Expected status 200, got %d", w.Code)
108108
}
109109

110-
// Parse response
110+
// Parse response (API responses are wrapped under {"data": ...})
111111
var response struct {
112-
DocID string `json:"docId"`
113-
ExpectedSigners []struct {
114-
Email string `json:"email"`
115-
HasSigned bool `json:"hasSigned"`
116-
} `json:"expectedSigners"`
117-
UnexpectedSignatures []struct {
118-
UserEmail string `json:"userEmail"`
119-
UserName *string `json:"userName,omitempty"`
120-
SignedAtUTC string `json:"signedAtUTC"`
121-
} `json:"unexpectedSignatures"`
122-
Stats struct {
123-
ExpectedCount int `json:"expectedCount"`
124-
SignedCount int `json:"signedCount"`
125-
PendingCount int `json:"pendingCount"`
126-
CompletionRate float64 `json:"completionRate"`
127-
} `json:"stats"`
128-
ShareLink string `json:"shareLink"`
112+
Data struct {
113+
DocID string `json:"docId"`
114+
ExpectedSigners []struct {
115+
Email string `json:"email"`
116+
HasSigned bool `json:"hasSigned"`
117+
} `json:"expectedSigners"`
118+
UnexpectedSignatures []struct {
119+
UserEmail string `json:"userEmail"`
120+
UserName *string `json:"userName,omitempty"`
121+
SignedAtUTC string `json:"signedAtUTC"`
122+
} `json:"unexpectedSignatures"`
123+
Stats struct {
124+
ExpectedCount int `json:"expectedCount"`
125+
SignedCount int `json:"signedCount"`
126+
PendingCount int `json:"pendingCount"`
127+
CompletionRate float64 `json:"completionRate"`
128+
} `json:"stats"`
129+
ShareLink string `json:"shareLink"`
130+
} `json:"data"`
129131
}
130132

131133
err = json.NewDecoder(w.Body).Decode(&response)
@@ -134,48 +136,48 @@ func TestAdminHandler_GetDocumentStatus_WithUnexpectedSignatures(t *testing.T) {
134136
}
135137

136138
// Verify response
137-
if response.DocID != docID {
138-
t.Errorf("Expected docId %s, got %s", docID, response.DocID)
139+
if response.Data.DocID != docID {
140+
t.Errorf("Expected docId %s, got %s", docID, response.Data.DocID)
139141
}
140142

141143
// Check expected signers
142-
if len(response.ExpectedSigners) != 1 {
143-
t.Errorf("Expected 1 expected signer, got %d", len(response.ExpectedSigners))
144+
if len(response.Data.ExpectedSigners) != 1 {
145+
t.Errorf("Expected 1 expected signer, got %d", len(response.Data.ExpectedSigners))
144146
} else {
145-
if response.ExpectedSigners[0].Email != "expected@example.com" {
146-
t.Errorf("Expected email 'expected@example.com', got '%s'", response.ExpectedSigners[0].Email)
147+
if response.Data.ExpectedSigners[0].Email != "expected@example.com" {
148+
t.Errorf("Expected email 'expected@example.com', got '%s'", response.Data.ExpectedSigners[0].Email)
147149
}
148-
if !response.ExpectedSigners[0].HasSigned {
150+
if !response.Data.ExpectedSigners[0].HasSigned {
149151
t.Error("Expected signer should have signed")
150152
}
151153
}
152154

153155
// Check unexpected signatures
154-
if len(response.UnexpectedSignatures) != 1 {
155-
t.Fatalf("Expected 1 unexpected signature, got %d", len(response.UnexpectedSignatures))
156+
if len(response.Data.UnexpectedSignatures) != 1 {
157+
t.Fatalf("Expected 1 unexpected signature, got %d", len(response.Data.UnexpectedSignatures))
156158
}
157-
if response.UnexpectedSignatures[0].UserEmail != "unexpected@example.com" {
158-
t.Errorf("Expected unexpected email 'unexpected@example.com', got '%s'", response.UnexpectedSignatures[0].UserEmail)
159+
if response.Data.UnexpectedSignatures[0].UserEmail != "unexpected@example.com" {
160+
t.Errorf("Expected unexpected email 'unexpected@example.com', got '%s'", response.Data.UnexpectedSignatures[0].UserEmail)
159161
}
160-
if response.UnexpectedSignatures[0].UserName == nil || *response.UnexpectedSignatures[0].UserName != "Unexpected User" {
162+
if response.Data.UnexpectedSignatures[0].UserName == nil || *response.Data.UnexpectedSignatures[0].UserName != "Unexpected User" {
161163
t.Error("Expected unexpected userName to be 'Unexpected User'")
162164
}
163165

164166
// Check stats
165-
if response.Stats.ExpectedCount != 1 {
166-
t.Errorf("Expected expectedCount 1, got %d", response.Stats.ExpectedCount)
167+
if response.Data.Stats.ExpectedCount != 1 {
168+
t.Errorf("Expected expectedCount 1, got %d", response.Data.Stats.ExpectedCount)
167169
}
168-
if response.Stats.SignedCount != 1 {
169-
t.Errorf("Expected signedCount 1, got %d", response.Stats.SignedCount)
170+
if response.Data.Stats.SignedCount != 1 {
171+
t.Errorf("Expected signedCount 1, got %d", response.Data.Stats.SignedCount)
170172
}
171-
if response.Stats.CompletionRate != 100.0 {
172-
t.Errorf("Expected completionRate 100.0, got %f", response.Stats.CompletionRate)
173+
if response.Data.Stats.CompletionRate != 100.0 {
174+
t.Errorf("Expected completionRate 100.0, got %f", response.Data.Stats.CompletionRate)
173175
}
174176

175177
// Check share link
176178
expectedShareLink := "https://example.com/?doc=" + docID
177-
if response.ShareLink != expectedShareLink {
178-
t.Errorf("Expected shareLink '%s', got '%s'", expectedShareLink, response.ShareLink)
179+
if response.Data.ShareLink != expectedShareLink {
180+
t.Errorf("Expected shareLink '%s', got '%s'", expectedShareLink, response.Data.ShareLink)
179181
}
180182
}
181183

@@ -228,12 +230,14 @@ func TestAdminHandler_GetDocumentStatus_NoExpectedSigners(t *testing.T) {
228230
t.Fatalf("Expected status 200, got %d", w.Code)
229231
}
230232

231-
// Parse response
233+
// Parse response (wrapped in {"data": ...})
232234
var response struct {
233-
ExpectedSigners []interface{} `json:"expectedSigners"`
234-
UnexpectedSignatures []struct {
235-
UserEmail string `json:"userEmail"`
236-
} `json:"unexpectedSignatures"`
235+
Data struct {
236+
ExpectedSigners []interface{} `json:"expectedSigners"`
237+
UnexpectedSignatures []struct {
238+
UserEmail string `json:"userEmail"`
239+
} `json:"unexpectedSignatures"`
240+
} `json:"data"`
237241
}
238242

239243
err = json.NewDecoder(w.Body).Decode(&response)
@@ -242,15 +246,15 @@ func TestAdminHandler_GetDocumentStatus_NoExpectedSigners(t *testing.T) {
242246
}
243247

244248
// Verify response
245-
if len(response.ExpectedSigners) != 0 {
246-
t.Errorf("Expected 0 expected signers, got %d", len(response.ExpectedSigners))
249+
if len(response.Data.ExpectedSigners) != 0 {
250+
t.Errorf("Expected 0 expected signers, got %d", len(response.Data.ExpectedSigners))
247251
}
248252

249253
// All signatures should be unexpected since there are no expected signers
250-
if len(response.UnexpectedSignatures) != 1 {
251-
t.Fatalf("Expected 1 unexpected signature, got %d", len(response.UnexpectedSignatures))
254+
if len(response.Data.UnexpectedSignatures) != 1 {
255+
t.Fatalf("Expected 1 unexpected signature, got %d", len(response.Data.UnexpectedSignatures))
252256
}
253-
if response.UnexpectedSignatures[0].UserEmail != "user@example.com" {
254-
t.Errorf("Expected email 'user@example.com', got '%s'", response.UnexpectedSignatures[0].UserEmail)
257+
if response.Data.UnexpectedSignatures[0].UserEmail != "user@example.com" {
258+
t.Errorf("Expected email 'user@example.com', got '%s'", response.Data.UnexpectedSignatures[0].UserEmail)
255259
}
256260
}

0 commit comments

Comments
 (0)