-
Notifications
You must be signed in to change notification settings - Fork 0
/
recording_handler_test.go
94 lines (68 loc) · 4.22 KB
/
recording_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
assert "github.com/pilu/miniassert"
"testing"
)
func TestRecordingHandler_WithExistingRecordingId(t *testing.T) {
recorder := newTestRequest("GET", "/recordings/833f00e1-781f-4edd-90e4-e52712618862.json")
body := string(recorder.Body.Bytes())
expectedBody := `{"id":"833f00e1-781f-4edd-90e4-e52712618862","name":"Get Lucky","comment":"","length":367000,"artists":[{"id":"056e4f3e-d505-4dad-8ec1-d04f521cbb56","name":"Daft Punk"},{"id":"149f91ef-1287-46da-9a8e-87fee02f1471","name":"Pharrell Williams"}]}` + "\n"
assert.Equal(t, expectedBody, body)
assert.Equal(t, 200, recorder.Code)
}
func TestRecordingHandler_WithRecordingIdNotFound(t *testing.T) {
recorder := newTestRequest("GET", "/recordings/00000000-0000-0000-0000-000000000000.json")
body := string(recorder.Body.Bytes())
assert.Equal(t, `{"error":"recording not found"}`+"\n", body)
assert.Equal(t, 404, recorder.Code)
}
func TestRecordingHandler_WithInvalidRecordingId(t *testing.T) {
recorder := newTestRequest("GET", "/recordings/bad-uuid.json")
body := string(recorder.Body.Bytes())
assert.Equal(t, "", body)
assert.Equal(t, 400, recorder.Code)
}
func TestRecordingHandler_WithNonExistingReleaseIdAndExistingRecordingId(t *testing.T) {
recorder := newTestRequest("GET", "/releases/00000000-0000-0000-0000-000000000000/recordings/833f00e1-781f-4edd-90e4-e52712618862.json")
body := string(recorder.Body.Bytes())
expectedBody := `{"error":"release not found"}` + "\n"
assert.Equal(t, expectedBody, body)
assert.Equal(t, 404, recorder.Code)
}
func TestRecordingHandler_WithWrongReleaseIdAndExistingRecordingId(t *testing.T) {
// Release is "Harder, Better, Faster, Stronger" but recording is "Get Lucky" which is in "Random Access Memories"
recorder := newTestRequest("GET", "/releases/e1ed2270-c44f-4c72-8836-140579b211fa/recordings/833f00e1-781f-4edd-90e4-e52712618862.json")
body := string(recorder.Body.Bytes())
expectedBody := `{"error":"recording not found"}` + "\n"
assert.Equal(t, expectedBody, body)
assert.Equal(t, 404, recorder.Code)
}
func TestRecordingHandler_WithExistingReleaseIdAndRecordingId(t *testing.T) {
recorder := newTestRequest("GET", "/releases/79215cdf-4764-4dee-b0b9-fec1643df7c5/recordings/833f00e1-781f-4edd-90e4-e52712618862.json")
body := string(recorder.Body.Bytes())
expectedBody := `{"id":"833f00e1-781f-4edd-90e4-e52712618862","name":"Get Lucky","comment":"","length":367000,"artists":[{"id":"056e4f3e-d505-4dad-8ec1-d04f521cbb56","name":"Daft Punk"},{"id":"149f91ef-1287-46da-9a8e-87fee02f1471","name":"Pharrell Williams"}]}` + "\n"
assert.Equal(t, expectedBody, body)
assert.Equal(t, 200, recorder.Code)
}
func TestRecordingHandler_WithNonExistingArtistIdAndExistingReleaseIdAndRecordingId(t *testing.T) {
recorder := newTestRequest("GET", "/artists/00000000-0000-0000-0000-000000000000/releases/79215cdf-4764-4dee-b0b9-fec1643df7c5/recordings/833f00e1-781f-4edd-90e4-e52712618862.json")
body := string(recorder.Body.Bytes())
expectedBody := `{"error":"artist not found"}` + "\n"
assert.Equal(t, expectedBody, body)
assert.Equal(t, 404, recorder.Code)
}
func TestRecordingHandler_WithWrongArtistIdAndExistingReleaseIdAndRecordingId(t *testing.T) {
// Artist is Guns'n'Roses but release is "Random Access Memories" by Daft Punk
recorder := newTestRequest("GET", "/artists/eeb1195b-f213-4ce1-b28c-8565211f8e43/releases/79215cdf-4764-4dee-b0b9-fec1643df7c5/recordings/833f00e1-781f-4edd-90e4-e52712618862.json")
body := string(recorder.Body.Bytes())
expectedBody := `{"error":"release not found"}` + "\n"
assert.Equal(t, expectedBody, body)
assert.Equal(t, 404, recorder.Code)
}
func TestRecordingHandler_WithExistingArtistIdAndReleaseIdAndRecordingId(t *testing.T) {
recorder := newTestRequest("GET", "/artists/056e4f3e-d505-4dad-8ec1-d04f521cbb56/releases/79215cdf-4764-4dee-b0b9-fec1643df7c5/recordings/833f00e1-781f-4edd-90e4-e52712618862.json")
body := string(recorder.Body.Bytes())
expectedBody := `{"id":"833f00e1-781f-4edd-90e4-e52712618862","name":"Get Lucky","comment":"","length":367000,"artists":[{"id":"056e4f3e-d505-4dad-8ec1-d04f521cbb56","name":"Daft Punk"},{"id":"149f91ef-1287-46da-9a8e-87fee02f1471","name":"Pharrell Williams"}]}` + "\n"
assert.Equal(t, expectedBody, body)
assert.Equal(t, 200, recorder.Code)
}