mirror of
https://github.com/gabehf/Koito.git
synced 2026-03-07 21:48:18 -08:00
chore: initial public commit
This commit is contained in:
commit
fc9054b78c
250 changed files with 32809 additions and 0 deletions
64
engine/import_test.go
Normal file
64
engine/import_test.go
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
package engine_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/gabehf/koito/engine"
|
||||
"github.com/gabehf/koito/internal/cfg"
|
||||
"github.com/gabehf/koito/internal/db"
|
||||
"github.com/gabehf/koito/internal/logger"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestImportMaloja(t *testing.T) {
|
||||
|
||||
src := "../static/maloja_import_test.json"
|
||||
destDir := filepath.Join(cfg.ConfigDir(), "import")
|
||||
dest := filepath.Join(destDir, "maloja_import_test.json")
|
||||
|
||||
// not going to make the dest dir because engine should make it already
|
||||
|
||||
input, err := os.ReadFile(src)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, os.WriteFile(dest, input, os.ModePerm))
|
||||
|
||||
engine.RunImporter(logger.Get(), store)
|
||||
|
||||
// maloja test import is 38 Magnify Tokyo streams
|
||||
a, err := store.GetArtist(context.Background(), db.GetArtistOpts{Name: "Magnify Tokyo"})
|
||||
require.NoError(t, err)
|
||||
t.Log(a)
|
||||
assert.Equal(t, "Magnify Tokyo", a.Name)
|
||||
assert.EqualValues(t, 38, a.ListenCount)
|
||||
}
|
||||
|
||||
func TestImportSpotify(t *testing.T) {
|
||||
|
||||
src := "../static/Streaming_History_Audio_spotify_import_test.json"
|
||||
destDir := filepath.Join(cfg.ConfigDir(), "import")
|
||||
dest := filepath.Join(destDir, "Streaming_History_Audio_spotify_import_test.json")
|
||||
|
||||
// not going to make the dest dir because engine should make it already
|
||||
|
||||
input, err := os.ReadFile(src)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, os.WriteFile(dest, input, os.ModePerm))
|
||||
|
||||
engine.RunImporter(logger.Get(), store)
|
||||
|
||||
a, err := store.GetArtist(context.Background(), db.GetArtistOpts{Name: "The Story So Far"})
|
||||
require.NoError(t, err)
|
||||
track, err := store.GetTrack(context.Background(), db.GetTrackOpts{Title: "Clairvoyant", ArtistIDs: []int32{a.ID}})
|
||||
require.NoError(t, err)
|
||||
t.Log(track)
|
||||
assert.Equal(t, "Clairvoyant", track.Title)
|
||||
// spotify includes duration data, but we only import when reason_end = trackdone
|
||||
// this is the only track with valid duration data
|
||||
assert.EqualValues(t, 181, track.Duration)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue