mirror of
https://github.com/gabehf/Koito.git
synced 2026-03-15 10:25:55 -07:00
test: add integration test
This commit is contained in:
parent
52e955b1b6
commit
6cb655166f
1 changed files with 27 additions and 0 deletions
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -890,3 +891,29 @@ func TestSetPrimaryArtist(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.EqualValues(t, 1, count, "expected only one primary artist for track")
|
assert.EqualValues(t, 1, count, "expected only one primary artist for track")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestManualListen(t *testing.T) {
|
||||||
|
|
||||||
|
t.Run("Submit Listens", doSubmitListens)
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
// happy
|
||||||
|
formdata := url.Values{}
|
||||||
|
formdata.Set("track_id", "1")
|
||||||
|
formdata.Set("unix", strconv.FormatInt(time.Now().Unix()-60, 10))
|
||||||
|
body := formdata.Encode()
|
||||||
|
resp, err := makeAuthRequest(t, session, "POST", "/apis/web/v1/listen", strings.NewReader(body))
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, http.StatusCreated, resp.StatusCode)
|
||||||
|
count, _ := store.Count(ctx, `SELECT COUNT(*) FROM listens WHERE track_id = $1`, 1)
|
||||||
|
assert.Equal(t, 2, count)
|
||||||
|
|
||||||
|
// 400
|
||||||
|
formdata.Set("track_id", "1")
|
||||||
|
formdata.Set("unix", strconv.FormatInt(time.Now().Unix()+60, 10))
|
||||||
|
body = formdata.Encode()
|
||||||
|
resp, err = makeAuthRequest(t, session, "POST", "/apis/web/v1/listen", strings.NewReader(body))
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue