Commit Graph

75 Commits

Author SHA1 Message Date
Claudio Ortolina a23f772c04 Re-enable Credo CyclomaticComplexity check 2026-03-06 10:08:25 +00:00
Claudio Ortolina f9b381570f Extract artist infos fixtures 2026-03-06 08:58:59 +00:00
Claudio Ortolina 3819afca4d Extract fixture 2026-03-06 08:53:25 +00:00
Claudio Ortolina c7285a2f80 Move more fixtures to compile time 2026-02-16 10:30:14 +00:00
Claudio Ortolina 2f7e2caa3c Cache fixtures 2026-02-16 09:50:10 +00:00
Claudio Ortolina bcae291cff Support getting artist bios from Wikipedia (experimental) 2026-02-09 15:20:06 +00:00
Claudio Ortolina 84159a1c0d Improve test coverage
Files Created (8 files, 54 new tests)

  Fixtures

  1. test/support/fixtures/music_library/record_sets.ex — record_set/1
and record_set_with_records/2 helpers
  2. test/support/fixtures/music_library/online_store_templates.ex —
online_store_template/1 helper

  Context Tests

  3. test/music_library/record_sets_test.exs — 20 tests covering search,
count, CRUD, add/remove/move records
  4. test/music_library/online_store_templates_test.exs — 8 tests
covering list, CRUD, URL generation, validation
  5. test/music_library/search_test.exs — 5 tests covering universal
search and search counts
  6. test/music_library/notes_test.exs — 4 tests covering get, create,
update

  LiveView Tests

  7. test/music_library_web/live/record_set_live/index_test.exs — 11
tests covering listing, empty state, search, ordering,
create/edit/delete sets, remove records, reorder records
  8.
test/music_library_web/live/online_store_template_live/index_test.exs —
6 tests covering listing, create/edit/delete, toggle enabled

  Results

  - 297 tests, 0 failures (up from 243 — 54 new tests added)
  - All existing tests continue to pass

There's a remaining gettext warning that needs to be investigated
2026-02-07 10:39:22 +00:00
Claudio Ortolina 7b697827fd Don't scrobble releases with zero duration 2025-10-23 10:27:08 +01:00
Claudio Ortolina a265f2ae52 Address Credo warnings 2025-09-16 12:57:03 +03:00
Claudio Ortolina dae334b1b7 Scrobbled tracks CRUD
- Failing tests
- Warnings
2025-09-16 12:45:36 +03:00
Claudio Ortolina 6c98b164eb Update more MusicBrainz fixtures 2025-09-15 14:31:55 +03:00
Claudio Ortolina b2283a3e5e Fix fixture path 2025-09-15 14:20:43 +03:00
Claudio Ortolina 2ef4eb2d2e Refresh fixtures 2025-09-15 14:02:53 +03:00
Claudio Ortolina dc77d337c0 Migrate from embedded covers to assets 2025-09-01 16:20:41 +03:00
Claudio Ortolina aee08cc2bb Use Enum for scrobble rule type 2025-07-04 14:23:19 +01:00
Claudio Ortolina d91685b646 First rough implementation of scrobble rules (Claude)
This plan outlines the implementation of functionality to manage
arbitrary rules for fixing data in the `scrobbled_tracks` table. The
system will support two types of transformations:

1. **Album Rule**: Update the album MusicBrainz ID of all tracks
belonging to a specific album (identified by album title)
2. **Artist Rule**: Update the artist MusicBrainz ID of all tracks
belonging to a specific artist (identified by artist name)

- `scrobbled_tracks` table exists with the following structure:
  - `scrobbled_at_uts` (integer, primary key)
  - `musicbrainz_id` (string) - track MusicBrainz ID
  - `title` (string) - track title
  - `cover_url` (string)
  - `scrobbled_at_label` (string)
  - `artist` (map) - embedded artist data with `musicbrainz_id` and
`name`
  - `album` (map) - embedded album data with `musicbrainz_id` and
`title`
  - `last_fm_data` (map) - raw Last.fm API response

- `LastFm.Track` - Schema for scrobbled tracks
- `LastFm.Artist` - Embedded artist schema
- `LastFm.Album` - Embedded album schema

- Main navigation has Stats, Collection, Wishlist sections
- "More" dropdown contains development tools and utilities
- Uses Phoenix LiveView for interactive components

**File**:
`priv/repo/migrations/YYYYMMDDHHMMSS_create_scrobble_rules.exs`

Create `scrobble_rules` table with:

- `id` (primary key)
- `type` (string) - "album" or "artist"
- `match_value` (string) - album title or artist name to match
- `target_musicbrainz_id` (string) - MusicBrainz ID to set
- `enabled` (boolean) - whether rule is active
- `description` (text) - optional description for the rule
- `inserted_at` (timestamp)
- `updated_at` (timestamp)

Indexes:

- `type, match_value` (compound index for efficient matching)
- `enabled` (for filtering active rules)

**File**: `lib/music_library/scrobble_rules/scrobble_rule.ex`

