Skip to content

Commit

Permalink
Added chapter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahcks committed Jul 24, 2023
1 parent ff1c3b5 commit 06f0be3
Show file tree
Hide file tree
Showing 3 changed files with 466 additions and 0 deletions.
45 changes: 45 additions & 0 deletions chapters_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package spotify

import (
"fmt"
"net/http"
"testing"
)

func TestGetAChapter(t *testing.T) {
client, server := testClientFile(http.StatusOK, "get_a_chapter.txt")
defer server.Close()

res, err := client.GetAChapter("0D5wENdkdwbqlrHoaJ9g29", "ES")
if err != nil {
t.Fatal(err)
}

fmt.Println(res)

if res == nil {
t.Error("Expected response")
} else {
if res.ID != "0D5wENdkdwbqlrHoaJ9g29" {
t.Errorf("Expected %s, got %s", "0D5wENdkdwbqlrHoaJ9g29", res.ID)
}
}
}

func TestGetSeveralChapters(t *testing.T) {
client, server := testClientFile(http.StatusOK, "get_several_chapters.txt")
defer server.Close()

res, err := client.GetSeveralChapters([]string{"0IsXVP0JmcB2adSE338GkK", "3ZXb8FKZGU0EHALYX6uCzU", "0D5wENdkdwbqlrHoaJ9g29"}, "ES")
if err != nil {
t.Fatal(err)
}

if res != nil {
if len(res.Chapters) != 3 {
t.Errorf("Expected %d, got %d", 3, len(res.Chapters))
}
} else {
t.Error("Expected response")
}
}
103 changes: 103 additions & 0 deletions test_json/get_a_chapter.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"restrictions": {
"reason": "payment_required"
},
"id": "0D5wENdkdwbqlrHoaJ9g29",
"description": "",
"chapter_number": 0,
"duration_ms": 42841,
"explicit": false,
"images": [
{
"height": 640,
"url": "https://i.scdn.co/image/ab676663000022a87e6216b6bf7861e7b8ceca4d",
"width": 640
},
{
"height": 300,
"url": "https://i.scdn.co/image/ab6766630000db5b7e6216b6bf7861e7b8ceca4d",
"width": 300
},
{
"height": 64,
"url": "https://i.scdn.co/image/ab6766630000703b7e6216b6bf7861e7b8ceca4d",
"width": 64
}
],
"languages": [
""
],
"name": "Introduction",
"audio_preview_url": null,
"release_date": "1970-01-01",
"release_date_precision": "day",
"resume_point": {
"fully_played": false,
"resume_position_ms": 0
},
"is_playable": false,
"html_description": "",
"audiobook": {
"authors": [
{
"name": "Cixin Liu"
}
],
"chapters": {
"href": null,
"items": [],
"limit": 0,
"next": null,
"offset": 0,
"previous": null,
"total": null
},
"copyrights": [],
"description": "Author(s): Cixin Liu\nNarrator(s): Luke Daniels\n\n<p><i>The Three-Body Problem </i>is the first chance for English-speaking readers to experience the Hugo Award-winning phenomenon from China's most beloved science fiction author, Liu Cixin.</p><p>Set against the backdrop of China's Cultural Revolution, a secret military project sends signals into space to establish contact with aliens. An alien civilization on the brink of destruction captures the signal and plans to invade Earth. </P><P>Meanwhile, on Earth, different camps start forming, planning to either welcome the superior beings and help them take over a world seen as corrupt, or to fight against the invasion. The result is a science fiction masterpiece of enormous scope and vision.</p></p><P>A Macmillan Audio production.</P>",
"edition": null,
"explicit": false,
"external_urls": {
"spotify": "https://open.spotify.com/show/1lxwPzRvQTVbwwoEdxyt6b"
},
"href": "https://api.spotify.com/v1/audiobooks/1lxwPzRvQTVbwwoEdxyt6b",
"html_description": "Author(s): Cixin Liu<br/>Narrator(s): Luke Daniels<br/>&lt;p&gt;&lt;i&gt;The Three-Body Problem &lt;/i&gt;is the first chance for English-speaking readers to experience the Hugo Award-winning phenomenon from China&#39;s most beloved science fiction author, Liu Cixin.&lt;/p&gt;&lt;p&gt;Set against the backdrop of China&#39;s Cultural Revolution, a secret military project sends signals into space to establish contact with aliens. An alien civilization on the brink of destruction captures the signal and plans to invade Earth. &lt;/P&gt;&lt;P&gt;Meanwhile, on Earth, different camps start forming, planning to either welcome the superior beings and help them take over a world seen as corrupt, or to fight against the invasion. The result is a science fiction masterpiece of enormous scope and vision.&lt;/p&gt;&lt;/p&gt;&lt;P&gt;A Macmillan Audio production.&lt;/P&gt;",
"id": "1lxwPzRvQTVbwwoEdxyt6b",
"images": [
{
"height": 640,
"url": "https://i.scdn.co/image/ab676663000022a87e6216b6bf7861e7b8ceca4d",
"width": 640
},
{
"height": 300,
"url": "https://i.scdn.co/image/ab6766630000db5b7e6216b6bf7861e7b8ceca4d",
"width": 300
},
{
"height": 64,
"url": "https://i.scdn.co/image/ab6766630000703b7e6216b6bf7861e7b8ceca4d",
"width": 64
}
],
"languages": [
"English"
],
"media_type": "audio",
"name": "The Three-Body Problem",
"narrators": [
{
"name": "Luke Daniels"
}
],
"publisher": "Macmillan Audio",
"total_chapters": null,
"type": "audiobook",
"uri": "spotify:show:1lxwPzRvQTVbwwoEdxyt6b"
},
"type": "chapter",
"uri": "spotify:episode:0D5wENdkdwbqlrHoaJ9g29",
"href": "https://api.spotify.com/v1/chapters/0D5wENdkdwbqlrHoaJ9g29",
"external_urls": {
"spotify": "https://open.spotify.com/episode/0D5wENdkdwbqlrHoaJ9g29"
}
}
Loading

0 comments on commit 06f0be3

Please sign in to comment.