museria 0.2.48 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. package/.eslintrc +10 -2
  2. package/.github/workflows/build.yml +3 -3
  3. package/.github/workflows/publish.yml +3 -3
  4. package/README.md +56 -60
  5. package/bin/actions.js +28 -28
  6. package/bin/index.js +4 -4
  7. package/bin/runner.js +1 -1
  8. package/bin/utils.js +6 -2
  9. package/dist/client/museria.client.js +7 -7
  10. package/dist/face/45a265d0f07b31cde85f.ttf +0 -0
  11. package/dist/face/6205fd00fb1b573e9f0f.ttf +0 -0
  12. package/dist/face/8d3cabfc66809162fb4d.woff2 +0 -0
  13. package/dist/face/fb8184add5a3101ad0a3.woff2 +0 -0
  14. package/dist/face/museria.face.js +33 -13
  15. package/dist/face/style.css +13 -11
  16. package/package.json +41 -40
  17. package/src/browser/client/index.js +2 -1
  18. package/src/browser/face/client.js +2 -1
  19. package/src/browser/face/controllers/app/app.html +77 -69
  20. package/src/browser/face/controllers/app/app.js +14 -7
  21. package/src/browser/face/controllers/app/app.scss +2 -22
  22. package/src/browser/face/index.js +3 -3
  23. package/src/browser/face/styles/main.scss +91 -11
  24. package/src/browser/face/styles/vars.scss +0 -1
  25. package/src/client.js +73 -74
  26. package/src/collection/transports/music/index.js +20 -18
  27. package/src/db/transports/database/index.js +7 -5
  28. package/src/db/transports/loki/index.js +30 -25
  29. package/src/errors.js +2 -1
  30. package/src/index.js +8 -6
  31. package/src/node.js +315 -323
  32. package/src/schema.js +27 -29
  33. package/src/server/transports/express/api/butler/controllers.js +7 -10
  34. package/src/server/transports/express/api/butler/routes.js +5 -5
  35. package/src/server/transports/express/api/master/controllers.js +7 -10
  36. package/src/server/transports/express/api/master/routes.js +5 -5
  37. package/src/server/transports/express/api/node/controllers.js +52 -61
  38. package/src/server/transports/express/api/node/routes.js +10 -10
  39. package/src/server/transports/express/api/routes.js +1 -1
  40. package/src/server/transports/express/api/slave/controllers.js +7 -10
  41. package/src/server/transports/express/api/slave/routes.js +6 -6
  42. package/src/server/transports/express/client/controllers.js +40 -61
  43. package/src/server/transports/express/client/routes.js +33 -39
  44. package/src/server/transports/express/controllers.js +10 -21
  45. package/src/server/transports/express/index.js +23 -20
  46. package/src/server/transports/express/midds.js +67 -67
  47. package/src/server/transports/express/routes.js +12 -12
  48. package/src/utils.js +175 -184
  49. package/test/client.js +311 -305
  50. package/test/db/database.js +32 -28
  51. package/test/db/loki.js +78 -74
  52. package/test/group.js +161 -156
  53. package/test/index.js +20 -10
  54. package/test/node.js +461 -460
  55. package/test/routes.js +404 -399
  56. package/test/server/express.js +35 -31
  57. package/test/services.js +25 -18
  58. package/test/tools.js +8 -6
  59. package/test/utils.js +236 -234
  60. package/webpack.client.js +9 -7
  61. package/webpack.face.js +8 -6
  62. package/dist/face/fa-brands-400.eot +0 -0
  63. package/dist/face/fa-brands-400.svg +0 -3717
  64. package/dist/face/fa-brands-400.ttf +0 -0
  65. package/dist/face/fa-brands-400.woff +0 -0
  66. package/dist/face/fa-brands-400.woff2 +0 -0
  67. package/dist/face/fa-solid-900.eot +0 -0
  68. package/dist/face/fa-solid-900.svg +0 -5034
  69. package/dist/face/fa-solid-900.ttf +0 -0
  70. package/dist/face/fa-solid-900.woff +0 -0
  71. package/dist/face/fa-solid-900.woff2 +0 -0
  72. /package/dist/face/{open-sans.ttf → 17e98b9e5586529b13cc.ttf} +0 -0
  73. /package/dist/face/{proxima-nova.ttf → 326601dfabd91e3f016c.ttf} +0 -0
  74. /package/dist/face/{logo.svg → ee9c6af64aa224827cec.svg} +0 -0
