-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathe2e.js
157 lines (132 loc) · 5.17 KB
/
e2e.js
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// ブラウザで /api/v3/login でログインした後、Chrome Dev Consoleに貼り付けてください。
console.log("----------STEP1 : 自分の情報を取得----------")
const getMeRes = await fetch("http://relaym.local:8080/api/v3/users/me", {
"headers": {
"X-CSRF-TOKEN": "relaym",
"content-type":"application/json"
},
"method": "GET",
"mode": "cors",
"credentials": "include"
});
console.assert(getMeRes.ok,"自分の情報を取得に失敗しました",getMeRes.status)
const user = await getMeRes.json()
console.log(user)
console.log("----------STEP2 : セッションの作成----------")
const sessionName = 'test'
const createSessionRes = await fetch("http://relaym.local:8080/api/v3/sessions", {
"headers": {
"X-CSRF-TOKEN": "relaym",
"content-type":"application/json"
},
"body": `{"name":"${sessionName}"}`,
"method": "POST",
"mode": "cors",
"credentials": "include"
});
console.assert(createSessionRes.ok,"セッションの作成に失敗しました",createSessionRes.status)
const session = await createSessionRes.json()
console.log(session)
console.log("----------STEP3 : デバイスを取得----------")
const getDevicesRes = await fetch(`http://relaym.local:8080/api/v3/sessions/${session.id}/devices`, {
"headers": {
"X-CSRF-TOKEN": "relaym",
"content-type":"application/json"
},
"method": "GET",
"mode": "cors",
"credentials": "include"
});
console.assert(getDevicesRes.ok,"デバイスの取得に失敗しました",getDevicesRes.status)
const devices = await getDevicesRes.json()
console.log(devices)
console.log("----------STEP4 : セッションに曲を追加(1曲目)----------")
const trackURI = 'spotify:track:5uQ0vKy2973Y9IUCd1wMEF'
const enqueueRes = await fetch(`http://relaym.local:8080/api/v3/sessions/${session.id}/queue`, {
"headers": {
"X-CSRF-TOKEN": "relaym",
"content-type":"application/json"
},
"body": `{"uri":"${trackURI}"}`,
"method": "POST",
"mode": "cors",
"credentials": "include"
});
console.assert(enqueueRes.ok,"キューへの追加に失敗しました",enqueueRes.status)
console.log("----------STEP5 : セッションに曲を追加(2曲目)----------")
const secondTrackURI = 'spotify:track:4BrmwVpDUCTNR0HzaO9Jpr'
const secondEnqueueRes = await fetch(`http://relaym.local:8080/api/v3/sessions/${session.id}/queue`, {
"headers": {
"X-CSRF-TOKEN": "relaym",
"content-type":"application/json"
},
"body": `{"uri":"${secondTrackURI}"}`,
"method": "POST",
"mode": "cors",
"credentials": "include"
});
console.assert(secondEnqueueRes.ok,"2曲目キューへの追加に失敗しました",secondEnqueueRes.status)
console.log("----------STEP6 : デバイスをセット----------")
const setDeviceRes = await fetch(`http://relaym.local:8080/api/v3/sessions/${session.id}/devices`, {
"headers": {
"X-CSRF-TOKEN": "relaym",
"content-type":"application/json"
},
"body": `{"device_id":"${devices.devices[0].id}"}`,
"method": "PUT",
"mode": "cors",
"credentials": "include"
});
console.assert(setDeviceRes.ok,"デバイスのセットに失敗しました",setDeviceRes.status)
console.log("----------STEP7 : 再生----------")
const playRes = await fetch(`http://relaym.local:8080/api/v3/sessions/${session.id}/state`, {
"headers": {
"X-CSRF-TOKEN": "relaym",
"content-type":"application/json"
},
"body": '{"state":"PLAY"}',
"method": "PUT",
"mode": "cors",
"credentials": "include"
});
console.assert(playRes.ok,"曲の再生に失敗しました",playRes.status)
const sleep = msec => new Promise(resolve => setTimeout(resolve, msec))
await sleep(5000)
console.log("----------STEP8 : 一時停止----------")
const pauseRes = await fetch(`http://relaym.local:8080/api/v3/sessions/${session.id}/state`, {
"headers": {
"X-CSRF-TOKEN": "relaym",
"content-type":"application/json"
},
"body": '{"state":"PAUSE"}',
"method": "PUT",
"mode": "cors",
"credentials": "include"
});
console.assert(pauseRes.ok,"曲の一時停止に失敗しました",pauseRes.status)
await sleep(5000)
console.log("----------STEP9 : 再度再生----------")
const rePlayRes = await fetch(`http://relaym.local:8080/api/v3/sessions/${session.id}/state`, {
"headers": {
"X-CSRF-TOKEN": "relaym",
"content-type":"application/json"
},
"body": '{"state":"PLAY"}',
"method": "PUT",
"mode": "cors",
"credentials": "include"
});
console.assert(rePlayRes.ok,"曲の再度再生に失敗しました",rePlayRes.status)
console.log("----------STEP10 : セッションに曲を追加(三曲目)----------")
const thirdTrackURI = 'spotify:track:36MwbWxhiFdyD29fhWJUoQ'
const thirdEnqueueRes = await fetch(`http://relaym.local:8080/api/v3/sessions/${session.id}/queue`, {
"headers": {
"X-CSRF-TOKEN": "relaym",
"content-type":"application/json"
},
"body": `{"uri":"${thirdTrackURI}"}`,
"method": "POST",
"mode": "cors",
"credentials": "include"
});
console.assert(thirdEnqueueRes.ok,"3曲目のキューへの追加に失敗しました",thirdEnqueueRes.status)