Create Ecto schema with:

- Field definitions matching migration
- Validations:
  - `type` must be "album" or "artist"
  - `match_value` required and non-empty
  - `target_musicbrainz_id` required and non-empty
  - `enabled` defaults to true
- Changeset functions for create/update operations

**File**: `lib/music_library/scrobble_rules.ex`

Implement context functions:

- `list_scrobble_rules(opts \\ [])` - list all rules with optional
filtering
- `get_scrobble_rule!(id)` - get specific rule by ID
- `create_scrobble_rule(attrs)` - create new rule
- `update_scrobble_rule(rule, attrs)` - update existing rule
- `delete_scrobble_rule(rule)` - delete rule
- `change_scrobble_rule(rule, attrs \\ %{})` - create changeset
- `list_enabled_rules()` - get only enabled rules for worker
- `apply_album_rule(rule)` - apply album transformation
- `apply_artist_rule(rule)` - apply artist transformation
- `apply_all_rules()` - apply all enabled rules

**File**: `lib/music_library_web/components/layouts/app.html.heex`

Add new navigation link in the "More" dropdown:

- Icon: `hero-adjustments-horizontal`
- Label: "Scrobble Rules"
- Route: `/scrobble-rules`
- Position: After "Oban" link, before separator

**File**: `lib/music_library_web/router.ex`

Add new LiveView routes in the authenticated scope:

- `/scrobble-rules` - index page
- `/scrobble-rules/new` - create new rule
- `/scrobble-rules/:id/edit` - edit existing rule

**File**: `lib/music_library_web/live/scrobble_rules_live/index.ex`

Implement LiveView with:

- List view showing all rules with status indicators
- Create/Edit forms with validation
- Delete confirmation
- Filter controls (by type, enabled/disabled)
- Manual rule application triggers
- Real-time updates via PubSub

**Template**:
`lib/music_library_web/live/scrobble_rules_live/index.html.heex`

- Table layout with rule details
- Action buttons (Edit, Delete, Apply)
- Form components for create/edit
- Status indicators for enabled/disabled rules

**File**:
`lib/music_library_web/live/scrobble_rules_live/form_component.ex`

Create reusable form component:

- Type selection (album/artist)
- Match value input with validation
- Target MusicBrainz ID input
- Description textarea
- Enable/disable toggle
- Save/Cancel actions

Where possible, use the components available at
<https://docs.fluxonui.com/1.1.4/overview.html>.

**File**: `lib/music_library/scrobble_rules/worker.ex`

Implement Oban worker:

- Scheduled to run periodically (e.g., every 30 minutes)
- Fetches all enabled rules
- Applies each rule in sequence
- Logs application results
- Handles errors gracefully
- Tracks last application time

**File**: `test/music_library/scrobble_rules_test.exs`

- Test all context functions
- Test rule application logic
- Test edge cases and error handling

**File**: `test/music_library/scrobble_rules/scrobble_rule_test.exs`

- Test schema validations
- Test changeset functions
- Test constraint validations

**File**: `test/music_library_web/live/scrobble_rules_live_test.exs`

- Test LiveView interactions
- Test form submissions
- Test real-time updates
- Test navigation and routing

**File**: `test/music_library/scrobble_rules/worker_test.exs`

- Test job execution
- Test rule application
- Test error handling
- Test scheduling

- Ensure atomic operations when applying rules
- Validate MusicBrainz IDs before applying
- Log all transformations for audit trail

- Index optimization for rule matching
- Batch processing for large datasets
- Rate limiting for external API calls

- Clear feedback on rule application
- Preview mode to show what would change
- Bulk operations for managing multiple rules
- Export/import functionality for rule sets

- Input validation and sanitization
- Rate limiting on rule creation
- Audit logging for all changes

```sql
-- scrobble_rules table
CREATE TABLE scrobble_rules (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  type TEXT NOT NULL CHECK (type IN ('album', 'artist')),
  match_value TEXT NOT NULL,
  target_musicbrainz_id TEXT NOT NULL,
  enabled BOOLEAN NOT NULL DEFAULT TRUE,
  description TEXT,
  inserted_at TIMESTAMP NOT NULL,
  updated_at TIMESTAMP NOT NULL
);

CREATE INDEX idx_scrobble_rules_type_match ON scrobble_rules(type,
match_value);
CREATE INDEX idx_scrobble_rules_enabled ON scrobble_rules(enabled);
```

```
lib/music_library/
├── scrobble_rules/
│   ├── scrobble_rule.ex          # Schema
│   └── worker.ex                 # Oban worker
└── scrobble_rules.ex             # Context

lib/music_library_web/
└── live/
    └── scrobble_rules_live/
        ├── index.ex              # LiveView
        ├── index.html.heex       # Template
        └── form_component.ex     # Form component

priv/repo/migrations/
└── YYYYMMDDHHMMSS_create_scrobble_rules.exs

test/
├── music_library/
│   ├── scrobble_rules_test.exs
│   └── scrobble_rules/
│       ├── scrobble_rule_test.exs
│       └── worker_test.exs
└── music_library_web/
    └── live/
        └── scrobble_rules_live_test.exs
```