package/test/routes.js CHANGED
@@ -1,471 +1,476 @@
1
- const assert = require('chai').assert;
2
- const fse = require('fs-extra');
3
- const path = require('path');
4
- const fetch = require('node-fetch');
5
- const Node = require('../src/node')();
6
- const Client = require('../src/client')();
7
- const utils = require('../src/utils');
8
- const schema = require('../src/schema');
9
- const tools = require('./tools');
10
-
11
- describe('routes', () => {
12
- let node;
13
- let client;
14
-
15
- before(async function() {
16
- node = new Node(await tools.createNodeOptions({
17
- network: {
1
+ import { assert } from "chai";
2
+ import fse from "fs-extra";
3
+ import path from "path";
4
+ import fetch from "node-fetch";
5
+ import node from "../src/node.js";
6
+ import client from "../src/client.js";
7
+ import utils from "../src/utils.js";
8
+ import schema from "../src/schema.js";
9
+ import tools from "./tools.js";
10
+
11
+ const Node = node();
12
+ const Client = client();
13
+
14
+ export default function () {
15
+ describe('routes', () => {
16
+ let node;
17
+ let client;
18
+
19
+ before(async function () {
20
+ node = new Node(await tools.createNodeOptions({
21
+ network: {
22
+ auth: { username: 'username', password: 'password' }
23
+ }
24
+ }));
25
+ await node.init();
26
+ client = new Client(await tools.createClientOptions({
27
+ address: node.address,
18
28
  auth: { username: 'username', password: 'password' }
19
- }
20
- }));
21
- await node.init();
22
- client = new Client(await tools.createClientOptions({
23
- address: node.address,
24
- auth: { username: 'username', password: 'password' }
25
- }));
26
- await client.init();
27
- });
28
-
29
- after(async function() {
30
- await node.deinit();
31
- await client.deinit();
32
- });
29
+ }));
30
+ await client.init();
31
+ });
33
32
 
34
- describe('/status', function () {
35
- it('should return an auth error', async function () {
36
- const res = await fetch(`http://${node.address}/status`);
37
- assert.equal(await res.status, 401);
33
+ after(async function () {
34
+ await node.deinit();
35
+ await client.deinit();
38
36
  });
39
37
 
40
- it('should return the status', async function () {
41
- const options = client.createDefaultRequestOptions({ method: 'get' });
42
- const res = await fetch(`http://${node.address}/status`, options);
43
- const json = await res.json();
44
- assert.doesNotThrow(() => {
45
- utils.validateSchema(schema.getStatusResponse(), json);
38
+ describe('/status', function () {
39
+ it('should return an auth error', async function () {
40
+ const res = await fetch(`http://${node.address}/status`);
41
+ assert.equal(await res.status, 401);
46
42
  });
47
- });
48
43
 
49
- it('should return the pretty status', async function () {
50
- const options = client.createDefaultRequestOptions({ method: 'get' });
51
- const res = await fetch(`http://${node.address}/status?pretty`, options);
52
- const json = await res.json();
53
- assert.doesNotThrow(() => {
54
- utils.validateSchema(schema.getStatusPrettyResponse(), json);
44
+ it('should return the status', async function () {
45
+ const options = client.createDefaultRequestOptions({ method: 'get' });
46
+ const res = await fetch(`http://${node.address}/status`, options);
47
+ const json = await res.json();
48
+ assert.doesNotThrow(() => {
49
+ utils.validateSchema(schema.getStatusResponse(), json);
50
+ });
55
51
  });
56
- });
57
- });
58
52
 
59
- describe('/audio/:hash', function () {
60
- it('should return an auth error', async function () {
61
- const res = await fetch(`http://${node.address}/audio/hash`);
62
- assert.equal(await res.status, 401);
53
+ it('should return the pretty status', async function () {
54
+ const options = client.createDefaultRequestOptions({ method: 'get' });
55
+ const res = await fetch(`http://${node.address}/status?pretty`, options);
56
+ const json = await res.json();
57
+ assert.doesNotThrow(() => {
58
+ utils.validateSchema(schema.getStatusPrettyResponse(), json);
59
+ });
60
+ });
63
61
  });
64
62
 
65
- it('should return 404', async function () {
66
- const options = client.createDefaultRequestOptions({ method: 'get' });
67
- const res = await fetch(`http://${node.address}/audio/wrong-hash`, options);
68
- assert.equal(res.status, 404);
69
- });
63
+ describe('/audio/:hash', function () {
64
+ it('should return an auth error', async function () {
65
+ const res = await fetch(`http://${node.address}/audio/hash`);
66
+ assert.equal(await res.status, 401);
67
+ });
70
68
 
71
- it('should return the file', async function () {
72
- const title = 'artist - title';
73
- const file = await utils.setSongTags(path.join(tools.tmpPath, 'audio.mp3'), { fullTitle: title });
74
- await node.addSong(file);
75
- const doc = await node.db.getMusicByPk(title);
76
- const code = utils.encodeSongTitle(doc.title);
77
- const buffer = await fse.readFile(node.getFilePath(doc.fileHash));
78
- const filePath = path.join(tools.tmpPath, 'audio-saved.mp3');
79
- const options = client.createDefaultRequestOptions({ method: 'get' });
80
- const res = await fetch(`http://${node.address}/audio/${ code }?${doc.fileHash}`, options);
81
- await tools.saveResponseToFile(res, filePath);
82
- assert.isOk(Buffer.compare(await fse.readFile(filePath), buffer) == 0);
83
- });
84
- });
69
+ it('should return 404', async function () {
70
+ const options = client.createDefaultRequestOptions({ method: 'get' });
71
+ const res = await fetch(`http://${node.address}/audio/wrong-hash`, options);
72
+ assert.equal(res.status, 404);
73
+ });
85
74
 
86
- describe('/cover/:hash', function () {
87
- it('should return an auth error', async function () {
88
- const res = await fetch(`http://${node.address}/cover/hash`);
89
- assert.equal(await res.status, 401);
75
+ it('should return the file', async function () {
76
+ const title = 'artist - title';
77
+ const file = await utils.setSongTags(path.join(tools.tmpPath, 'audio.mp3'), { fullTitle: title });
78
+ await node.addSong(file);
79
+ const doc = await node.db.getMusicByPk(title);
80
+ const code = utils.encodeSongTitle(doc.title);
81
+ const buffer = await fse.readFile(node.getFilePath(doc.fileHash));
82
+ const filePath = path.join(tools.tmpPath, 'audio-saved.mp3');
83
+ const options = client.createDefaultRequestOptions({ method: 'get' });
84
+ const res = await fetch(`http://${node.address}/audio/${code}?${doc.fileHash}`, options);
85
+ await tools.saveResponseToFile(res, filePath);
86
+ assert.isOk(Buffer.compare(await fse.readFile(filePath), buffer) == 0);
87
+ });
90
88
  });
91
89
 
92
- it('should return 404', async function () {
93
- const options = client.createDefaultRequestOptions({ method: 'get' });
94
- const res = await fetch(`http://${node.address}/cover/wrong-hash`, options);
95
- assert.equal(res.status, 404);
96
- });
90
+ describe('/cover/:hash', function () {
91
+ it('should return an auth error', async function () {
92
+ const res = await fetch(`http://${node.address}/cover/hash`);
93
+ assert.equal(await res.status, 401);
94
+ });
97
95
 
98
- it('should return the file', async function () {
99
- const title = 'artist - title';
100
- const file = await utils.setSongTags(path.join(tools.tmpPath, 'audio.mp3'), {
101
- fullTitle: title,
102
- APIC: path.join(tools.tmpPath, 'cover.jpg')
103
- });
104
- await node.addSong(file);
105
- const doc = await node.db.getMusicByPk(title);
106
- const code = utils.encodeSongTitle(doc.title);
107
- const buffer = (await utils.getSongTags(node.getFilePath(doc.fileHash))).APIC
108
- const filePath = path.join(tools.tmpPath, 'cover-saved.jpg');
109
- const options = client.createDefaultRequestOptions({ method: 'get' });
110
- const res = await fetch(`http://${node.address}/cover/${ code }?${doc.fileHash}`, options);
111
- await tools.saveResponseToFile(res, filePath);
112
- assert.isOk(Buffer.compare(await fse.readFile(filePath), buffer) == 0);
113
- });
114
- });
96
+ it('should return 404', async function () {
97
+ const options = client.createDefaultRequestOptions({ method: 'get' });
98
+ const res = await fetch(`http://${node.address}/cover/wrong-hash`, options);
99
+ assert.equal(res.status, 404);
100
+ });
115
101
 
116
- describe('/client/request-song', function () {
117
- it('should return an auth error', async function () {
118
- const res = await fetch(`http://${node.address}/client/request-song`, { method: 'get' });
119
- assert.equal(await res.status, 401);
102
+ it('should return the file', async function () {
103
+ const title = 'artist - title';
104
+ const file = await utils.setSongTags(path.join(tools.tmpPath, 'audio.mp3'), {
105
+ fullTitle: title,
106
+ APIC: path.join(tools.tmpPath, 'cover.jpg')
107
+ });
108
+ await node.addSong(file);
109
+ const doc = await node.db.getMusicByPk(title);
110
+ const code = utils.encodeSongTitle(doc.title);
111
+ const buffer = (await utils.getSongTags(node.getFilePath(doc.fileHash))).APIC;
112
+ const filePath = path.join(tools.tmpPath, 'cover-saved.jpg');
113
+ const options = client.createDefaultRequestOptions({ method: 'get' });
114
+ const res = await fetch(`http://${node.address}/cover/${code}?${doc.fileHash}`, options);
115
+ await tools.saveResponseToFile(res, filePath);
116
+ assert.isOk(Buffer.compare(await fse.readFile(filePath), buffer) == 0);
117
+ });
120
118
  });
121
119
 
122
- it('should return an error because of a wrong title', async function () {
123
- const options = client.createDefaultRequestOptions({ method: 'get' });
124
- const res = await fetch(`http://${node.address}/client/request-song/?type=audio`, options);
125
- assert.equal(res.status, 422, 'check the status');
126
- assert.isOk((await res.json()).message.match('Wrong song title'), 'check the message');
127
- });
120
+ describe('/client/request-song', function () {
121
+ it('should return an auth error', async function () {
122
+ const res = await fetch(`http://${node.address}/client/request-song`, { method: 'get' });
123
+ assert.equal(await res.status, 401);
124
+ });
128
125
 
129
- it('should return an error because of a wrong type', async function () {
130
- const options = client.createDefaultRequestOptions({ method: 'get' });
131
- const res = await fetch(`http://${node.address}/client/request-song/?title=artist - title`, options);
132
- assert.equal(res.status, 422, 'check the status');
133
- assert.isOk((await res.json()).message.match('Link type'), 'check the message');
134
- });
126
+ it('should return an error because of a wrong title', async function () {
127
+ const options = client.createDefaultRequestOptions({ method: 'get' });
128
+ const res = await fetch(`http://${node.address}/client/request-song/?type=audio`, options);
129
+ assert.equal(res.status, 422, 'check the status');
130
+ assert.isOk((await res.json()).message.match('Wrong song title'), 'check the message');
131
+ });
135
132
 
136
- it('should return 404 for audio', async function () {
137
- const options = client.createDefaultRequestOptions({ method: 'get' });
138
- const res = await fetch(`http://${node.address}/client/request-song/?title=unexistent - song&type=audio`, options);
139
- assert.equal(res.status, 404);
140
- });
133
+ it('should return an error because of a wrong type', async function () {
134
+ const options = client.createDefaultRequestOptions({ method: 'get' });
135
+ const res = await fetch(`http://${node.address}/client/request-song/?title=artist - title`, options);
136
+ assert.equal(res.status, 422, 'check the status');
137
+ assert.isOk((await res.json()).message.match('Link type'), 'check the message');
138
+ });
141
139
 
142
- it('should return 404 for cover', async function () {
143
- const options = client.createDefaultRequestOptions({ method: 'get' });
144
- const res = await fetch(`http://${node.address}/client/request-song/?title=unexistent - song&type=cover`, options);
145
- assert.equal(res.status, 404);
146
- });
140
+ it('should return 404 for audio', async function () {
141
+ const options = client.createDefaultRequestOptions({ method: 'get' });
142
+ const res = await fetch(`http://${node.address}/client/request-song/?title=unexistent - song&type=audio`, options);
143
+ assert.equal(res.status, 404);
144
+ });
147
145
 
148
- it('should return the audio file', async function () {
149
- const title = 'artist - title';
150
- const doc = await node.db.getMusicByPk(title);
151
- const buffer = await fse.readFile(node.getFilePath(doc.fileHash));
152
- const filePath = path.join(tools.tmpPath, 'audio-saved.mp3');
153
- const options = client.createDefaultRequestOptions({ method: 'get' });
154
- const res = await fetch(`http://${node.address}/client/request-song/?title=${title}&type=audio`, options);
155
- await tools.saveResponseToFile(res, filePath);
156
- assert.isOk(Buffer.compare(await fse.readFile(filePath), buffer) == 0);
157
- });
146
+ it('should return 404 for cover', async function () {
147
+ const options = client.createDefaultRequestOptions({ method: 'get' });
148
+ const res = await fetch(`http://${node.address}/client/request-song/?title=unexistent - song&type=cover`, options);
149
+ assert.equal(res.status, 404);
150
+ });
158
151
 
159
- it('should return the cover file', async function () {
160
- const title = 'artist - title';
161
- const doc = await node.db.getMusicByPk(title);
162
- const buffer = (await utils.getSongTags(node.getFilePath(doc.fileHash))).APIC
163
- const filePath = path.join(tools.tmpPath, 'cover-saved.jpg');
164
- const options = client.createDefaultRequestOptions({ method: 'get' });
165
- const res = await fetch(`http://${node.address}/client/request-song/?title=${title}&type=cover`, options);
166
- await tools.saveResponseToFile(res, filePath);
167
- assert.isOk(Buffer.compare(await fse.readFile(filePath), buffer) == 0);
168
- });
169
- });
152
+ it('should return the audio file', async function () {
153
+ const title = 'artist - title';
154
+ const doc = await node.db.getMusicByPk(title);
155
+ const buffer = await fse.readFile(node.getFilePath(doc.fileHash));
156
+ const filePath = path.join(tools.tmpPath, 'audio-saved.mp3');
157
+ const options = client.createDefaultRequestOptions({ method: 'get' });
158
+ const res = await fetch(`http://${node.address}/client/request-song/?title=${title}&type=audio`, options);
159
+ await tools.saveResponseToFile(res, filePath);
160
+ assert.isOk(Buffer.compare(await fse.readFile(filePath), buffer) == 0);
161
+ });
170
162
 
171
- describe('/client/add-song', function () {
172
- it('should return an auth error', async function () {
173
- const res = await fetch(`http://${node.address}/client/add-song`, { method: 'post' });
174
- assert.equal(await res.status, 401);
163
+ it('should return the cover file', async function () {
164
+ const title = 'artist - title';
165
+ const doc = await node.db.getMusicByPk(title);
166
+ const buffer = (await utils.getSongTags(node.getFilePath(doc.fileHash))).APIC;
167
+ const filePath = path.join(tools.tmpPath, 'cover-saved.jpg');
168
+ const options = client.createDefaultRequestOptions({ method: 'get' });
169
+ const res = await fetch(`http://${node.address}/client/request-song/?title=${title}&type=cover`, options);
170
+ await tools.saveResponseToFile(res, filePath);
171
+ assert.isOk(Buffer.compare(await fse.readFile(filePath), buffer) == 0);
172
+ });
175
173
  });
176
174
 
177
- it('should return an error', async function () {
178
- const options = client.createDefaultRequestOptions();
179
- const res = await fetch(`http://${node.address}/client/add-song`, options);
180
- assert.equal(res.status, 422);
181
- });
175
+ describe('/client/add-song', function () {
176
+ it('should return an auth error', async function () {
177
+ const res = await fetch(`http://${node.address}/client/add-song`, { method: 'post' });
178
+ assert.equal(await res.status, 401);
179
+ });
182
180
 
183
- it('should save the song', async function () {
184
- const title = 'new - song';
185
- const file = await utils.setSongTags(path.join(tools.tmpPath, 'audio.mp3'), {
186
- fullTitle: title,
187
- APIC: path.join(tools.tmpPath, 'cover.jpg'),
188
- TIT3: 'x'
189
- });
190
- const fileOptions = { contentType: 'audio/mpeg', filename: `audio.mp3` };
191
- const body = tools.createRequestFormData({
192
- file: { value: fse.createReadStream(file), options: fileOptions }
193
- });
194
- const options = client.createDefaultRequestOptions({ body });
195
- const res = await fetch(`http://${node.address}/client/add-song`, options);
196
- const json = await res.json();
197
- const doc = await node.db.getMusicByPk(title);
198
- assert.isNotNull(doc, 'check the database');
199
- assert.equal(utils.beautifySongTitle(title), json.title, 'check the title');
200
- assert.equal(json.tags.TIT3, 'x', 'check the tags');
201
- assert.isTrue(await node.hasFile(doc.fileHash), 'check the file');
202
- assert.isTrue(utils.isValidSongAudioLink(json.audioLink), 'check the audio link');
203
- assert.isTrue(utils.isValidSongCoverLink(json.coverLink), 'check the cover link');
204
- });
205
- });
181
+ it('should return an error', async function () {
182
+ const options = client.createDefaultRequestOptions();
183
+ const res = await fetch(`http://${node.address}/client/add-song`, options);
184
+ assert.equal(res.status, 422);
185
+ });
206
186
 
207
- describe('/client/get-song-info', function () {
208
- it('should return an auth error', async function () {
209
- const res = await fetch(`http://${node.address}/client/get-song-info`, { method: 'post' });
210
- assert.equal(await res.status, 401);
187
+ it('should save the song', async function () {
188
+ const title = 'new - song';
189
+ const file = await utils.setSongTags(path.join(tools.tmpPath, 'audio.mp3'), {
190
+ fullTitle: title,
191
+ APIC: path.join(tools.tmpPath, 'cover.jpg'),
192
+ TIT3: 'x'
193
+ });
194
+ const fileOptions = { contentType: 'audio/mpeg', filename: `audio.mp3` };
195
+ const body = tools.createRequestFormData({
196
+ file: { value: fse.createReadStream(file), options: fileOptions }
197
+ });
198
+ const options = client.createDefaultRequestOptions({ body });
199
+ const res = await fetch(`http://${node.address}/client/add-song`, options);
200
+ const json = await res.json();
201
+ const doc = await node.db.getMusicByPk(title);
202
+ assert.isNotNull(doc, 'check the database');
203
+ assert.equal(utils.beautifySongTitle(title), json.title, 'check the title');
204
+ assert.equal(json.tags.TIT3, 'x', 'check the tags');
205
+ assert.isTrue(await node.hasFile(doc.fileHash), 'check the file');
206
+ assert.isTrue(utils.isValidSongAudioLink(json.audioLink), 'check the audio link');
207
+ assert.isTrue(utils.isValidSongCoverLink(json.coverLink), 'check the cover link');
208
+ });
211
209
  });
212
210
 
213
- it('should return an error', async function () {
214
- const options = client.createDefaultRequestOptions({ method: 'post' });
215
- const res = await fetch(`http://${node.address}/client/get-song-info`, options);
216
- assert.equal(res.status, 422);
217
- });
211
+ describe('/client/get-song-info', function () {
212
+ it('should return an auth error', async function () {
213
+ const res = await fetch(`http://${node.address}/client/get-song-info`, { method: 'post' });
214
+ assert.equal(await res.status, 401);
215
+ });
218
216
 
219
- it('should return the info', async function () {
220
- const title = 'new - song';
221
- const options = client.createDefaultRequestOptions(tools.createJsonRequestOptions({ body: { title } }));
222
- const res = await fetch(`http://${node.address}/client/get-song-info`, options);
223
- const json = await res.json();
224
- const info = json.info[0];
225
- assert.lengthOf(json.info, 1, 'check the length');
226
- assert.equal(utils.beautifySongTitle(title), info.title, 'check the title');
227
- assert.equal(info.tags.TIT3, 'x', 'check the tags');
228
- assert.isTrue(utils.isValidSongAudioLink(info.audioLink), 'check the audio link');
229
- assert.isTrue(utils.isValidSongCoverLink(info.coverLink), 'check the cover link');
230
- });
231
- });
217
+ it('should return an error', async function () {
218
+ const options = client.createDefaultRequestOptions({ method: 'post' });
219
+ const res = await fetch(`http://${node.address}/client/get-song-info`, options);
220
+ assert.equal(res.status, 422);
221
+ });
232
222
 
233
- describe('/client/find-songs', function () {
234
- it('should return an auth error', async function () {
235
- const res = await fetch(`http://${node.address}/client/find-songs`, { method: 'post' });
236
- assert.equal(await res.status, 401);
223
+ it('should return the info', async function () {
224
+ const title = 'new - song';
225
+ const options = client.createDefaultRequestOptions(tools.createJsonRequestOptions({ body: { title } }));
226
+ const res = await fetch(`http://${node.address}/client/get-song-info`, options);
227
+ const json = await res.json();
228
+ const info = json.info[0];
229
+ assert.lengthOf(json.info, 1, 'check the length');
230
+ assert.equal(utils.beautifySongTitle(title), info.title, 'check the title');
231
+ assert.equal(info.tags.TIT3, 'x', 'check the tags');
232
+ assert.isTrue(utils.isValidSongAudioLink(info.audioLink), 'check the audio link');
233
+ assert.isTrue(utils.isValidSongCoverLink(info.coverLink), 'check the cover link');
234
+ });
237
235
  });
238
236
 
239
- it('should return the songs', async function () {
240
- const str = 'new - song';
241
- const options = client.createDefaultRequestOptions(tools.createJsonRequestOptions({ body: { str } }));
242
- const res = await fetch(`http://${node.address}/client/find-songs`, options);
243
- const json = await res.json();
244
- const songs = json.songs[0];
245
- assert.lengthOf(json.songs, 1, 'check the length');
246
- assert.isOk(songs.title.toLowerCase().match(str.toLowerCase()), 'check the title');
247
- assert.equal(songs.tags.TIT3, 'x', 'check the tags');
248
- assert.isTrue(utils.isValidSongAudioLink(songs.audioLink), 'check the audio link');
249
- assert.isTrue(utils.isValidSongCoverLink(songs.coverLink), 'check the cover link');
250
- });
251
- });
237
+ describe('/client/find-songs', function () {
238
+ it('should return an auth error', async function () {
239
+ const res = await fetch(`http://${node.address}/client/find-songs`, { method: 'post' });
240
+ assert.equal(await res.status, 401);
241
+ });
252
242
 
253
- describe('/client/find-artist-songs', function () {
254
- it('should return an auth error', async function () {
255
- const res = await fetch(`http://${node.address}/client/find-artist-songs`, { method: 'post' });
256
- assert.equal(await res.status, 401);
243
+ it('should return the songs', async function () {
244
+ const str = 'new - song';
245
+ const options = client.createDefaultRequestOptions(tools.createJsonRequestOptions({ body: { str } }));
246
+ const res = await fetch(`http://${node.address}/client/find-songs`, options);
247
+ const json = await res.json();
248
+ const songs = json.songs[0];
249
+ assert.lengthOf(json.songs, 1, 'check the length');
250
+ assert.isOk(songs.title.toLowerCase().match(str.toLowerCase()), 'check the title');
251
+ assert.equal(songs.tags.TIT3, 'x', 'check the tags');
252
+ assert.isTrue(utils.isValidSongAudioLink(songs.audioLink), 'check the audio link');
253
+ assert.isTrue(utils.isValidSongCoverLink(songs.coverLink), 'check the cover link');
254
+ });
257
255
  });
258
256
 
259
- it('should return the songs', async function () {
260
- const artist = 'new';
261
- const options = client.createDefaultRequestOptions(tools.createJsonRequestOptions({ body: { artist } }));
262
- const res = await fetch(`http://${node.address}/client/find-artist-songs`, options);
263
- const json = await res.json();
264
- const songs = json.songs[0];
265
- assert.lengthOf(json.songs, 1, 'check the length');
266
- assert.isOk(songs.title.toLowerCase().match(artist.toLowerCase()), 'check the title');
267
- assert.equal(songs.tags.TIT3, 'x', 'check the tags');
268
- assert.isTrue(utils.isValidSongAudioLink(songs.audioLink), 'check the audio link');
269
- assert.isTrue(utils.isValidSongCoverLink(songs.coverLink), 'check the cover link');
270
- });
271
- });
257
+ describe('/client/find-artist-songs', function () {
258
+ it('should return an auth error', async function () {
259
+ const res = await fetch(`http://${node.address}/client/find-artist-songs`, { method: 'post' });
260
+ assert.equal(await res.status, 401);
261
+ });
272
262
 
273
- describe('/client/get-song-link', function () {
274
- it('should return an auth error', async function () {
275
- const res = await fetch(`http://${node.address}/client/get-song-link`, { method: 'post' });
276
- assert.equal(await res.status, 401);
263
+ it('should return the songs', async function () {
264
+ const artist = 'new';
265
+ const options = client.createDefaultRequestOptions(tools.createJsonRequestOptions({ body: { artist } }));
266
+ const res = await fetch(`http://${node.address}/client/find-artist-songs`, options);
267
+ const json = await res.json();
268
+ const songs = json.songs[0];
269
+ assert.lengthOf(json.songs, 1, 'check the length');
270
+ assert.isOk(songs.title.toLowerCase().match(artist.toLowerCase()), 'check the title');
271
+ assert.equal(songs.tags.TIT3, 'x', 'check the tags');
272
+ assert.isTrue(utils.isValidSongAudioLink(songs.audioLink), 'check the audio link');
273
+ assert.isTrue(utils.isValidSongCoverLink(songs.coverLink), 'check the cover link');
274
+ });
277
275
  });
278
276
 
279
- it('should return an error because of a wrong title', async function () {
280
- const body = { type: 'audio' }
281
- const options = client.createDefaultRequestOptions(tools.createJsonRequestOptions({ body }));
282
- const res = await fetch(`http://${node.address}/client/get-song-link`, options);
283
- assert.equal(res.status, 422, 'check the status');
284
- assert.isOk((await res.json()).message.match('Wrong song title'), 'check the message');
285
- });
277
+ describe('/client/get-song-link', function () {
278
+ it('should return an auth error', async function () {
279
+ const res = await fetch(`http://${node.address}/client/get-song-link`, { method: 'post' });
280
+ assert.equal(await res.status, 401);
281
+ });
286
282
 
287
- it('should return an error because of a wrong type', async function () {
288
- const body = { title: 'new - song' };
289
- const options = client.createDefaultRequestOptions(tools.createJsonRequestOptions({ body }));
290
- const res = await fetch(`http://${node.address}/client/get-song-link`, options);
291
- assert.equal(res.status, 422, 'check the status');
292
- assert.isOk((await res.json()).message.match('Link type'), 'check the message');
293
- });
283
+ it('should return an error because of a wrong title', async function () {
284
+ const body = { type: 'audio' };
285
+ const options = client.createDefaultRequestOptions(tools.createJsonRequestOptions({ body }));
286
+ const res = await fetch(`http://${node.address}/client/get-song-link`, options);
287
+ assert.equal(res.status, 422, 'check the status');
288
+ assert.isOk((await res.json()).message.match('Wrong song title'), 'check the message');
289
+ });
294
290
 
295
- it('should return an empty audio link', async function () {
296
- const body = { title: 'unexistent - unexistent', type: 'audio' };
297
- const options = client.createDefaultRequestOptions(tools.createJsonRequestOptions({ body }));
298
- const res = await fetch(`http://${node.address}/client/get-song-link`, options);
299
- const json = await res.json();
300
- assert.isEmpty(json.link);
301
- });
291
+ it('should return an error because of a wrong type', async function () {
292
+ const body = { title: 'new - song' };
293
+ const options = client.createDefaultRequestOptions(tools.createJsonRequestOptions({ body }));
294
+ const res = await fetch(`http://${node.address}/client/get-song-link`, options);
295
+ assert.equal(res.status, 422, 'check the status');
296
+ assert.isOk((await res.json()).message.match('Link type'), 'check the message');
297
+ });
298
+
299
+ it('should return an empty audio link', async function () {
300
+ const body = { title: 'unexistent - unexistent', type: 'audio' };
301
+ const options = client.createDefaultRequestOptions(tools.createJsonRequestOptions({ body }));
302
+ const res = await fetch(`http://${node.address}/client/get-song-link`, options);
303
+ const json = await res.json();
304
+ assert.isEmpty(json.link);
305
+ });
302
306
 
303
- it('should return an empty cover link', async function () {
304
- const body = { title: 'unexistent - unexistent', type: 'cover' };
305
- const options = client.createDefaultRequestOptions(tools.createJsonRequestOptions({ body }));
306
- const res = await fetch(`http://${node.address}/client/get-song-link`, options);
307
- const json = await res.json();
308
- assert.isEmpty(json.link);
309
- });
307
+ it('should return an empty cover link', async function () {
308
+ const body = { title: 'unexistent - unexistent', type: 'cover' };
309
+ const options = client.createDefaultRequestOptions(tools.createJsonRequestOptions({ body }));
310
+ const res = await fetch(`http://${node.address}/client/get-song-link`, options);
311
+ const json = await res.json();
312
+ assert.isEmpty(json.link);
313
+ });
310
314
 
311
- it('should return the audio link', async function () {
312
- const title = 'new - song';
313
- const body = { title, type: 'audio' };
314
- const options = client.createDefaultRequestOptions(tools.createJsonRequestOptions({ body }));
315
- const res = await fetch(`http://${node.address}/client/get-song-link`, options);
316
- const json = await res.json();
317
- assert.isTrue(utils.isValidSongAudioLink(json.link));
318
- });
315
+ it('should return the audio link', async function () {
316
+ const title = 'new - song';
317
+ const body = { title, type: 'audio' };
318
+ const options = client.createDefaultRequestOptions(tools.createJsonRequestOptions({ body }));
319
+ const res = await fetch(`http://${node.address}/client/get-song-link`, options);
320
+ const json = await res.json();
321
+ assert.isTrue(utils.isValidSongAudioLink(json.link));
322
+ });
319
323
 
320
- it('should return the cover link', async function () {
321
- const title = 'new - song';
322
- const body = { title, type: 'cover' };
323
- const options = client.createDefaultRequestOptions(tools.createJsonRequestOptions({ body }));
324
- const res = await fetch(`http://${node.address}/client/get-song-link`, options);
325
- const json = await res.json();
326
- assert.isTrue(utils.isValidSongCoverLink(json.link));
324
+ it('should return the cover link', async function () {
325
+ const title = 'new - song';
326
+ const body = { title, type: 'cover' };
327
+ const options = client.createDefaultRequestOptions(tools.createJsonRequestOptions({ body }));
328
+ const res = await fetch(`http://${node.address}/client/get-song-link`, options);
329
+ const json = await res.json();
330
+ assert.isTrue(utils.isValidSongCoverLink(json.link));
331
+ });
327
332
  });
328
- });
329
333
 
330
- describe('/client/remove-song/', function () {
331
- it('should return an auth error', async function () {
332
- const res = await fetch(`http://${node.address}/client/remove-song/`, { method: 'post' });
333
- assert.equal(await res.status, 401);
334
- });
334
+ describe('/client/remove-song/', function () {
335
+ it('should return an auth error', async function () {
336
+ const res = await fetch(`http://${node.address}/client/remove-song/`, { method: 'post' });
337
+ assert.equal(await res.status, 401);
338
+ });
335
339
 
336
- it('should return a data error', async function () {
337
- const options = client.createDefaultRequestOptions();
338
- const res = await fetch(`http://${node.address}/client/remove-song/`, options);
339
- assert.equal(res.status, 422);
340
- });
340
+ it('should return a data error', async function () {
341
+ const options = client.createDefaultRequestOptions();
342
+ const res = await fetch(`http://${node.address}/client/remove-song/`, options);
343
+ assert.equal(res.status, 422);
344
+ });
341
345
 
342
- it('should not remove the file with priority 1', async function () {
343
- const title = 'new - song';
344
- const doc = await node.db.getMusicByPk(title);
345
- doc.priority = 1;
346
- const options = client.createDefaultRequestOptions(tools.createJsonRequestOptions({ body: { title } }));
347
- const res = await fetch(`http://${node.address}/client/remove-song/`, options);
348
- const json = await res.json();
349
- doc.priority = 0;
350
- assert.equal(json.removed, 0, 'check the response');
351
- assert.isTrue(await node.hasFile(doc.fileHash), 'check the file');
352
- });
346
+ it('should not remove the file with priority 1', async function () {
347
+ const title = 'new - song';
348
+ const doc = await node.db.getMusicByPk(title);
349
+ doc.priority = 1;
350
+ const options = client.createDefaultRequestOptions(tools.createJsonRequestOptions({ body: { title } }));
351
+ const res = await fetch(`http://${node.address}/client/remove-song/`, options);
352
+ const json = await res.json();
353
+ doc.priority = 0;
354
+ assert.equal(json.removed, 0, 'check the response');
355
+ assert.isTrue(await node.hasFile(doc.fileHash), 'check the file');
356
+ });
353
357
 
354
- it('should remove the file', async function () {
355
- const title = 'new - song';
356
- const doc = await node.db.getMusicByPk(title);
357
- const options = client.createDefaultRequestOptions(tools.createJsonRequestOptions({ body: { title } }));
358
- const res = await fetch(`http://${node.address}/client/remove-song/`, options);
359
- const json = await res.json();
360
- assert.equal(json.removed, 1, 'check the response');
361
- assert.isNull(await node.db.getMusicByPk(title), 'check the database');
362
- assert.isFalse(await node.hasFile(doc.fileHash), 'check the file');
358
+ it('should remove the file', async function () {
359
+ const title = 'new - song';
360
+ const doc = await node.db.getMusicByPk(title);
361
+ const options = client.createDefaultRequestOptions(tools.createJsonRequestOptions({ body: { title } }));
362
+ const res = await fetch(`http://${node.address}/client/remove-song/`, options);
363
+ const json = await res.json();
364
+ assert.equal(json.removed, 1, 'check the response');
365
+ assert.isNull(await node.db.getMusicByPk(title), 'check the database');
366
+ assert.isFalse(await node.hasFile(doc.fileHash), 'check the file');
367
+ });
363
368
  });
364
- });
365
369
 
366
- describe('/api/master/remove-song/', function () {
367
- it('should return an auth error', async function () {
368
- const res = await fetch(`http://${node.address}/api/master/remove-song/`, { method: 'post' });
369
- assert.equal(await res.status, 401);
370
- });
370
+ describe('/api/master/remove-song/', function () {
371
+ it('should return an auth error', async function () {
372
+ const res = await fetch(`http://${node.address}/api/master/remove-song/`, { method: 'post' });
373
+ assert.equal(await res.status, 401);
374
+ });
371
375
 
372
- it('should return a data error', async function () {
373
- const options = node.createDefaultRequestOptions(tools.createJsonRequestOptions());
374
- const res = await fetch(`http://${node.address}/api/master/remove-song/`, options);
375
- assert.equal(res.status, 422);
376
- });
376
+ it('should return a data error', async function () {
377
+ const options = node.createDefaultRequestOptions(tools.createJsonRequestOptions());
378
+ const res = await fetch(`http://${node.address}/api/master/remove-song/`, options);
379
+ assert.equal(res.status, 422);
380
+ });
377
381
 
378
- it('should return the right schema', async function () {
379
- const body = {
380
- level: 2,
381
- title: 'artist - title'
382
- };
383
- const options = node.createDefaultRequestOptions(tools.createJsonRequestOptions({ body }));
384
- const res = await fetch(`http://${node.address}/api/master/remove-song/`, options);
385
- const json = tools.createServerResponse(node.address, await res.json());
386
- assert.doesNotThrow(() => {
387
- utils.validateSchema(schema.getSongRemovalMasterResponse(), json);
382
+ it('should return the right schema', async function () {
383
+ const body = {
384
+ level: 2,
385
+ title: 'artist - title'
386
+ };
387
+ const options = node.createDefaultRequestOptions(tools.createJsonRequestOptions({ body }));
388
+ const res = await fetch(`http://${node.address}/api/master/remove-song/`, options);
389
+ const json = tools.createServerResponse(node.address, await res.json());
390
+ assert.doesNotThrow(() => {
391
+ utils.validateSchema(schema.getSongRemovalMasterResponse(), json);
392
+ });
388
393
  });
389
394
  });
390
- });
391
-
392
- describe('/api/butler/remove-song/', function () {
393
- it('should return an auth error', async function () {
394
- const res = await fetch(`http://${node.address}/api/butler/remove-song/`, { method: 'post' });
395
- assert.equal(await res.status, 401);
396
- });
397
395
 
398
- it('should return a data error', async function () {
399
- const options = node.createDefaultRequestOptions(tools.createJsonRequestOptions());
400
- const res = await fetch(`http://${node.address}/api/butler/remove-song/`, options);
401
- assert.equal(res.status, 422);
402
- });
396
+ describe('/api/butler/remove-song/', function () {
397
+ it('should return an auth error', async function () {
398
+ const res = await fetch(`http://${node.address}/api/butler/remove-song/`, { method: 'post' });
399
+ assert.equal(await res.status, 401);
400
+ });
403
401
 
404
- it('should return the right schema', async function () {
405
- const body = {
406
- level: 1,
407
- title: 'artist - title'
408
- };
409
- const options = node.createDefaultRequestOptions(tools.createJsonRequestOptions({ body }));
410
- const res = await fetch(`http://${node.address}/api/butler/remove-song/`, options);
411
- const json = tools.createServerResponse(node.address, await res.json());
412
- assert.doesNotThrow(() => {
413
- utils.validateSchema(schema.getSongRemovalButlerResponse(), json);
402
+ it('should return a data error', async function () {
403
+ const options = node.createDefaultRequestOptions(tools.createJsonRequestOptions());
404
+ const res = await fetch(`http://${node.address}/api/butler/remove-song/`, options);
405
+ assert.equal(res.status, 422);
414
406
  });
415
- });
416
- });
417
407
 
418
- describe('/api/slave/remove-song/', function () {
419
- it('should return an auth error', async function () {
420
- const res = await fetch(`http://${node.address}/api/slave/remove-song/`, { method: 'post' });
421
- assert.equal(await res.status, 401);
408
+ it('should return the right schema', async function () {
409
+ const body = {
410
+ level: 1,
411
+ title: 'artist - title'
412
+ };
413
+ const options = node.createDefaultRequestOptions(tools.createJsonRequestOptions({ body }));
414
+ const res = await fetch(`http://${node.address}/api/butler/remove-song/`, options);
415
+ const json = tools.createServerResponse(node.address, await res.json());
416
+ assert.doesNotThrow(() => {
417
+ utils.validateSchema(schema.getSongRemovalButlerResponse(), json);
418
+ });
419
+ });
422
420
  });
423
421
 
424
- it('should return a data error', async function () {
425
- const options = node.createDefaultRequestOptions();
426
- const res = await fetch(`http://${node.address}/api/slave/remove-song/`, options);
427
- assert.equal(res.status, 422);
428
- });
422
+ describe('/api/slave/remove-song/', function () {
423
+ it('should return an auth error', async function () {
424
+ const res = await fetch(`http://${node.address}/api/slave/remove-song/`, { method: 'post' });
425
+ assert.equal(await res.status, 401);
426
+ });
429
427
 
430
- it('should return the right schema', async function () {
431
- const body = {
432
- level: 0,
433
- title: 'artist - title'
434
- };
435
- const options = node.createDefaultRequestOptions(tools.createJsonRequestOptions({ body }));
436
- const res = await fetch(`http://${node.address}/api/slave/remove-song/`, options);
437
- const json = tools.createServerResponse(node.address, await res.json());
438
- assert.doesNotThrow(() => {
439
- utils.validateSchema(schema.getSongRemovalSlaveResponse(), json);
428
+ it('should return a data error', async function () {
429
+ const options = node.createDefaultRequestOptions();
430
+ const res = await fetch(`http://${node.address}/api/slave/remove-song/`, options);
431
+ assert.equal(res.status, 422);
440
432
  });
441
- });
442
- });
443
433
 
444
- describe('/api/node/add-song/', function () {
445
- it('should return an auth error', async function () {
446
- const res = await fetch(`http://${node.address}/api/node/add-song/`, { method: 'post' });
447
- assert.equal(await res.status, 401);
434
+ it('should return the right schema', async function () {
435
+ const body = {
436
+ level: 0,
437
+ title: 'artist - title'
438
+ };
439
+ const options = node.createDefaultRequestOptions(tools.createJsonRequestOptions({ body }));
440
+ const res = await fetch(`http://${node.address}/api/slave/remove-song/`, options);
441
+ const json = tools.createServerResponse(node.address, await res.json());
442
+ assert.doesNotThrow(() => {
443
+ utils.validateSchema(schema.getSongRemovalSlaveResponse(), json);
444
+ });
445
+ });
448
446
  });
449
447
 
450
- it('should return an error', async function () {
451
- const options = node.createDefaultRequestOptions();
452
- const res = await fetch(`http://${node.address}/api/node/add-song/`, options);
453
- assert.equal(res.status, 422);
454
- });
448
+ describe('/api/node/add-song/', function () {
449
+ it('should return an auth error', async function () {
450
+ const res = await fetch(`http://${node.address}/api/node/add-song/`, { method: 'post' });
451
+ assert.equal(await res.status, 401);
452
+ });
455
453
 
456
- it('should return the right schema', async function () {
457
- const fullTitle = 'new - song';
458
- const file = await utils.setSongTags(path.join(tools.tmpPath, 'audio.mp3'), { fullTitle });
459
- const fileOptions = { contentType: 'audio/mpeg', filename: `audio.mp3` };
460
- const body = tools.createRequestFormData({
461
- file: { value: fse.createReadStream(file), options: fileOptions }
454
+ it('should return an error', async function () {
455
+ const options = node.createDefaultRequestOptions();
456
+ const res = await fetch(`http://${node.address}/api/node/add-song/`, options);
457
+ assert.equal(res.status, 422);
462
458
  });
463
- const options = node.createDefaultRequestOptions({ body });
464
- const res = await fetch(`http://${node.address}/api/node/add-song/`, options);
465
- const json = tools.createServerResponse(node.address, await res.json());
466
- assert.doesNotThrow(() => {
467
- utils.validateSchema(schema.getSongAdditionResponse(), json);
459
+
460
+ it('should return the right schema', async function () {
461
+ const fullTitle = 'new - song';
462
+ const file = await utils.setSongTags(path.join(tools.tmpPath, 'audio.mp3'), { fullTitle });
463
+ const fileOptions = { contentType: 'audio/mpeg', filename: `audio.mp3` };
464
+ const body = tools.createRequestFormData({
465
+ file: { value: fse.createReadStream(file), options: fileOptions }
466
+ });
467
+ const options = node.createDefaultRequestOptions({ body });
468
+ const res = await fetch(`http://${node.address}/api/node/add-song/`, options);
469
+ const json = tools.createServerResponse(node.address, await res.json());
470
+ assert.doesNotThrow(() => {
471
+ utils.validateSchema(schema.getSongAdditionResponse(), json);
472
+ });
468
473
  });
469
474
  });
470
475
  });
471
- });
476
+ }