mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-16 10:09:28 +02:00
74 lines
2.9 KiB
Go
74 lines
2.9 KiB
Go
/*
|
|
Copyright © 2023 Philipp Wolfer <phw@uploadedlobster.com>
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
all copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
THE SOFTWARE.
|
|
*/
|
|
package funkwhale_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"go.uploadedlobster.com/scotty/backends/funkwhale"
|
|
"go.uploadedlobster.com/scotty/models"
|
|
)
|
|
|
|
func TestListenFromFunkwhale(t *testing.T) {
|
|
fwListen := funkwhale.Listening{
|
|
CreationDate: "2023-11-09T23:59:29.022005Z",
|
|
User: funkwhale.User{
|
|
UserName: "outsidecontext",
|
|
},
|
|
Track: funkwhale.Track{
|
|
Title: "Oweynagat",
|
|
RecordingMbid: "c0a1fc94-5f04-4a5f-bc09-e5de0c49cd12",
|
|
Position: 5,
|
|
DiscNumber: 1,
|
|
Tags: []string{"foo", "bar"},
|
|
Artist: funkwhale.Artist{
|
|
Name: "Dool",
|
|
ArtistMbid: "24412926-c7bd-48e8-afad-8a285b42e131",
|
|
},
|
|
Album: funkwhale.Album{
|
|
Title: "Here Now, There Then",
|
|
ReleaseMbid: "d7f22677-9803-4d21-ba42-081b633a6f68",
|
|
},
|
|
Uploads: []funkwhale.Upload{
|
|
{
|
|
Duration: 414,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
listen := funkwhale.ListenFromFunkwhale(fwListen)
|
|
assert.Equal(t, time.Unix(1699574369, 0).Unix(), listen.ListenedAt.Unix())
|
|
assert.Equal(t, fwListen.User.UserName, listen.UserName)
|
|
assert.Equal(t, time.Duration(414*time.Second), listen.Duration)
|
|
assert.Equal(t, fwListen.Track.Title, listen.TrackName)
|
|
assert.Equal(t, fwListen.Track.Album.Title, listen.ReleaseName)
|
|
assert.Equal(t, []string{fwListen.Track.Artist.Name}, listen.ArtistNames)
|
|
assert.Equal(t, fwListen.Track.Position, listen.Track.TrackNumber)
|
|
assert.Equal(t, fwListen.Track.Tags, listen.Track.Tags)
|
|
// assert.Equal(t, backends.FunkwhaleClientName, listen.AdditionalInfo["disc_number"])
|
|
assert.Equal(t, models.MBID(fwListen.Track.RecordingMbid), listen.RecordingMbid)
|
|
assert.Equal(t, models.MBID(fwListen.Track.Album.ReleaseMbid), listen.ReleaseMbid)
|
|
assert.Equal(t, models.MBID(fwListen.Track.Artist.ArtistMbid), listen.ArtistMbids[0])
|
|
assert.Equal(t, funkwhale.FunkwhaleClientName, listen.AdditionalInfo["media_player"])
|
|
}
|