Files
skrueckenandCursor 98d2253f44
CI / test-and-build (push) Failing after 1m19s
CI / demo (push) Skipped
Add YouTrack pull/push sync with project settings and time tracking.
Wire manual Y menu and CLI sync for issues and work items, persist
per-project credentials, and keep local edits until an explicit push.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-24 00:17:51 +02:00

71 lines
1.6 KiB
Go

package project_test
import (
"os"
"path/filepath"
"testing"
"task/internal/project"
)
func TestMetaSaveLoad(t *testing.T) {
dir := t.TempDir()
store := project.NewDirStore(dir)
if err := store.Ensure("inbox"); err != nil {
t.Fatal(err)
}
meta := project.Meta{
YouTrack: &project.YouTrack{
BaseURL: "https://yt.example.com",
Token: "perm:secret",
ProjectKey: "PROJ",
},
}
if err := store.SaveMeta("inbox", meta); err != nil {
t.Fatalf("SaveMeta: %v", err)
}
path := filepath.Join(dir, "projects", "inbox", "meta.json")
st, err := os.Stat(path)
if err != nil {
t.Fatalf("stat: %v", err)
}
if st.Mode().Perm()&0o077 != 0 {
t.Fatalf("meta permissions too open: %o", st.Mode().Perm())
}
got, err := store.LoadMeta("inbox")
if err != nil {
t.Fatalf("LoadMeta: %v", err)
}
if got.YouTrack == nil || got.YouTrack.Token != "perm:secret" || got.YouTrack.ProjectKey != "PROJ" {
t.Fatalf("got %+v", got.YouTrack)
}
}
func TestLoadMetaMissing(t *testing.T) {
store := project.NewDirStore(t.TempDir())
got, err := store.LoadMeta("missing")
if err != nil {
t.Fatalf("LoadMeta: %v", err)
}
if got.YouTrack != nil {
t.Fatalf("expected empty meta, got %+v", got)
}
}
func TestYouTrackConfiguredAndQuery(t *testing.T) {
y := project.YouTrack{BaseURL: "https://x", Token: "t", ProjectKey: "ABC"}
if !y.Configured() {
t.Fatal("expected configured")
}
if y.IssueQuery() != "project: ABC" {
t.Fatalf("query = %q", y.IssueQuery())
}
y.Query = "Assignee: me"
if y.IssueQuery() != "Assignee: me" {
t.Fatalf("query = %q", y.IssueQuery())
}
}