Deezer authentication and loves export

This commit is contained in:
Philipp Wolfer 2023-11-23 15:30:43 +01:00
parent f447a259d4
commit 3a364b6ae4
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
11 changed files with 685 additions and 0 deletions

View file

@ -0,0 +1,50 @@
/*
Copyright © 2023 Philipp Wolfer <phw@uploadedlobster.com>
Scotty is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later version.
Scotty is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
Scotty. If not, see <https://www.gnu.org/licenses/>.
*/
package deezer_test
import (
"encoding/json"
"os"
"testing"
"time"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uploadedlobster.com/scotty/backends/deezer"
)
func TestFromConfig(t *testing.T) {
config := viper.New()
config.Set("client-id", "someclientid")
config.Set("client-secret", "someclientsecret")
backend := (&deezer.DeezerApiBackend{}).FromConfig(config)
assert.IsType(t, &deezer.DeezerApiBackend{}, backend)
}
func TestLovedTrackAsLove(t *testing.T) {
data, err := os.ReadFile("testdata/track.json")
require.NoError(t, err)
track := deezer.LovedTrack{}
err = json.Unmarshal(data, &track)
require.NoError(t, err)
love := track.AsLove()
assert.Equal(t, time.Unix(1700743848, 0), love.Created)
assert.Equal(t, time.Duration(255*time.Second), love.Duration)
assert.Equal(t, "Never Take Me Alive", love.TrackName)
assert.Equal(t, "Outland", love.ReleaseName)
assert.Equal(t, "Spear Of Destiny", love.ArtistName())
}