Restructure the monorepo into clear top-level directories: - backend/: Go module root (cmd, internal, pkg, configs, migrations, docs/swagger, scripts, tests, go.mod, Makefile, .air.toml) - deploy/: Docker (Dockerfile, docker-compose*), quickstart, fluentd - docs/: project documentation + reports/ (moved from repo root) - AGENTS.md: new AI coding-agent guide at repo root Update all references to the new layout: - Dockerfile: COPY backend/go.mod, COPY backend/ (context = repo root) - docker-compose files: context ../.., dockerfile deploy/docker/Dockerfile, env_file ../../.env, volume mounts ../../backend:/app - deploy/quickstart/compose.yaml: dockerfile deploy/docker/Dockerfile - CI: working-directory: backend for go commands, file deploy/docker/Dockerfile, coverage path backend/coverage.out, health_check backend/scripts/ - backend/Makefile: docker target uses -f ../deploy/docker/Dockerfile ../ - README: architecture tree, quickstart, config paths updated Move root stray scripts (rename_models.*, run_m11_tests.sh, verify_build.sh, gorm_bool_main.go) to backend/scripts/legacy/. All moves via git mv to preserve history. Build, vet, SQLite tests, and docker compose config verified.
187 lines
5.9 KiB
Plaintext
187 lines
5.9 KiB
Plaintext
package v1
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/gochat/gochat/internal/service"
|
|
)
|
|
|
|
func setupLinearIntegrationRouter() *gin.Engine {
|
|
gin.SetMode(gin.TestMode)
|
|
r := gin.New()
|
|
r.RedirectTrailingSlash = false
|
|
handler := NewLinearIntegrationHandler(nil)
|
|
|
|
integrations := r.Group("/api/v1/accounts/:account_id/integrations")
|
|
RegisterLinearIntegrationRoutes(integrations, handler)
|
|
|
|
return r
|
|
}
|
|
|
|
// ========================================
|
|
// LinearIntegration — param validation tests
|
|
// ========================================
|
|
|
|
func TestLinearIntegration_Delete_BadAccountID(t *testing.T) {
|
|
r := setupLinearIntegrationRouter()
|
|
|
|
w := httptest.NewRecorder()
|
|
req, _ := http.NewRequest("DELETE", "/api/v1/accounts/abc/integrations/linear/", nil)
|
|
r.ServeHTTP(w, req)
|
|
|
|
assert.Equal(t, http.StatusBadRequest, w.Code)
|
|
|
|
var resp map[string]interface{}
|
|
json.Unmarshal(w.Body.Bytes(), &resp)
|
|
errBody := resp["error"].(map[string]interface{})
|
|
assert.Contains(t, errBody["message"], "invalid account_id")
|
|
}
|
|
|
|
func TestLinearIntegration_GetTeams_BadAccountID(t *testing.T) {
|
|
r := setupLinearIntegrationRouter()
|
|
|
|
w := httptest.NewRecorder()
|
|
req, _ := http.NewRequest("GET", "/api/v1/accounts/abc/integrations/linear/teams", nil)
|
|
r.ServeHTTP(w, req)
|
|
|
|
assert.Equal(t, http.StatusBadRequest, w.Code)
|
|
|
|
var resp map[string]interface{}
|
|
json.Unmarshal(w.Body.Bytes(), &resp)
|
|
errBody := resp["error"].(map[string]interface{})
|
|
assert.Contains(t, errBody["message"], "invalid account_id")
|
|
}
|
|
|
|
func TestLinearIntegration_GetTeamEntities_BadAccountID(t *testing.T) {
|
|
r := setupLinearIntegrationRouter()
|
|
|
|
w := httptest.NewRecorder()
|
|
req, _ := http.NewRequest("GET", "/api/v1/accounts/abc/integrations/linear/team_entities", nil)
|
|
r.ServeHTTP(w, req)
|
|
|
|
assert.Equal(t, http.StatusBadRequest, w.Code)
|
|
|
|
var resp map[string]interface{}
|
|
json.Unmarshal(w.Body.Bytes(), &resp)
|
|
errBody := resp["error"].(map[string]interface{})
|
|
assert.Contains(t, errBody["message"], "invalid account_id")
|
|
}
|
|
|
|
func TestLinearIntegration_CreateIssue_BadAccountID(t *testing.T) {
|
|
r := setupLinearIntegrationRouter()
|
|
|
|
body, _ := json.Marshal(service.CreateLinearIssueRequest{TeamID: "team1", Identifier: "GO-1", Title: "Bug"})
|
|
w := httptest.NewRecorder()
|
|
req, _ := http.NewRequest("POST", "/api/v1/accounts/abc/integrations/linear/create_issue", bytes.NewReader(body))
|
|
req.Header.Set("Content-Type", "application/json")
|
|
r.ServeHTTP(w, req)
|
|
|
|
assert.Equal(t, http.StatusBadRequest, w.Code)
|
|
|
|
var resp map[string]interface{}
|
|
json.Unmarshal(w.Body.Bytes(), &resp)
|
|
errBody := resp["error"].(map[string]interface{})
|
|
assert.Contains(t, errBody["message"], "invalid account_id")
|
|
}
|
|
|
|
func TestLinearIntegration_CreateIssue_InvalidJSON(t *testing.T) {
|
|
r := setupLinearIntegrationRouter()
|
|
|
|
w := httptest.NewRecorder()
|
|
req, _ := http.NewRequest("POST", "/api/v1/accounts/1/integrations/linear/create_issue", bytes.NewReader([]byte("invalid json")))
|
|
req.Header.Set("Content-Type", "application/json")
|
|
r.ServeHTTP(w, req)
|
|
|
|
assert.Equal(t, http.StatusBadRequest, w.Code)
|
|
|
|
var resp map[string]interface{}
|
|
json.Unmarshal(w.Body.Bytes(), &resp)
|
|
assert.False(t, resp["success"].(bool))
|
|
}
|
|
|
|
func TestLinearIntegration_LinkIssue_BadAccountID(t *testing.T) {
|
|
r := setupLinearIntegrationRouter()
|
|
|
|
body, _ := json.Marshal(service.LinkLinearIssueRequest{IssueID: "issue1", ConversationID: 1})
|
|
w := httptest.NewRecorder()
|
|
req, _ := http.NewRequest("POST", "/api/v1/accounts/abc/integrations/linear/link_issue", bytes.NewReader(body))
|
|
req.Header.Set("Content-Type", "application/json")
|
|
r.ServeHTTP(w, req)
|
|
|
|
assert.Equal(t, http.StatusBadRequest, w.Code)
|
|
|
|
var resp map[string]interface{}
|
|
json.Unmarshal(w.Body.Bytes(), &resp)
|
|
errBody := resp["error"].(map[string]interface{})
|
|
assert.Contains(t, errBody["message"], "invalid account_id")
|
|
}
|
|
|
|
func TestLinearIntegration_LinkIssue_InvalidJSON(t *testing.T) {
|
|
r := setupLinearIntegrationRouter()
|
|
|
|
w := httptest.NewRecorder()
|
|
req, _ := http.NewRequest("POST", "/api/v1/accounts/1/integrations/linear/link_issue", bytes.NewReader([]byte("invalid json")))
|
|
req.Header.Set("Content-Type", "application/json")
|
|
r.ServeHTTP(w, req)
|
|
|
|
assert.Equal(t, http.StatusBadRequest, w.Code)
|
|
|
|
var resp map[string]interface{}
|
|
json.Unmarshal(w.Body.Bytes(), &resp)
|
|
assert.False(t, resp["success"].(bool))
|
|
}
|
|
|
|
func TestLinearIntegration_UnlinkIssue_BadAccountID(t *testing.T) {
|
|
r := setupLinearIntegrationRouter()
|
|
|
|
body, _ := json.Marshal(service.UnlinkLinearIssueRequest{IssueID: "issue1", ConversationID: 1})
|
|
w := httptest.NewRecorder()
|
|
req, _ := http.NewRequest("POST", "/api/v1/accounts/abc/integrations/linear/unlink_issue", bytes.NewReader(body))
|
|
req.Header.Set("Content-Type", "application/json")
|
|
r.ServeHTTP(w, req)
|
|
|
|
assert.Equal(t, http.StatusBadRequest, w.Code)
|
|
|
|
var resp map[string]interface{}
|
|
json.Unmarshal(w.Body.Bytes(), &resp)
|
|
errBody := resp["error"].(map[string]interface{})
|
|
assert.Contains(t, errBody["message"], "invalid account_id")
|
|
}
|
|
|
|
func TestLinearIntegration_SearchIssue_BadAccountID(t *testing.T) {
|
|
r := setupLinearIntegrationRouter()
|
|
|
|
w := httptest.NewRecorder()
|
|
req, _ := http.NewRequest("GET", "/api/v1/accounts/abc/integrations/linear/search_issue", nil)
|
|
r.ServeHTTP(w, req)
|
|
|
|
assert.Equal(t, http.StatusBadRequest, w.Code)
|
|
|
|
var resp map[string]interface{}
|
|
json.Unmarshal(w.Body.Bytes(), &resp)
|
|
errBody := resp["error"].(map[string]interface{})
|
|
assert.Contains(t, errBody["message"], "invalid account_id")
|
|
}
|
|
|
|
func TestLinearIntegration_GetLinkedIssues_BadAccountID(t *testing.T) {
|
|
r := setupLinearIntegrationRouter()
|
|
|
|
w := httptest.NewRecorder()
|
|
req, _ := http.NewRequest("GET", "/api/v1/accounts/abc/integrations/linear/linked_issues", nil)
|
|
r.ServeHTTP(w, req)
|
|
|
|
assert.Equal(t, http.StatusBadRequest, w.Code)
|
|
|
|
var resp map[string]interface{}
|
|
json.Unmarshal(w.Body.Bytes(), &resp)
|
|
errBody := resp["error"].(map[string]interface{})
|
|
assert.Contains(t, errBody["message"], "invalid account_id")
|
|
}
|