-
Notifications
You must be signed in to change notification settings - Fork 0
/
releases_handler_test.go
53 lines (40 loc) · 1.95 KB
/
releases_handler_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
assert "github.com/pilu/miniassert"
"testing"
)
func TestReleasesHandler_WithExistingArtistId(t *testing.T) {
recorder := newTestRequest("GET", "/artists/056e4f3e-d505-4dad-8ec1-d04f521cbb56/releases.json")
assert.Equal(t, 200, recorder.Code)
}
func TestReleasesHandler_WithArtistIdNotFound(t *testing.T) {
recorder := newTestRequest("GET", "/artists/00000000-0000-0000-0000-000000000000/releases.json")
body := string(recorder.Body.Bytes())
assert.Equal(t, `{"error":"artist not found"}`+"\n", body)
assert.Equal(t, 404, recorder.Code)
}
func TestReleasesHandler_WithInvalidUUID(t *testing.T) {
recorder := newTestRequest("GET", "/artists/bad-uuid/releases.json")
body := string(recorder.Body.Bytes())
assert.Equal(t, "", body)
assert.Equal(t, 400, recorder.Code)
}
func TestReleasesHandler_WithExistingArtistIdAndReleaseGroupId(t *testing.T) {
recorder := newTestRequest("GET", "/artists/056e4f3e-d505-4dad-8ec1-d04f521cbb56/release-groups/aa997ea0-2936-40bd-884d-3af8a0e064dc/releases.json")
assert.Equal(t, 200, recorder.Code)
}
func TestReleaseHandler_WithExistingArtistIdAndNonExistingReleaseGroupId(t *testing.T) {
recorder := newTestRequest("GET", "/artists/056e4f3e-d505-4dad-8ec1-d04f521cbb56/release-groups/00000000-0000-0000-0000-000000000000/releases.json")
body := string(recorder.Body.Bytes())
expectedBody := `{"error":"release group not found"}` + "\n"
assert.Equal(t, expectedBody, body)
assert.Equal(t, 404, recorder.Code)
}
func TestReleasesHandler_WithExistingArtistIdAndWrongReleaseGroupId(t *testing.T) {
// Artist is Guns'n'Roses but release group is "Random Access Memories" by Daft Punk
recorder := newTestRequest("GET", "/artists/eeb1195b-f213-4ce1-b28c-8565211f8e43/release-groups/aa997ea0-2936-40bd-884d-3af8a0e064dc/releases.json")
body := string(recorder.Body.Bytes())
expectedBody := `{"error":"release group not found"}` + "\n"
assert.Equal(t, expectedBody, body)
assert.Equal(t, 404, recorder.Code)
}