1. Database migration and schema
2. Context module with basic CRUD operations
3. LiveView interface for rule management
4. Navigation and routing updates
5. Periodic worker implementation
6. Comprehensive testing
7. Documentation and deployment

This plan ensures a robust, maintainable solution that integrates
seamlessly with the existing Music Library application architecture.
2025-07-03 16:47:08 +01:00
Claudio Ortolina 07d9db6011 Speed up tests by caching cover data
Suggested and executed by Claude
2025-06-14 21:15:06 +03:00
Claudio Ortolina c5e47cbc8c Display dominant colors from the db 2025-06-07 20:07:23 +01:00
Claudio Ortolina 27c1cc0eda Import artist joinphrase 2025-06-03 18:16:47 +01:00
Claudio Ortolina fba621db10 Include artists in get_release 2025-05-04 21:50:23 +01:00
Claudio Ortolina f4fe638a95 Display tracks for records with a selected release 2025-05-04 21:10:40 +01:00
Claudio Ortolina 3e7341d4ca Support choosing a selected release 2025-05-01 17:42:40 +01:00
Claudio Ortolina e083950138 Rename record.release to record.release_date
Includes changes to dependent tables (i.e. the record search index) and
related functions.
2025-05-01 14:04:57 +01:00
Claudio Ortolina f1dd45e438 Show country flag for artist 2025-04-29 09:58:06 +01:00
Claudio Ortolina 34069636a0 Add tests for Artists.fetch_artist_info/1 2025-04-28 11:04:45 +01:00
Claudio Ortolina 1f43e1d993 Use JSON instead of Jason where possible
In some places, we need pretty printing so it's not possible to remove
the dependency.
2025-03-23 08:34:25 +00:00
Claudio Ortolina 93f6b260b2 Extract test fixture for release_group_releases 2025-03-01 07:40:00 +00:00
Claudio Ortolina a218942110 Remove mox in favour of built-in Req stubs 2025-02-28 16:41:16 +00:00
Claudio Ortolina 3d11cd585d Use built-in Req stub for LastFm tests 2025-02-27 13:43:49 +00:00
Claudio Ortolina 7df136c890 Sort aliases 2025-02-20 15:27:01 +00:00
Claudio Ortolina 163bbe8902 Add test for importing a record via barcode scan 2025-02-18 20:40:04 +00:00
Claudio Ortolina 324732b5ee Use different fixture for marbles individual release 2025-02-18 20:38:46 +00:00
Claudio Ortolina 94a2784020 Move function in MusicBrainz main module 2025-02-17 22:07:49 +00:00
Claudio Ortolina 336551e9f8 Namespace Obsidian fixtures 2025-02-17 16:08:19 +00:00
Claudio Ortolina 513ce6363f Rename RecordsFixtures -> Fixtures.Records 2025-02-17 16:08:19 +00:00
Claudio Ortolina ea7b5b646a Namespace MusicBrainz fixtures 2025-02-17 16:03:23 +00:00
Claudio Ortolina d27f3ccf72 Namespace Last.Fm fixtures 2025-02-17 15:52:54 +00:00
Claudio Ortolina d077f08afa Start making it more robust
- Use structured data for search/render
- Start testing component
- Start testing domain logic
2025-02-15 18:08:30 +00:00
Claudio Ortolina c46227ecf7 Update MusicBrainz fixtures 2025-02-12 21:52:58 +00:00
Claudio Ortolina 027b3af547 Rename ReleaseGroup to ReleaseGroupSearchResult 2025-02-10 16:38:04 +00:00
Claudio Ortolina 3c8b39237c Fix return type of artist_get_info fixture 2025-01-24 10:35:39 +00:00
Claudio Ortolina b9005e52f9 Use streams with import component 2025-01-20 13:58:21 +00:00
Claudio Ortolina ed6ef2c7ef Rename record_fixture* to record* 2025-01-06 14:20:36 +00:00
Claudio Ortolina 97533416f7 Support arbitrary resizing in cover controller 2024-12-31 11:58:30 +00:00
Claudio Ortolina 9dce1cacb9 Where possible, use built-in JSON instead of Jason
Note that it's not possible to replace any call where we encode and
pretty print, as JSON doesn't have such functionality.
2024-12-19 20:18:09 +00:00
Claudio Ortolina 3fbd6ba1bf Use release and release group fixtures with names everywhere 2024-12-14 23:52:09 +03:00
Claudio Ortolina 4ede4e3736 Add test for importing a record from scrobble activity 2024-12-14 23:41:39 +03:00
Claudio Ortolina a19d42ae30 Add more fixtures for release groups and releases 2024-12-14 23:24:21 +03:00
Claudio Ortolina 632f5c4661 Include album names in mb fixtures 2024-12-14 23:19:14 +03:00
Claudio Ortolina bef38967a1 Stub artist show test 2024-12-03 20:16:35 +00:00