feat: add translated and phonetic lyric previews
This commit is contained in:
1 parent
bfd84ccdb5
commit
783e620214
10 files changed
+680
-44
No files matched your search
+14
-1
@@ -15,7 +15,7 @@ func (fakeQQ) Search(keyword string, limit int) ([]song, error) {
|
||||
return []song{{Name: keyword, MID: "0004jPDk2eB2dt", Singer: "Tester", Interval: limit}}, nil
|
||||
}
|
||||
func (fakeQQ) Lyrics(string) (lyricResult, error) {
|
||||
return lyricResult{Code: 0, Lyric: "[00:01.00]line"}, nil
|
||||
return lyricResult{Code: 0, Lyric: "[00:01.00]line", Trans: "[00:01.00]翻译", Roma: "[00:01.00]sound"}, nil
|
||||
}
|
||||
|
||||
func testApp() (*localApp, http.Handler, fs.FS) {
|
||||
@@ -103,3 +103,16 @@ func TestRejectsInvalidMID(t *testing.T) {
|
||||
t.Fatalf("expected 400, got %d", w.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLyricsReturnsAvailableTranslationAndPhonetics(t *testing.T) {
|
||||
_, handler, _ := testApp()
|
||||
r := request(http.MethodPost, "http://127.0.0.1:18765/api/lyrics", `{"mid":"0004jPDk2eB2dt"}`)
|
||||
r.AddCookie(validSessionCookie())
|
||||
r.Header.Set("Content-Type", "application/json")
|
||||
r.Header.Set("Origin", "http://127.0.0.1:18765")
|
||||
w := httptest.NewRecorder()
|
||||
handler.ServeHTTP(w, r)
|
||||
if w.Code != http.StatusOK || !strings.Contains(w.Body.String(), `"trans":"[00:01.00]翻译"`) || !strings.Contains(w.Body.String(), `"roma":"[00:01.00]sound"`) {
|
||||
t.Fatalf("status=%d body=%s", w.Code, w.Body.String())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user