(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func TestMigrateFromJSON(t *testing.T) { |
| 11 | tmpDir := t.TempDir() |
| 12 | |
| 13 | // Create prd.json with some statuses |
| 14 | jsonContent := `{ |
| 15 | "project": "Test", |
| 16 | "description": "A test", |
| 17 | "userStories": [ |
| 18 | {"id": "US-001", "title": "Done Story", "passes": true, "priority": 1}, |
| 19 | {"id": "US-002", "title": "In Progress Story", "passes": false, "inProgress": true, "priority": 2}, |
| 20 | {"id": "US-003", "title": "Pending Story", "passes": false, "priority": 3} |
| 21 | ] |
| 22 | }` |
| 23 | if err := os.WriteFile(filepath.Join(tmpDir, "prd.json"), []byte(jsonContent), 0644); err != nil { |
| 24 | t.Fatalf("failed to write prd.json: %v", err) |
| 25 | } |
| 26 | |
| 27 | // Create prd.md with the same stories |
| 28 | mdContent := `# Test |
| 29 | |
| 30 | ### US-001: Done Story |
| 31 | - [ ] A |
| 32 | |
| 33 | ### US-002: In Progress Story |
| 34 | - [ ] B |
| 35 | |
| 36 | ### US-003: Pending Story |
| 37 | - [ ] C |
| 38 | ` |
| 39 | if err := os.WriteFile(filepath.Join(tmpDir, "prd.md"), []byte(mdContent), 0644); err != nil { |
| 40 | t.Fatalf("failed to write prd.md: %v", err) |
| 41 | } |
| 42 | |
| 43 | // Run migration |
| 44 | if err := MigrateFromJSON(tmpDir); err != nil { |
| 45 | t.Fatalf("MigrateFromJSON() error = %v", err) |
| 46 | } |
| 47 | |
| 48 | // Verify prd.json is renamed to prd.json.bak |
| 49 | if _, err := os.Stat(filepath.Join(tmpDir, "prd.json")); !os.IsNotExist(err) { |
| 50 | t.Error("prd.json should be renamed") |
| 51 | } |
| 52 | if _, err := os.Stat(filepath.Join(tmpDir, "prd.json.bak")); err != nil { |
| 53 | t.Error("prd.json.bak should exist") |
| 54 | } |
| 55 | |
| 56 | // Verify prd.md has the correct statuses |
| 57 | data, err := os.ReadFile(filepath.Join(tmpDir, "prd.md")) |
| 58 | if err != nil { |
| 59 | t.Fatalf("failed to read prd.md: %v", err) |
| 60 | } |
| 61 | result := string(data) |
| 62 | |
| 63 | // US-001 should be done with checked boxes |
| 64 | if !strings.Contains(result, "- [x] A") { |
| 65 | t.Error("US-001 should have checked checkbox") |
| 66 | } |
| 67 |
nothing calls this directly
no test coverage detected