cli + tui to publish to leaflet (wip) & manage tasks, notes & watch/read lists 馃崈
charm leaflet readability golang
at main 302 lines 11 kB view raw
1package repo 2 3import ( 4 "context" 5 "testing" 6 7 "github.com/stormlightlabs/noteleaf/internal/shared" 8) 9 10func TestFindMethods(t *testing.T) { 11 db := CreateTestDB(t) 12 repos := SetupTestData(t, db) 13 ctx := context.Background() 14 15 t.Run("TaskRepository Find", func(t *testing.T) { 16 t.Run("finds tasks by status", func(t *testing.T) { 17 options := TaskListOptions{ 18 Status: "pending", 19 } 20 tasks, err := repos.Tasks.Find(ctx, options) 21 shared.AssertNoError(t, err, "Find should succeed") 22 shared.AssertTrue(t, len(tasks) >= 1, "Should find at least one pending task") 23 for _, task := range tasks { 24 shared.AssertEqual(t, "pending", task.Status, "All returned tasks should be pending") 25 } 26 }) 27 28 t.Run("finds tasks by priority", func(t *testing.T) { 29 options := TaskListOptions{ 30 Priority: "high", 31 } 32 tasks, err := repos.Tasks.Find(ctx, options) 33 shared.AssertNoError(t, err, "Find should succeed") 34 shared.AssertTrue(t, len(tasks) >= 1, "Should find at least one high priority task") 35 for _, task := range tasks { 36 shared.AssertEqual(t, "high", task.Priority, "All returned tasks should be high priority") 37 } 38 }) 39 40 t.Run("finds tasks by project", func(t *testing.T) { 41 options := TaskListOptions{ 42 Project: "test-project", 43 } 44 tasks, err := repos.Tasks.Find(ctx, options) 45 shared.AssertNoError(t, err, "Find should succeed") 46 shared.AssertTrue(t, len(tasks) >= 1, "Should find tasks in test-project") 47 for _, task := range tasks { 48 shared.AssertEqual(t, "test-project", task.Project, "All returned tasks should be in test-project") 49 } 50 }) 51 52 t.Run("finds tasks by context", func(t *testing.T) { 53 options := TaskListOptions{ 54 Context: "test-context", 55 } 56 tasks, err := repos.Tasks.Find(ctx, options) 57 shared.AssertNoError(t, err, "Find should succeed") 58 shared.AssertTrue(t, len(tasks) >= 1, "Should find tasks in test-context") 59 for _, task := range tasks { 60 shared.AssertEqual(t, "test-context", task.Context, "All returned tasks should be in test-context") 61 } 62 }) 63 64 t.Run("finds tasks by multiple criteria", func(t *testing.T) { 65 options := TaskListOptions{ 66 Status: "pending", 67 Priority: "high", 68 Project: "test-project", 69 } 70 tasks, err := repos.Tasks.Find(ctx, options) 71 shared.AssertNoError(t, err, "Find should succeed") 72 for _, task := range tasks { 73 shared.AssertEqual(t, "pending", task.Status, "Task should be pending") 74 shared.AssertEqual(t, "high", task.Priority, "Task should be high priority") 75 shared.AssertEqual(t, "test-project", task.Project, "Task should be in test-project") 76 } 77 }) 78 79 t.Run("returns empty for non-matching criteria", func(t *testing.T) { 80 options := TaskListOptions{ 81 Status: "non-existent-status", 82 } 83 tasks, err := repos.Tasks.Find(ctx, options) 84 shared.AssertNoError(t, err, "Find should succeed even with no results") 85 shared.AssertEqual(t, 0, len(tasks), "Should find no tasks") 86 }) 87 88 t.Run("returns all tasks with empty options", func(t *testing.T) { 89 options := TaskListOptions{} 90 tasks, err := repos.Tasks.Find(ctx, options) 91 shared.AssertNoError(t, err, "Find should succeed with empty options") 92 shared.AssertTrue(t, len(tasks) >= 2, "Should return all tasks for empty options") 93 }) 94 }) 95 96 t.Run("BookRepository Find", func(t *testing.T) { 97 t.Run("finds books by status", func(t *testing.T) { 98 options := BookListOptions{ 99 Status: "reading", 100 } 101 books, err := repos.Books.Find(ctx, options) 102 shared.AssertNoError(t, err, "Find should succeed") 103 shared.AssertTrue(t, len(books) >= 1, "Should find at least one book being read") 104 for _, book := range books { 105 shared.AssertEqual(t, "reading", book.Status, "All returned books should be reading") 106 } 107 }) 108 109 t.Run("finds books by author", func(t *testing.T) { 110 options := BookListOptions{ 111 Author: "Test Author", 112 } 113 books, err := repos.Books.Find(ctx, options) 114 shared.AssertNoError(t, err, "Find should succeed") 115 shared.AssertTrue(t, len(books) >= 1, "Should find at least one book by Test Author") 116 for _, book := range books { 117 shared.AssertEqual(t, "Test Author", book.Author, "All returned books should be by Test Author") 118 } 119 }) 120 121 t.Run("finds books by minimum progress", func(t *testing.T) { 122 options := BookListOptions{ 123 MinProgress: 0, 124 } 125 books, err := repos.Books.Find(ctx, options) 126 shared.AssertNoError(t, err, "Find should succeed") 127 shared.AssertTrue(t, len(books) >= 1, "Should find books with progress >= 0") 128 for _, book := range books { 129 shared.AssertTrue(t, book.Progress >= 0, "All returned books should have progress >= 0") 130 } 131 }) 132 133 t.Run("finds books by multiple criteria", func(t *testing.T) { 134 options := BookListOptions{ 135 Status: "reading", 136 Author: "Test Author", 137 MinProgress: 0, 138 } 139 books, err := repos.Books.Find(ctx, options) 140 shared.AssertNoError(t, err, "Find should succeed") 141 for _, book := range books { 142 shared.AssertEqual(t, "reading", book.Status, "Book should be reading") 143 shared.AssertEqual(t, "Test Author", book.Author, "Book should be by Test Author") 144 shared.AssertTrue(t, book.Progress >= 0, "Book should have progress >= 0") 145 } 146 }) 147 148 t.Run("returns empty for non-matching criteria", func(t *testing.T) { 149 options := BookListOptions{ 150 Status: "non-existent-status", 151 } 152 books, err := repos.Books.Find(ctx, options) 153 shared.AssertNoError(t, err, "Find should succeed even with no results") 154 shared.AssertEqual(t, 0, len(books), "Should find no books") 155 }) 156 157 t.Run("returns all books with empty options", func(t *testing.T) { 158 options := BookListOptions{} 159 books, err := repos.Books.Find(ctx, options) 160 shared.AssertNoError(t, err, "Find should succeed with empty options") 161 shared.AssertTrue(t, len(books) >= 2, "Should return all books for empty options") 162 }) 163 }) 164 165 t.Run("MovieRepository Find", func(t *testing.T) { 166 t.Run("finds movies by status", func(t *testing.T) { 167 options := MovieListOptions{ 168 Status: "watched", 169 } 170 movies, err := repos.Movies.Find(ctx, options) 171 shared.AssertNoError(t, err, "Find should succeed") 172 shared.AssertTrue(t, len(movies) >= 1, "Should find at least one watched movie") 173 for _, movie := range movies { 174 shared.AssertEqual(t, "watched", movie.Status, "All returned movies should be watched") 175 } 176 }) 177 178 t.Run("finds movies by year", func(t *testing.T) { 179 options := MovieListOptions{ 180 Year: 2023, 181 } 182 movies, err := repos.Movies.Find(ctx, options) 183 shared.AssertNoError(t, err, "Find should succeed") 184 shared.AssertTrue(t, len(movies) >= 1, "Should find movies from 2023") 185 for _, movie := range movies { 186 shared.AssertEqual(t, 2023, movie.Year, "Movie should be from 2023") 187 } 188 }) 189 190 t.Run("finds movies by minimum rating", func(t *testing.T) { 191 options := MovieListOptions{ 192 MinRating: 0.0, 193 } 194 movies, err := repos.Movies.Find(ctx, options) 195 shared.AssertNoError(t, err, "Find should succeed") 196 shared.AssertTrue(t, len(movies) >= 1, "Should find movies with rating >= 0") 197 for _, movie := range movies { 198 shared.AssertTrue(t, movie.Rating >= 0.0, "Movie rating should be >= 0") 199 } 200 }) 201 202 t.Run("finds movies by multiple criteria", func(t *testing.T) { 203 options := MovieListOptions{ 204 Status: "watched", 205 Year: 2023, 206 MinRating: 0.0, 207 } 208 movies, err := repos.Movies.Find(ctx, options) 209 shared.AssertNoError(t, err, "Find should succeed") 210 for _, movie := range movies { 211 shared.AssertEqual(t, "watched", movie.Status, "Movie should be watched") 212 shared.AssertEqual(t, 2023, movie.Year, "Movie should be from 2023") 213 shared.AssertTrue(t, movie.Rating >= 0.0, "Movie rating should be >= 0") 214 } 215 }) 216 217 t.Run("returns empty for non-matching criteria", func(t *testing.T) { 218 options := MovieListOptions{ 219 Status: "non-existent-status", 220 } 221 movies, err := repos.Movies.Find(ctx, options) 222 shared.AssertNoError(t, err, "Find should succeed even with no results") 223 shared.AssertEqual(t, 0, len(movies), "Should find no movies") 224 }) 225 226 t.Run("returns all movies with empty options", func(t *testing.T) { 227 options := MovieListOptions{} 228 movies, err := repos.Movies.Find(ctx, options) 229 shared.AssertNoError(t, err, "Find should succeed with empty options") 230 shared.AssertTrue(t, len(movies) >= 2, "Should return all movies for empty options") 231 }) 232 }) 233 234 t.Run("TVRepository Find", func(t *testing.T) { 235 t.Run("finds TV shows by status", func(t *testing.T) { 236 options := TVListOptions{ 237 Status: "watching", 238 } 239 shows, err := repos.TV.Find(ctx, options) 240 shared.AssertNoError(t, err, "Find should succeed") 241 shared.AssertTrue(t, len(shows) >= 1, "Should find at least one TV show being watched") 242 for _, show := range shows { 243 shared.AssertEqual(t, "watching", show.Status, "All returned shows should be watching") 244 } 245 }) 246 247 t.Run("finds TV shows by season", func(t *testing.T) { 248 options := TVListOptions{ 249 Season: 1, 250 } 251 shows, err := repos.TV.Find(ctx, options) 252 shared.AssertNoError(t, err, "Find should succeed") 253 shared.AssertTrue(t, len(shows) >= 1, "Should find TV shows with season 1") 254 for _, show := range shows { 255 shared.AssertEqual(t, 1, show.Season, "All returned shows should be season 1") 256 } 257 }) 258 259 t.Run("finds TV shows by minimum rating", func(t *testing.T) { 260 options := TVListOptions{ 261 MinRating: 0.0, 262 } 263 shows, err := repos.TV.Find(ctx, options) 264 shared.AssertNoError(t, err, "Find should succeed") 265 shared.AssertTrue(t, len(shows) >= 1, "Should find TV shows with rating >= 0") 266 for _, show := range shows { 267 shared.AssertTrue(t, show.Rating >= 0.0, "Show rating should be >= 0") 268 } 269 }) 270 271 t.Run("finds TV shows by multiple criteria", func(t *testing.T) { 272 options := TVListOptions{ 273 Status: "watching", 274 Season: 1, 275 MinRating: 0.0, 276 } 277 shows, err := repos.TV.Find(ctx, options) 278 shared.AssertNoError(t, err, "Find should succeed") 279 for _, show := range shows { 280 shared.AssertEqual(t, "watching", show.Status, "Show should be watching") 281 shared.AssertEqual(t, 1, show.Season, "Show should be season 1") 282 shared.AssertTrue(t, show.Rating >= 0.0, "Show rating should be >= 0") 283 } 284 }) 285 286 t.Run("returns empty for non-matching criteria", func(t *testing.T) { 287 options := TVListOptions{ 288 Status: "non-existent-status", 289 } 290 shows, err := repos.TV.Find(ctx, options) 291 shared.AssertNoError(t, err, "Find should succeed even with no results") 292 shared.AssertEqual(t, 0, len(shows), "Should find no TV shows") 293 }) 294 295 t.Run("returns all TV shows with empty options", func(t *testing.T) { 296 options := TVListOptions{} 297 shows, err := repos.TV.Find(ctx, options) 298 shared.AssertNoError(t, err, "Find should succeed with empty options") 299 shared.AssertTrue(t, len(shows) >= 2, "Should return all TV shows for empty options") 300 }) 301 }) 302}