feat!: replace OpenSubsonic with a native mood-first API
Remove the /rest compatibility layer and the playlist model. Moods are now first-class private collections, and playback is driven by short-lived radio sessions whose queues are generated by the server. - Bearer device tokens (hashed) with revocable sessions. - Library snapshot/delta sync with tombstones and per-folder scoping. - Mood CRUD, seeds, preview and recommendations. - Radio batches weighted by seeds, genres, artists, text and playback affinity. - Playback events (started/completed/skipped) and explicit add-to-mood. - Stream, download and cover endpoints with query-token support for browsers. - V5 migration drops playlists and migrates existing moods; scanner writes tombstones and song update timestamps. - Built-in UI rebuilt on the native API with a radio player. - Native API integration tests and a rewritten smoke test (49 checks). - Chart bumped to 0.2.0. BREAKING CHANGE: the OpenSubsonic API and static playlists are gone.
This commit is contained in:
1 parent
28bfdd9d00
commit
b33eb076c1
46 files changed
+3472
-5823
No files matched your search
+158
-150
@@ -1,9 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# End-to-end smoke test: generates a tiny tagged MP3 library, starts the server
|
||||
# against it, and exercises the endpoints a Subsonic client uses.
|
||||
# End-to-end smoke test for the native mood-first API.
|
||||
#
|
||||
# Requirements: ffmpeg, sqlite3, curl, md5sum, java (or use nix-shell).
|
||||
# Generates a tiny tagged MP3 library, starts the server against it, and
|
||||
# exercises auth, sync, moods, radio sessions, add-to-mood and streaming.
|
||||
#
|
||||
# Requirements: ffmpeg, sqlite3, curl, python3, java.
|
||||
# Usage: scripts/smoke.sh [work-dir]
|
||||
#
|
||||
set -euo pipefail
|
||||
@@ -15,9 +17,9 @@ PORT="${SMOKE_PORT:-18099}"
|
||||
USER="smoke"
|
||||
PASS="smoke-pass"
|
||||
BASE="http://127.0.0.1:${PORT}"
|
||||
SALT="smoke-salt"
|
||||
TOKEN="$(printf '%s%s' "$PASS" "$SALT" | md5sum | cut -d' ' -f1)"
|
||||
AUTH="u=${USER}&t=${TOKEN}&s=${SALT}&v=1.16.1&c=smoke&f=json"
|
||||
TOKEN=""
|
||||
HTTP_STATUS=""
|
||||
HTTP_BODY=""
|
||||
|
||||
PASSED=0
|
||||
FAILED=0
|
||||
@@ -26,20 +28,30 @@ log() { printf '%s\n' "$*"; }
|
||||
pass() { PASSED=$((PASSED + 1)); log "PASS $1"; }
|
||||
fail() { FAILED=$((FAILED + 1)); log "FAIL $1: $2"; }
|
||||
|
||||
mkdir -p "$WORK/music/Smoke Artist/Smoke Album" "$WORK/longform" "$WORK/data"
|
||||
json_field() { python3 -c 'import json,sys;d=json.load(sys.stdin);print(eval("d"+sys.argv[1]))' "$1"; }
|
||||
|
||||
mkdir -p "$WORK/music/Smoke Artist/Smoke Album" "$WORK/music/Second Artist/Second Album" \
|
||||
"$WORK/longform/Long Narrator/Long Book" "$WORK/data"
|
||||
|
||||
log "Generated test library in $WORK"
|
||||
ffmpeg -hide_banner -loglevel error -y \
|
||||
-f lavfi -i "sine=frequency=440:duration=2" \
|
||||
-metadata title="Smoke Song" \
|
||||
-metadata artist="Smoke Artist" \
|
||||
-metadata album="Smoke Album" \
|
||||
-metadata album_artist="Smoke Artist" \
|
||||
-metadata genre="Rock" \
|
||||
-metadata track="1" \
|
||||
-metadata date="2026" \
|
||||
-metadata title="Smoke Song" -metadata artist="Smoke Artist" \
|
||||
-metadata album="Smoke Album" -metadata album_artist="Smoke Artist" \
|
||||
-metadata genre="Rock" -metadata track="1" -metadata date="2026" \
|
||||
-b:a 192k "$WORK/music/Smoke Artist/Smoke Album/01 - Smoke Song.mp3"
|
||||
|
||||
ffmpeg -hide_banner -loglevel error -y \
|
||||
-f lavfi -i "sine=frequency=550:duration=2" \
|
||||
-metadata title="Second Song" -metadata artist="Second Artist" \
|
||||
-metadata album="Second Album" -metadata album_artist="Second Artist" \
|
||||
-metadata genre="Ambient" -metadata track="1" -metadata date="2026" \
|
||||
-b:a 192k "$WORK/music/Second Artist/Second Album/01 - Second Song.mp3"
|
||||
ffmpeg -hide_banner -loglevel error -y \
|
||||
-f lavfi -i "sine=frequency=660:duration=2" \
|
||||
-metadata title="Chapter One" -metadata artist="Long Narrator" \
|
||||
-metadata album="Long Book" -metadata album_artist="Long Narrator" \
|
||||
-metadata genre="Audiobook" -metadata track="1" -metadata date="2026" \
|
||||
-b:a 128k "$WORK/longform/Long Narrator/Long Book/01 - Chapter One.mp3"
|
||||
ffmpeg -hide_banner -loglevel error -y \
|
||||
-f lavfi -i "color=c=red:s=64x64" -frames:v 1 \
|
||||
"$WORK/music/Smoke Artist/Smoke Album/cover.jpg"
|
||||
@@ -80,182 +92,178 @@ SERVER_PID=$!
|
||||
trap 'kill $SERVER_PID 2>/dev/null || true' EXIT
|
||||
|
||||
log "Waiting for the server and initial scan..."
|
||||
SONGS=0
|
||||
for _ in $(seq 1 120); do
|
||||
if curl -sf "$BASE/health" >/dev/null 2>&1; then
|
||||
SONGS="$(sqlite3 "$WORK/data/musicmanager.db" 'select count(*) from songs' 2>/dev/null || echo 0)"
|
||||
[[ "$SONGS" -gt 0 ]] && break
|
||||
[[ "$SONGS" -ge 3 ]] && break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
if [[ "${SONGS:-0}" -eq 0 ]]; then
|
||||
if [[ "${SONGS:-0}" -lt 3 ]]; then
|
||||
log "Server did not scan the test library; see $WORK/server.log"
|
||||
tail -20 "$WORK/server.log" || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ALBUM_ID="$(sqlite3 "$WORK/data/musicmanager.db" 'select id from albums limit 1')"
|
||||
ARTIST_ID="$(sqlite3 "$WORK/data/musicmanager.db" 'select id from artists limit 1')"
|
||||
SONG_ID="$(sqlite3 "$WORK/data/musicmanager.db" 'select id from songs limit 1')"
|
||||
log "Scanned: artist=$ARTIST_ID album=$ALBUM_ID song=$SONG_ID"
|
||||
SONG_ID="$(sqlite3 "$WORK/data/musicmanager.db" "select id from songs where title='Smoke Song'")"
|
||||
SONG2_ID="$(sqlite3 "$WORK/data/musicmanager.db" "select id from songs where title='Second Song'")"
|
||||
LONG_ID="$(sqlite3 "$WORK/data/musicmanager.db" "select id from songs where title='Chapter One'")"
|
||||
ALBUM_ID="$(sqlite3 "$WORK/data/musicmanager.db" "select album_id from songs where id='$SONG_ID'")"
|
||||
log "Scanned: song=$SONG_ID second=$SONG2_ID longform=$LONG_ID"
|
||||
|
||||
# check <name> <path-with-query> [expected-status]
|
||||
check() {
|
||||
local name="$1" path="$2" expected="${3:-200}" body status
|
||||
body="$(curl -s -w '\n%{http_code}' "$BASE$path")"
|
||||
status="$(printf '%s' "$body" | tail -1)"
|
||||
body="$(printf '%s' "$body" | sed '$d')"
|
||||
|
||||
if [[ "$status" != "$expected" ]]; then
|
||||
fail "$name" "HTTP $status (expected $expected): $(printf '%s' "$body" | head -c 200)"
|
||||
return
|
||||
# api <method> <path> [json-body] [token-override]
|
||||
api() {
|
||||
local method="$1" path="$2" body="${3:-}" auth="${4:-$TOKEN}"
|
||||
local args=(-s -w '\n%{http_code}' -X "$method" "$BASE/api/v1$path")
|
||||
[[ -n "$auth" ]] && args+=(-H "Authorization: Bearer $auth")
|
||||
if [[ -n "$body" ]]; then
|
||||
args+=(-H 'Content-Type: application/json' -d "$body")
|
||||
fi
|
||||
if [[ "$expected" == "200" ]] && ! printf '%s' "$body" | grep -q '"status":"ok"'; then
|
||||
fail "$name" "$(printf '%s' "$body" | head -c 200)"
|
||||
return
|
||||
fi
|
||||
pass "$name"
|
||||
local out
|
||||
out="$(curl "${args[@]}")"
|
||||
HTTP_STATUS="$(printf '%s' "$out" | tail -1)"
|
||||
HTTP_BODY="$(printf '%s' "$out" | sed '$d')"
|
||||
}
|
||||
|
||||
# check_post <name> <path> <extra-form-data>
|
||||
check_post() {
|
||||
local name="$1" path="$2" extra="${3:-}" body status
|
||||
body="$(curl -s -w '\n%{http_code}' -X POST \
|
||||
-H 'Content-Type: application/x-www-form-urlencoded' \
|
||||
--data "${AUTH}${extra}" "$BASE$path")"
|
||||
status="$(printf '%s' "$body" | tail -1)"
|
||||
body="$(printf '%s' "$body" | sed '$d')"
|
||||
|
||||
if [[ "$status" != "200" ]]; then
|
||||
fail "$name (POST)" "HTTP $status: $(printf '%s' "$body" | head -c 200)"
|
||||
return
|
||||
expect() {
|
||||
local name="$1" expected="$2" method="$3" path="$4" body="${5:-}"
|
||||
api "$method" "$path" "$body"
|
||||
if [[ "$HTTP_STATUS" == "$expected" ]]; then
|
||||
pass "$name"
|
||||
else
|
||||
fail "$name" "HTTP $HTTP_STATUS (expected $expected): ${HTTP_BODY:0:240}"
|
||||
fi
|
||||
if ! printf '%s' "$body" | grep -q '"status":"ok"'; then
|
||||
fail "$name (POST)" "$(printf '%s' "$body" | head -c 200)"
|
||||
return
|
||||
fi
|
||||
pass "$name (POST)"
|
||||
}
|
||||
|
||||
check "ping" "/rest/ping.view?$AUTH"
|
||||
check "getLicense" "/rest/getLicense.view?$AUTH"
|
||||
check "getOpenSubsonicExtensions" "/rest/getOpenSubsonicExtensions.view?$AUTH"
|
||||
check "getMusicFolders" "/rest/getMusicFolders.view?$AUTH"
|
||||
check "getIndexes" "/rest/getIndexes.view?$AUTH"
|
||||
check "getArtists" "/rest/getArtists.view?$AUTH"
|
||||
check "getArtist" "/rest/getArtist.view?$AUTH&id=$ARTIST_ID"
|
||||
check "getAlbum" "/rest/getAlbum.view?$AUTH&id=$ALBUM_ID"
|
||||
check "getSong" "/rest/getSong.view?$AUTH&id=$SONG_ID"
|
||||
check "search3" "/rest/search3.view?$AUTH&query=smoke"
|
||||
check "getAlbumList2" "/rest/getAlbumList2.view?$AUTH&type=alphabeticalByName&size=10"
|
||||
check "getAlbumList" "/rest/getAlbumList.view?$AUTH&type=newest&size=10"
|
||||
check "getRandomSongs" "/rest/getRandomSongs.view?$AUTH&size=10"
|
||||
check "getGenres" "/rest/getGenres.view?$AUTH"
|
||||
check "getSongsByGenre" "/rest/getSongsByGenre.view?$AUTH&genre=Rock"
|
||||
check "getMusicDirectory (folder)" "/rest/getMusicDirectory.view?$AUTH&id=1"
|
||||
check "getMusicDirectory (album)" "/rest/getMusicDirectory.view?$AUTH&id=$ALBUM_ID"
|
||||
check "getUser" "/rest/getUser.view?$AUTH&username=$USER"
|
||||
check "getUsers" "/rest/getUsers.view?$AUTH"
|
||||
check "getScanStatus" "/rest/getScanStatus.view?$AUTH"
|
||||
check "getStarred2" "/rest/getStarred2.view?$AUTH"
|
||||
check "getLyricsBySongId" "/rest/getLyricsBySongId.view?$AUTH&id=$SONG_ID"
|
||||
check "getArtistInfo2" "/rest/getArtistInfo2.view?$AUTH&id=$ARTIST_ID"
|
||||
check "getAlbumInfo2" "/rest/getAlbumInfo2.view?$AUTH&id=$ALBUM_ID"
|
||||
check "getSimilarSongs2" "/rest/getSimilarSongs2.view?$AUTH&id=$ARTIST_ID"
|
||||
check "getTopSongs" "/rest/getTopSongs.view?$AUTH&artist=Smoke%20Artist"
|
||||
check "getInternetRadioStations" "/rest/getInternetRadioStations.view?$AUTH"
|
||||
check "jukeboxControl" "/rest/jukeboxControl.view?$AUTH&action=status"
|
||||
expect_eq() {
|
||||
local name="$1" expected="$2" actual="$3"
|
||||
if [[ "$actual" == "$expected" ]]; then
|
||||
pass "$name"
|
||||
else
|
||||
fail "$name" "expected '$expected', got '$actual'"
|
||||
fi
|
||||
}
|
||||
|
||||
# The formPost extension means clients may use POST for every endpoint.
|
||||
check_post "ping" "/rest/ping.view"
|
||||
check_post "getAlbumList2" "/rest/getAlbumList2.view" "&type=alphabeticalByName&size=10"
|
||||
check_post "getGenres" "/rest/getGenres.view"
|
||||
check_post "getPlaylists" "/rest/getPlaylists.view"
|
||||
check_post "getUser" "/rest/getUser.view" "&username=$USER"
|
||||
log ""
|
||||
log "Authentication"
|
||||
LOGIN_STATUS="$(curl -s -o "$WORK/login.json" -w '%{http_code}' -X POST \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d "{\"username\":\"$USER\",\"password\":\"$PASS\",\"deviceName\":\"smoke\",\"platform\":\"cli\"}" \
|
||||
"$BASE/api/v1/auth/login")"
|
||||
expect_eq "login status" "200" "$LOGIN_STATUS"
|
||||
TOKEN="$(json_field '["token"]' < "$WORK/login.json" 2>/dev/null || true)"
|
||||
if [[ -n "$TOKEN" ]]; then pass "login token"; else fail "login token" "$(head -c 200 "$WORK/login.json")"; fi
|
||||
expect_eq "login user" "$USER" "$(json_field '["user"]["name"]' < "$WORK/login.json" 2>/dev/null || true)"
|
||||
|
||||
check "scrobble" "/rest/scrobble.view?$AUTH&id=$SONG_ID"
|
||||
check "star" "/rest/star.view?$AUTH&id=$SONG_ID&albumId=$ALBUM_ID&artistId=$ARTIST_ID"
|
||||
check "getStarred2 after star" "/rest/getStarred2.view?$AUTH"
|
||||
check "setRating" "/rest/setRating.view?$AUTH&id=$SONG_ID&rating=4"
|
||||
check "unstar" "/rest/unstar.view?$AUTH&id=$SONG_ID&albumId=$ALBUM_ID&artistId=$ARTIST_ID"
|
||||
check "createBookmark" "/rest/createBookmark.view?$AUTH&id=$SONG_ID&position=1000"
|
||||
check "getBookmarks" "/rest/getBookmarks.view?$AUTH"
|
||||
check "deleteBookmark" "/rest/deleteBookmark.view?$AUTH&id=$SONG_ID"
|
||||
BAD_STATUS="$(curl -s -o /dev/null -w '%{http_code}' -X POST \
|
||||
-H 'Content-Type: application/json' -d '{"username":"smoke","password":"wrong"}' \
|
||||
"$BASE/api/v1/auth/login")"
|
||||
expect_eq "login rejects bad password" "401" "$BAD_STATUS"
|
||||
UNAUTH_STATUS="$(curl -s -o /dev/null -w '%{http_code}' "$BASE/api/v1/moods")"
|
||||
expect_eq "unauthenticated request rejected" "401" "$UNAUTH_STATUS"
|
||||
|
||||
PLAYLIST_JSON="$(curl -s "$BASE/rest/createPlaylist.view?$AUTH&name=Smoke%20List&songId=$SONG_ID")"
|
||||
PLAYLIST_ID="$(printf '%s' "$PLAYLIST_JSON" | python3 -c 'import json,sys; print(json.load(sys.stdin)["subsonic-response"]["playlist"]["id"])' 2>/dev/null || true)"
|
||||
if [[ -z "$PLAYLIST_ID" ]]; then
|
||||
fail "createPlaylist" "$(printf '%s' "$PLAYLIST_JSON" | head -c 300)"
|
||||
else
|
||||
pass "createPlaylist"
|
||||
check "getPlaylists" "/rest/getPlaylists.view?$AUTH"
|
||||
check "getPlaylist" "/rest/getPlaylist.view?$AUTH&id=$PLAYLIST_ID"
|
||||
check "updatePlaylist" "/rest/updatePlaylist.view?$AUTH&playlistId=$PLAYLIST_ID&songIndexToRemove=0"
|
||||
check "deletePlaylist" "/rest/deletePlaylist.view?$AUTH&id=$PLAYLIST_ID"
|
||||
fi
|
||||
expect "me" "200" "GET" "/me"
|
||||
expect_eq "me name" "$USER" "$(printf '%s' "$HTTP_BODY" | json_field '["name"]')"
|
||||
|
||||
MOOD_JSON="$(curl -s "$BASE/rest/createMood.view?$AUTH&name=Smoke%20Mood&songId=$SONG_ID&targetSize=5")"
|
||||
MOOD_ID="$(printf '%s' "$MOOD_JSON" | python3 -c 'import json,sys; print(json.load(sys.stdin)["subsonic-response"]["mood"]["id"])' 2>/dev/null || true)"
|
||||
if [[ -z "$MOOD_ID" ]]; then
|
||||
fail "createMood" "$(printf '%s' "$MOOD_JSON" | head -c 300)"
|
||||
else
|
||||
pass "createMood"
|
||||
check "getMoods" "/rest/getMoods.view?$AUTH"
|
||||
check "getMood" "/rest/getMood.view?$AUTH&id=$MOOD_ID"
|
||||
check "getPlaylist (mood)" "/rest/getPlaylist.view?$AUTH&id=$MOOD_ID"
|
||||
check "refreshMood" "/rest/refreshMood.view?$AUTH&id=$MOOD_ID"
|
||||
check "deleteMood" "/rest/deleteMood.view?$AUTH&id=$MOOD_ID"
|
||||
fi
|
||||
log ""
|
||||
log "Library sync"
|
||||
expect "library snapshot (music)" "200" "GET" "/library/songs?scope=music"
|
||||
MUSIC_COUNT="$(printf '%s' "$HTTP_BODY" | json_field '["songs"].__len__()' 2>/dev/null || echo 0)"
|
||||
expect_eq "music snapshot has 2 songs" "2" "$MUSIC_COUNT"
|
||||
expect_eq "snapshot contains smoke song" "1" "$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;print(sum(1 for s in json.load(sys.stdin)["songs"] if s["id"]=="'"$SONG_ID"'"))')"
|
||||
|
||||
check "savePlayQueue" "/rest/savePlayQueue.view?$AUTH&id=$SONG_ID&position=0"
|
||||
check "getPlayQueue" "/rest/getPlayQueue.view?$AUTH"
|
||||
check "savePlayQueueByIndex" "/rest/savePlayQueueByIndex.view?$AUTH&id=$SONG_ID¤tIndex=0&position=0"
|
||||
check "getPlayQueueByIndex" "/rest/getPlayQueueByIndex.view?$AUTH"
|
||||
expect "library snapshot (longform)" "200" "GET" "/library/songs?scope=longform"
|
||||
expect_eq "longform snapshot has 1 song" "1" "$(printf '%s' "$HTTP_BODY" | json_field '["songs"].__len__()')"
|
||||
expect "search" "200" "GET" "/library/search?q=smoke&scope=music"
|
||||
expect_eq "search finds one song" "1" "$(printf '%s' "$HTTP_BODY" | json_field '["songs"].__len__()')"
|
||||
|
||||
STREAM_STATUS="$(curl -s -o "$WORK/stream.mp3" -w '%{http_code}' "$BASE/rest/stream.view?$AUTH&id=$SONG_ID")"
|
||||
log ""
|
||||
log "Moods"
|
||||
expect "create mood" "201" "POST" "/moods" \
|
||||
"{\"name\":\"Smoke Mood\",\"genres\":[\"Rock\"],\"targetSize\":10,\"seedSongIds\":[\"$SONG_ID\"]}"
|
||||
MOOD_ID="$(printf '%s' "$HTTP_BODY" | json_field '["mood"]["id"]' 2>/dev/null || true)"
|
||||
if [[ -n "$MOOD_ID" ]]; then pass "mood id"; else fail "mood id" "${HTTP_BODY:0:200}"; fi
|
||||
expect_eq "mood seed count" "1" "$(printf '%s' "$HTTP_BODY" | json_field '["mood"]["seedCount"]')"
|
||||
expect "list moods" "200" "GET" "/moods"
|
||||
expect_eq "list contains mood" "1" "$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;print(sum(1 for m in json.load(sys.stdin)["moods"] if m["id"]=="'"$MOOD_ID"'"))')"
|
||||
expect "get mood" "200" "GET" "/moods/$MOOD_ID"
|
||||
expect "mood preview" "200" "GET" "/moods/$MOOD_ID/preview?limit=10"
|
||||
expect_eq "preview is not empty" "yes" "$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;print("yes" if json.load(sys.stdin)["songs"] else "no")')"
|
||||
expect "add seed" "200" "POST" "/moods/$MOOD_ID/seeds" "{\"songId\":\"$SONG2_ID\"}"
|
||||
expect_eq "seed count after add" "2" "$(printf '%s' "$HTTP_BODY" | json_field '["mood"]["seedCount"]')"
|
||||
expect "remove seed" "204" "DELETE" "/moods/$MOOD_ID/seeds/$SONG2_ID"
|
||||
expect "get mood after seed removal" "200" "GET" "/moods/$MOOD_ID"
|
||||
expect_eq "seed count after remove" "1" "$(printf '%s' "$HTTP_BODY" | json_field '["mood"]["seedCount"]')"
|
||||
|
||||
log ""
|
||||
log "Radio sessions"
|
||||
expect "start session" "201" "POST" "/moods/$MOOD_ID/sessions" '{"limit":10}'
|
||||
SESSION_ID="$(printf '%s' "$HTTP_BODY" | json_field '["id"]' 2>/dev/null || true)"
|
||||
if [[ -n "$SESSION_ID" ]]; then pass "session id"; else fail "session id" "${HTTP_BODY:0:200}"; fi
|
||||
expect_eq "queue contains seed" "yes" "$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;print("yes" if any(s["id"]=="'"$SONG_ID"'" for s in json.load(sys.stdin)["queue"]) else "no")')"
|
||||
expect_eq "queue excludes longform" "yes" "$(printf '%s' "$HTTP_BODY" | python3 -c 'import json,sys;print("yes" if all(s["id"]!="'"$LONG_ID"'" for s in json.load(sys.stdin)["queue"]) else "no")')"
|
||||
expect "next tracks" "200" "POST" "/sessions/$SESSION_ID/next" '{"limit":10}'
|
||||
expect "playback event" "200" "POST" "/sessions/$SESSION_ID/events" \
|
||||
"{\"events\":[{\"songId\":\"$SONG_ID\",\"type\":\"completed\",\"positionSeconds\":2}]}"
|
||||
expect_eq "accepted events" "1" "$(printf '%s' "$HTTP_BODY" | json_field '["accepted"]')"
|
||||
expect "add playing track to current mood" "200" "POST" "/sessions/$SESSION_ID/add-to-mood" \
|
||||
"{\"songId\":\"$SONG2_ID\"}"
|
||||
expect_eq "seed count after add-to-mood" "2" "$(printf '%s' "$HTTP_BODY" | json_field '["mood"]["seedCount"]')"
|
||||
expect "resume session" "200" "GET" "/sessions/$SESSION_ID"
|
||||
expect_eq "session mood" "$MOOD_ID" "$(printf '%s' "$HTTP_BODY" | json_field '["moodId"]')"
|
||||
expect "close session" "204" "DELETE" "/sessions/$SESSION_ID"
|
||||
|
||||
log ""
|
||||
log "Media"
|
||||
STREAM_STATUS="$(curl -s -o "$WORK/stream.mp3" -w '%{http_code}' \
|
||||
"$BASE/api/v1/songs/$SONG_ID/stream?token=$TOKEN")"
|
||||
if [[ "$STREAM_STATUS" == "200" && -s "$WORK/stream.mp3" ]]; then
|
||||
pass "stream"
|
||||
pass "stream with query token"
|
||||
else
|
||||
fail "stream" "HTTP $STREAM_STATUS, $(wc -c < "$WORK/stream.mp3" 2>/dev/null || echo 0) bytes"
|
||||
fail "stream with query token" "HTTP $STREAM_STATUS"
|
||||
fi
|
||||
|
||||
RANGE_STATUS="$(curl -s -o /dev/null -w '%{http_code}' -H 'Range: bytes=0-9' "$BASE/rest/stream.view?$AUTH&id=$SONG_ID")"
|
||||
if [[ "$RANGE_STATUS" == "206" ]]; then pass "stream range"; else fail "stream range" "HTTP $RANGE_STATUS"; fi
|
||||
RANGE_STATUS="$(curl -s -o /dev/null -w '%{http_code}' -H 'Range: bytes=0-9' \
|
||||
"$BASE/api/v1/songs/$SONG_ID/stream?token=$TOKEN")"
|
||||
expect_eq "stream range" "206" "$RANGE_STATUS"
|
||||
|
||||
TRANSCODE_STATUS="$(curl -s -D "$WORK/transcode.headers" -o "$WORK/transcoded.mp3" -w '%{http_code}' "$BASE/rest/stream.view?$AUTH&id=$SONG_ID&maxBitRate=64")"
|
||||
TRANSCODE_STATUS="$(curl -s -D "$WORK/transcode.headers" -o "$WORK/transcoded.mp3" -w '%{http_code}' \
|
||||
"$BASE/api/v1/songs/$SONG_ID/stream?token=$TOKEN&maxBitRate=64")"
|
||||
if [[ "$TRANSCODE_STATUS" == "200" && -s "$WORK/transcoded.mp3" ]] \
|
||||
&& grep -qi '^content-type: audio/mpeg' "$WORK/transcode.headers" \
|
||||
&& [[ $(wc -c < "$WORK/transcoded.mp3") -lt $(wc -c < "$WORK/stream.mp3") ]]; then
|
||||
pass "stream transcode (maxBitRate)"
|
||||
&& grep -qi '^content-type: audio/mpeg' "$WORK/transcode.headers"; then
|
||||
pass "stream transcode"
|
||||
else
|
||||
fail "stream transcode (maxBitRate)" "HTTP $TRANSCODE_STATUS, $(wc -c < "$WORK/transcoded.mp3" 2>/dev/null || echo 0) bytes"
|
||||
fail "stream transcode" "HTTP $TRANSCODE_STATUS"
|
||||
fi
|
||||
|
||||
OFFSET_STATUS="$(curl -s -o "$WORK/offset.mp3" -w '%{http_code}' "$BASE/rest/stream.view?$AUTH&id=$SONG_ID&timeOffset=1")"
|
||||
if [[ "$OFFSET_STATUS" == "200" && -s "$WORK/offset.mp3" ]] \
|
||||
&& [[ $(wc -c < "$WORK/offset.mp3") -lt $(wc -c < "$WORK/stream.mp3") ]]; then
|
||||
pass "stream transcode (timeOffset)"
|
||||
DOWNLOAD_STATUS="$(curl -s -o "$WORK/download.mp3" -w '%{http_code}' \
|
||||
"$BASE/api/v1/songs/$SONG_ID/stream?token=$TOKEN&download=true")"
|
||||
if [[ "$DOWNLOAD_STATUS" == "200" && -s "$WORK/download.mp3" ]]; then
|
||||
pass "download original"
|
||||
else
|
||||
fail "stream transcode (timeOffset)" "HTTP $OFFSET_STATUS"
|
||||
fail "download original" "HTTP $DOWNLOAD_STATUS"
|
||||
fi
|
||||
|
||||
FORMAT_STATUS="$(curl -s -o "$WORK/format.mp3" -w '%{http_code}' "$BASE/rest/stream.view?$AUTH&id=$SONG_ID&format=flac")"
|
||||
if [[ "$FORMAT_STATUS" == "200" && -s "$WORK/format.mp3" ]]; then
|
||||
pass "stream transcode (format fallback)"
|
||||
else
|
||||
fail "stream transcode (format fallback)" "HTTP $FORMAT_STATUS"
|
||||
fi
|
||||
|
||||
DOWNLOAD_STATUS="$(curl -s -o /dev/null -w '%{http_code}' "$BASE/rest/download.view?$AUTH&id=$SONG_ID")"
|
||||
if [[ "$DOWNLOAD_STATUS" == "200" ]]; then pass "download"; else fail "download" "HTTP $DOWNLOAD_STATUS"; fi
|
||||
|
||||
COVER_STATUS="$(curl -s -o "$WORK/cover.jpg" -w '%{http_code}' "$BASE/rest/getCoverArt.view?$AUTH&id=$ALBUM_ID&size=32")"
|
||||
COVER_STATUS="$(curl -s -o "$WORK/cover.jpg" -w '%{http_code}' \
|
||||
"$BASE/api/v1/covers/$ALBUM_ID?size=32&token=$TOKEN")"
|
||||
if [[ "$COVER_STATUS" == "200" && -s "$WORK/cover.jpg" ]]; then
|
||||
pass "getCoverArt"
|
||||
pass "cover art"
|
||||
else
|
||||
fail "getCoverArt" "HTTP $COVER_STATUS"
|
||||
fail "cover art" "HTTP $COVER_STATUS"
|
||||
fi
|
||||
|
||||
expect "scan status" "200" "GET" "/scan"
|
||||
expect "start scan" "202" "POST" "/scan"
|
||||
|
||||
log ""
|
||||
log "Cleanup"
|
||||
expect "delete mood" "204" "DELETE" "/moods/$MOOD_ID"
|
||||
expect "logout" "204" "POST" "/auth/logout"
|
||||
api "GET" "/me" "" "$TOKEN"
|
||||
expect_eq "token revoked after logout" "401" "$HTTP_STATUS"
|
||||
|
||||
log ""
|
||||
log "Smoke test finished: $PASSED passed, $FAILED failed"
|
||||
log "Server log: $WORK/server.log"
|
||||
|
||||
Reference in new issue
Block a user