museria 0.2.49 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +55 -59
  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 +312 -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/client.js CHANGED
@@ -1,362 +1,368 @@
1
- const assert = require('chai').assert;
2
- const fse = require('fs-extra');
3
- const path = require('path');
4
- const Node = require('../src/node')();
5
- const Client = require('../src/client')();
6
- const utils = require('../src/utils');
7
- const tools = require('./tools');
8
-
9
- describe('Client', () => {
10
- let client;
11
- let node;
12
-
13
- before(async function() {
14
- node = new Node(await tools.createNodeOptions());
15
- await node.init();
16
- });
1
+ import { assert } from "chai";
2
+ import fse from "fs-extra";
3
+ import path from "path";
4
+ import node from "../src/node.js";
5
+ import client from "../src/client.js";
6
+ import utils from "../src/utils.js";
7
+ import tools from "./tools.js";
17
8
 
18
- after(async function() {
19
- await node.deinit();
20
- });
9
+ const Node = node();
10
+ const Client = client();
21
11
 
22
- describe('instance creation', function () {
23
- it('should create an instance', async function () {
24
- const options = await tools.createClientOptions({ address: node.address });
25
- assert.doesNotThrow(() => client = new Client(options));
26
- });
27
- });
12
+ export default function () {
13
+ describe('Client', () => {
14
+ let client;
15
+ let node;
28
16
 
29
- describe('.init()', function () {
30
- it('should not throw an exception', async function () {
31
- await client.init();
17
+ before(async function () {
18
+ node = new Node(await tools.createNodeOptions());
19
+ await node.init();
32
20
  });
33
- });
34
21
 
35
- describe('.addSong()', function () {
36
- it('should not add the song with a wrong title', async function () {
37
- const file = await utils.setSongTags(path.join(tools.tmpPath, 'audio.mp3'), { fullTitle: 'wrong' });
38
- try {
39
- await client.addSong(file);
40
- throw new Error('Fail');
41
- }
42
- catch(err) {
43
- assert.isOk(err.message.match('Wrong song title'));
44
- }
22
+ after(async function () {
23
+ await node.deinit();
45
24
  });
46
25
 
47
- it('should add the song', async () => {
48
- const title = 'artist - title';
49
- const file = await utils.setSongTags(path.join(tools.tmpPath, 'audio.mp3'), {
50
- fullTitle: title,
51
- APIC: path.join(tools.tmpPath, 'cover.jpg'),
52
- TIT3: 'x'
53
- });
54
- const result = await client.addSong(file);
55
- const doc = await node.db.getMusicByPk(result.title);
56
- assert.equal(utils.beautifySongTitle(title), result.title, 'check the title');
57
- assert.equal(result.tags.TIT3, 'x', 'check the tags');
58
- assert.isNotNull(doc, 'check the database');
59
- assert.isTrue(await node.hasFile(doc.fileHash), 'check the file');
60
- assert.isTrue(utils.isValidSongAudioLink(result.audioLink), 'check the audio link');
61
- assert.isTrue(utils.isValidSongCoverLink(result.coverLink), 'check the cover link');
26
+ describe('instance creation', function () {
27
+ it('should create an instance', async function () {
28
+ const options = await tools.createClientOptions({ address: node.address });
29
+ assert.doesNotThrow(() => client = new Client(options));
30
+ });
62
31
  });
63
- });
64
32
 
65
- describe('.getSongInfo()', function () {
66
- it('should throw an error because of a wrong title', async function () {
67
- try {
68
- await client.getSongInfo('wrong');
69
- throw new Error('Fail');
70
- }
71
- catch(err) {
72
- assert.isOk(err.message.match('Wrong song title'));
73
- }
33
+ describe('.init()', function () {
34
+ it('should not throw an exception', async function () {
35
+ await client.init();
36
+ });
74
37
  });
75
38
 
76
- it('should return an empty array', async function () {
77
- const info = await client.getSongInfo('unexistent - song');
78
- assert.lengthOf(info, 0);
79
- });
39
+ describe('.addSong()', function () {
40
+ it('should not add the song with a wrong title', async function () {
41
+ const file = await utils.setSongTags(path.join(tools.tmpPath, 'audio.mp3'), { fullTitle: 'wrong' });
42
+
43
+ try {
44
+ await client.addSong(file);
45
+ throw new Error('Fail');
46
+ }
47
+ catch (err) {
48
+ assert.isOk(err.message.match('Wrong song title'));
49
+ }
50
+ });
80
51
 
81
- it('should return the info', async function () {
82
- const title = 'artist - title';
83
- const info = await client.getSongInfo(title);
84
- const result = info[0];
85
- assert.lengthOf(info, 1, 'check the length');
86
- assert.equal(utils.beautifySongTitle(title), result.title, 'check the title');
87
- assert.equal(result.tags.TIT3, 'x', 'check the tags');
88
- assert.isTrue(utils.isValidSongAudioLink(result.audioLink), 'check the audio link');
89
- assert.isTrue(utils.isValidSongCoverLink(result.coverLink), 'check the cover link');
52
+ it('should add the song', async () => {
53
+ const title = 'artist - title';
54
+ const file = await utils.setSongTags(path.join(tools.tmpPath, 'audio.mp3'), {
55
+ fullTitle: title,
56
+ APIC: path.join(tools.tmpPath, 'cover.jpg'),
57
+ TIT3: 'x'
58
+ });
59
+ const result = await client.addSong(file);
60
+ const doc = await node.db.getMusicByPk(result.title);
61
+ assert.equal(utils.beautifySongTitle(title), result.title, 'check the title');
62
+ assert.equal(result.tags.TIT3, 'x', 'check the tags');
63
+ assert.isNotNull(doc, 'check the database');
64
+ assert.isTrue(await node.hasFile(doc.fileHash), 'check the file');
65
+ assert.isTrue(utils.isValidSongAudioLink(result.audioLink), 'check the audio link');
66
+ assert.isTrue(utils.isValidSongCoverLink(result.coverLink), 'check the cover link');
67
+ });
90
68
  });
91
- });
92
69
 
93
- describe('.findSongs()', function () {
94
- it('should return an empty array', async function () {
95
- const songs = await client.findSongs('unexistent');
96
- assert.lengthOf(songs, 0);
97
- });
70
+ describe('.getSongInfo()', function () {
71
+ it('should throw an error because of a wrong title', async function () {
72
+ try {
73
+ await client.getSongInfo('wrong');
74
+ throw new Error('Fail');
75
+ }
76
+ catch (err) {
77
+ assert.isOk(err.message.match('Wrong song title'));
78
+ }
79
+ });
98
80
 
99
- it('should return the songs', async function () {
100
- const str = 'arTist';
101
- const songs = await client.findSongs(str);
102
- const result = songs[0];
103
- assert.lengthOf(songs, 1, 'check the length');
104
- assert.isOk(result.title.toLowerCase().match(str.toLowerCase()), 'check the title');
105
- assert.equal(result.tags.TIT3, 'x', 'check the tags');
106
- assert.isTrue(utils.isValidSongAudioLink(result.audioLink), 'check the audio link');
107
- assert.isTrue(utils.isValidSongCoverLink(result.coverLink), 'check the cover link');
108
- });
109
- });
81
+ it('should return an empty array', async function () {
82
+ const info = await client.getSongInfo('unexistent - song');
83
+ assert.lengthOf(info, 0);
84
+ });
110
85
 
111
- describe('.findArtistSongs()', function () {
112
- it('should return an empty array', async function () {
113
- const songs = await client.findArtistSongs('art');
114
- assert.lengthOf(songs, 0);
86
+ it('should return the info', async function () {
87
+ const title = 'artist - title';
88
+ const info = await client.getSongInfo(title);
89
+ const result = info[0];
90
+ assert.lengthOf(info, 1, 'check the length');
91
+ assert.equal(utils.beautifySongTitle(title), result.title, 'check the title');
92
+ assert.equal(result.tags.TIT3, 'x', 'check the tags');
93
+ assert.isTrue(utils.isValidSongAudioLink(result.audioLink), 'check the audio link');
94
+ assert.isTrue(utils.isValidSongCoverLink(result.coverLink), 'check the cover link');
95
+ });
115
96
  });
116
97
 
117
- it('should return the songs', async function () {
118
- const str = 'artist';
119
- const songs = await client.findArtistSongs(str);
120
- const result = songs[0];
121
- assert.lengthOf(songs, 1, 'check the length');
122
- assert.isOk(result.title.toLowerCase().match(str), 'check the title');
123
- assert.equal(result.tags.TIT3, 'x', 'check the tags');
124
- assert.isTrue(utils.isValidSongAudioLink(result.audioLink), 'check the audio link');
125
- assert.isTrue(utils.isValidSongCoverLink(result.coverLink), 'check the cover link');
126
- });
127
- });
98
+ describe('.findSongs()', function () {
99
+ it('should return an empty array', async function () {
100
+ const songs = await client.findSongs('unexistent');
101
+ assert.lengthOf(songs, 0);
102
+ });
128
103
 
129
- describe('.getSong()', function () {
130
- it('should throw an error because of a wrong title', async function () {
131
- try {
132
- await client.getSong('wrong');
133
- throw new Error('Fail');
134
- }
135
- catch(err) {
136
- assert.isOk(err.message.match('Wrong song title'));
137
- }
104
+ it('should return the songs', async function () {
105
+ const str = 'arTist';
106
+ const songs = await client.findSongs(str);
107
+ const result = songs[0];
108
+ assert.lengthOf(songs, 1, 'check the length');
109
+ assert.isOk(result.title.toLowerCase().match(str.toLowerCase()), 'check the title');
110
+ assert.equal(result.tags.TIT3, 'x', 'check the tags');
111
+ assert.isTrue(utils.isValidSongAudioLink(result.audioLink), 'check the audio link');
112
+ assert.isTrue(utils.isValidSongCoverLink(result.coverLink), 'check the cover link');
113
+ });
138
114
  });
139
115
 
140
- it('should return null', async function () {
141
- assert.isNull(await client.getSong('unexistent - song'));
142
- });
116
+ describe('.findArtistSongs()', function () {
117
+ it('should return an empty array', async function () {
118
+ const songs = await client.findArtistSongs('art');
119
+ assert.lengthOf(songs, 0);
120
+ });
143
121
 
144
- it('should return the right info', async function () {
145
- const title = 'artist - title';
146
- const info = await client.getSong(title);
147
- assert.equal(utils.beautifySongTitle(title), info.title, 'check the title');
148
- assert.equal(info.tags.TIT3, 'x', 'check the tags');
149
- assert.isTrue(utils.isValidSongAudioLink(info.audioLink), 'check the audio link');
150
- assert.isTrue(utils.isValidSongCoverLink(info.coverLink), 'check the cover link');
122
+ it('should return the songs', async function () {
123
+ const str = 'artist';
124
+ const songs = await client.findArtistSongs(str);
125
+ const result = songs[0];
126
+ assert.lengthOf(songs, 1, 'check the length');
127
+ assert.isOk(result.title.toLowerCase().match(str), 'check the title');
128
+ assert.equal(result.tags.TIT3, 'x', 'check the tags');
129
+ assert.isTrue(utils.isValidSongAudioLink(result.audioLink), 'check the audio link');
130
+ assert.isTrue(utils.isValidSongCoverLink(result.coverLink), 'check the cover link');
131
+ });
151
132
  });
152
- });
153
133
 
154
- describe('.getSongAudioLink()', function () {
155
- it('should throw an error because of a wrong title', async function () {
156
- try {
157
- await client.getSongAudioLink('wrong');
158
- throw new Error('Fail');
159
- }
160
- catch(err) {
161
- assert.isOk(err.message.match('Wrong song title'));
162
- }
163
- });
134
+ describe('.getSong()', function () {
135
+ it('should throw an error because of a wrong title', async function () {
136
+ try {
137
+ await client.getSong('wrong');
138
+ throw new Error('Fail');
139
+ }
140
+ catch (err) {
141
+ assert.isOk(err.message.match('Wrong song title'));
142
+ }
143
+ });
164
144
 
165
- it('should return an empty string', async function () {
166
- assert.isEmpty(await client.getSongAudioLink('unexistent - song'));
167
- });
145
+ it('should return null', async function () {
146
+ assert.isNull(await client.getSong('unexistent - song'));
147
+ });
168
148
 
169
- it('should return the link', async function () {
170
- const link = await client.getSongAudioLink('artist - title')
171
- assert.isTrue(utils.isValidSongAudioLink(link));
149
+ it('should return the right info', async function () {
150
+ const title = 'artist - title';
151
+ const info = await client.getSong(title);
152
+ assert.equal(utils.beautifySongTitle(title), info.title, 'check the title');
153
+ assert.equal(info.tags.TIT3, 'x', 'check the tags');
154
+ assert.isTrue(utils.isValidSongAudioLink(info.audioLink), 'check the audio link');
155
+ assert.isTrue(utils.isValidSongCoverLink(info.coverLink), 'check the cover link');
156
+ });
172
157
  });
173
- });
174
158
 
175
- describe('.getSongCoverLink()', function () {
176
- it('should throw an error because of a wrong title', async function () {
177
- try {
178
- await client.getSongCoverLink('wrong');
179
- throw new Error('Fail');
180
- }
181
- catch(err) {
182
- assert.isOk(err.message.match('Wrong song title'));
183
- }
184
- });
159
+ describe('.getSongAudioLink()', function () {
160
+ it('should throw an error because of a wrong title', async function () {
161
+ try {
162
+ await client.getSongAudioLink('wrong');
163
+ throw new Error('Fail');
164
+ }
165
+ catch (err) {
166
+ assert.isOk(err.message.match('Wrong song title'));
167
+ }
168
+ });
185
169
 
186
- it('should return an empty string', async function () {
187
- assert.isEmpty(await client.getSongCoverLink('unexistent - song'));
188
- });
170
+ it('should return an empty string', async function () {
171
+ assert.isEmpty(await client.getSongAudioLink('unexistent - song'));
172
+ });
189
173
 
190
- it('should return the link', async function () {
191
- const link = await client.getSongCoverLink('artist - title')
192
- assert.isTrue(utils.isValidSongCoverLink(link));
174
+ it('should return the link', async function () {
175
+ const link = await client.getSongAudioLink('artist - title');
176
+ assert.isTrue(utils.isValidSongAudioLink(link));
177
+ });
193
178
  });
194
- });
195
179
 
196
- describe('.getSongAudioToBuffer()', function () {
197
- it('should throw an error because of a wrong title', async function () {
198
- try {
199
- await client.getSongAudioToBuffer('wrong');
200
- throw new Error('Fail');
201
- }
202
- catch(err) {
203
- assert.isOk(err.message.match('Wrong song title'));
204
- }
205
- });
180
+ describe('.getSongCoverLink()', function () {
181
+ it('should throw an error because of a wrong title', async function () {
182
+ try {
183
+ await client.getSongCoverLink('wrong');
184
+ throw new Error('Fail');
185
+ }
186
+ catch (err) {
187
+ assert.isOk(err.message.match('Wrong song title'));
188
+ }
189
+ });
206
190
 
207
- it('should throw an error because of wrong link', async function () {
208
- try {
209
- await client.getSongAudioToBuffer('unexistent - song');
210
- throw new Error('Fail');
211
- }
212
- catch(err) {
213
- assert.isOk(err.message.match('Link for song'));
214
- }
215
- });
191
+ it('should return an empty string', async function () {
192
+ assert.isEmpty(await client.getSongCoverLink('unexistent - song'));
193
+ });
216
194
 
217
- it('should be the same buffer', async function () {
218
- const title = 'artist - title';
219
- const doc = await node.db.getMusicByPk(title);
220
- const originalBuffer = await fse.readFile(node.getFilePath(doc.fileHash));
221
- const buffer = await client.getSongAudioToBuffer(title);
222
- assert.isTrue(Buffer.compare(originalBuffer, buffer) == 0);
195
+ it('should return the link', async function () {
196
+ const link = await client.getSongCoverLink('artist - title');
197
+ assert.isTrue(utils.isValidSongCoverLink(link));
198
+ });
223
199
  });
224
- });
225
200
 
226
- describe('.getSongCoverToBuffer()', function () {
227
- it('should throw an error because of a wrong title', async function () {
228
- try {
229
- await client.getSongCoverToBuffer('wrong');
230
- throw new Error('Fail');
231
- }
232
- catch(err) {
233
- assert.isOk(err.message.match('Wrong song title'));
234
- }
235
- });
201
+ describe('.getSongAudioToBuffer()', function () {
202
+ it('should throw an error because of a wrong title', async function () {
203
+ try {
204
+ await client.getSongAudioToBuffer('wrong');
205
+ throw new Error('Fail');
206
+ }
207
+ catch (err) {
208
+ assert.isOk(err.message.match('Wrong song title'));
209
+ }
210
+ });
236
211
 
237
- it('should throw an error because of wrong link', async function () {
238
- try {
239
- await client.getSongCoverToBuffer('unexistent - song');
240
- throw new Error('Fail');
241
- }
242
- catch(err) {
243
- assert.isOk(err.message.match('Link for song'));
244
- }
245
- });
212
+ it('should throw an error because of wrong link', async function () {
213
+ try {
214
+ await client.getSongAudioToBuffer('unexistent - song');
215
+ throw new Error('Fail');
216
+ }
217
+ catch (err) {
218
+ assert.isOk(err.message.match('Link for song'));
219
+ }
220
+ });
246
221
 
247
- it('should be the same buffer', async function () {
248
- const title = 'artist - title';
249
- const doc = await node.db.getMusicByPk(title);
250
- const originalBuffer = (await utils.getSongTags(node.getFilePath(doc.fileHash))).APIC;
251
- const buffer = await client.getSongCoverToBuffer(title);
252
- assert.isTrue(Buffer.compare(originalBuffer, buffer) == 0);
222
+ it('should be the same buffer', async function () {
223
+ const title = 'artist - title';
224
+ const doc = await node.db.getMusicByPk(title);
225
+ const originalBuffer = await fse.readFile(node.getFilePath(doc.fileHash));
226
+ const buffer = await client.getSongAudioToBuffer(title);
227
+ assert.isTrue(Buffer.compare(originalBuffer, buffer) == 0);
228
+ });
253
229
  });
254
- });
255
230
 
256
- describe('.getSongAudioToPath()', function () {
257
- it('should throw an error because of a wrong title', async function () {
258
- try {
259
- await client.getSongAudioToPath('wrong');
260
- throw new Error('Fail');
261
- }
262
- catch(err) {
263
- assert.isOk(err.message.match('Wrong song title'));
264
- }
265
- });
231
+ describe('.getSongCoverToBuffer()', function () {
232
+ it('should throw an error because of a wrong title', async function () {
233
+ try {
234
+ await client.getSongCoverToBuffer('wrong');
235
+ throw new Error('Fail');
236
+ }
237
+ catch (err) {
238
+ assert.isOk(err.message.match('Wrong song title'));
239
+ }
240
+ });
266
241
 
267
- it('should throw an error because of wrong link', async function () {
268
- try {
269
- await client.getSongAudioToPath('unexistent - song');
270
- throw new Error('Fail');
271
- }
272
- catch(err) {
273
- assert.isOk(err.message.match('Link for song'));
274
- }
275
- });
242
+ it('should throw an error because of wrong link', async function () {
243
+ try {
244
+ await client.getSongCoverToBuffer('unexistent - song');
245
+ throw new Error('Fail');
246
+ }
247
+ catch (err) {
248
+ assert.isOk(err.message.match('Link for song'));
249
+ }
250
+ });
276
251
 
277
- it('should save the file', async function () {
278
- const filePath = path.join(tools.tmpPath, 'audio-saved.mp3');
279
- const title = 'artist - title';
280
- const doc = await node.db.getMusicByPk(title);
281
- const originalBuffer = await fse.readFile(node.getFilePath(doc.fileHash));
282
- await client.getSongAudioToPath(title, filePath);
283
- const buffer = await fse.readFile(filePath);
284
- assert.isTrue(Buffer.compare(originalBuffer, buffer) == 0);
252
+ it('should be the same buffer', async function () {
253
+ const title = 'artist - title';
254
+ const doc = await node.db.getMusicByPk(title);
255
+ const originalBuffer = (await utils.getSongTags(node.getFilePath(doc.fileHash))).APIC;
256
+ const buffer = await client.getSongCoverToBuffer(title);
257
+ assert.isTrue(Buffer.compare(originalBuffer, buffer) == 0);
258
+ });
285
259
  });
286
- });
287
260
 
288
- describe('.getSongCoverToPath()', function () {
289
- it('should throw an error because of a wrong title', async function () {
290
- try {
291
- await client.getSongCoverToPath('wrong');
292
- throw new Error('Fail');
293
- }
294
- catch(err) {
295
- assert.isOk(err.message.match('Wrong song title'));
296
- }
297
- });
261
+ describe('.getSongAudioToPath()', function () {
262
+ it('should throw an error because of a wrong title', async function () {
263
+ try {
264
+ await client.getSongAudioToPath('wrong');
265
+ throw new Error('Fail');
266
+ }
267
+ catch (err) {
268
+ assert.isOk(err.message.match('Wrong song title'));
269
+ }
270
+ });
298
271
 
299
- it('should throw an error because of wrong link', async function () {
300
- try {
301
- await client.getSongCoverToPath('unexistent - song');
302
- throw new Error('Fail');
303
- }
304
- catch(err) {
305
- assert.isOk(err.message.match('Link for song'));
306
- }
307
- });
272
+ it('should throw an error because of wrong link', async function () {
273
+ try {
274
+ await client.getSongAudioToPath('unexistent - song');
275
+ throw new Error('Fail');
276
+ }
277
+ catch (err) {
278
+ assert.isOk(err.message.match('Link for song'));
279
+ }
280
+ });
308
281
 
309
- it('should save the file', async function () {
310
- const filePath = path.join(tools.tmpPath, '/cover-saved.jpg');
311
- const title = 'artist - title';
312
- const doc = await node.db.getMusicByPk(title);
313
- const originalBuffer = (await utils.getSongTags(node.getFilePath(doc.fileHash))).APIC;
314
- await client.getSongCoverToPath(title, filePath);
315
- const buffer = await fse.readFile(filePath);
316
- assert.isTrue(Buffer.compare(originalBuffer, buffer) == 0);
282
+ it('should save the file', async function () {
283
+ const filePath = path.join(tools.tmpPath, 'audio-saved.mp3');
284
+ const title = 'artist - title';
285
+ const doc = await node.db.getMusicByPk(title);
286
+ const originalBuffer = await fse.readFile(node.getFilePath(doc.fileHash));
287
+ await client.getSongAudioToPath(title, filePath);
288
+ const buffer = await fse.readFile(filePath);
289
+ assert.isTrue(Buffer.compare(originalBuffer, buffer) == 0);
290
+ });
317
291
  });
318
- });
319
292
 
320
- describe('.removeSong()', function () {
321
- it('should throw an error because of a wrong title', async function () {
322
- try {
323
- await client.getSongAudioLink('wrong');
324
- throw new Error('Fail');
325
- }
326
- catch(err) {
327
- assert.isOk(err.message.match('Wrong song title'));
328
- }
329
- });
293
+ describe('.getSongCoverToPath()', function () {
294
+ it('should throw an error because of a wrong title', async function () {
295
+ try {
296
+ await client.getSongCoverToPath('wrong');
297
+ throw new Error('Fail');
298
+ }
299
+ catch (err) {
300
+ assert.isOk(err.message.match('Wrong song title'));
301
+ }
302
+ });
330
303
 
331
- it('should return the link', async function () {
332
- const title = 'artist - title';
333
- const doc = await node.db.getMusicByPk(title);
334
- const res = await client.removeSong(title);
335
- assert.equal(res.removed, 1, 'check the result');
336
- assert.isNull(await node.db.getMusicByPk(title), 'check the database');
337
- assert.isFalse(await node.hasFile(doc.fileHash), 'check the file');
304
+ it('should throw an error because of wrong link', async function () {
305
+ try {
306
+ await client.getSongCoverToPath('unexistent - song');
307
+ throw new Error('Fail');
308
+ }
309
+ catch (err) {
310
+ assert.isOk(err.message.match('Link for song'));
311
+ }
312
+ });
313
+
314
+ it('should save the file', async function () {
315
+ const filePath = path.join(tools.tmpPath, '/cover-saved.jpg');
316
+ const title = 'artist - title';
317
+ const doc = await node.db.getMusicByPk(title);
318
+ const originalBuffer = (await utils.getSongTags(node.getFilePath(doc.fileHash))).APIC;
319
+ await client.getSongCoverToPath(title, filePath);
320
+ const buffer = await fse.readFile(filePath);
321
+ assert.isTrue(Buffer.compare(originalBuffer, buffer) == 0);
322
+ });
338
323
  });
339
- });
340
324
 
341
- describe('.createRequestedSongAudioLink()', () => {
342
- it('should return the right link', async () => {
343
- const title = 'artist-title';
344
- const link = client.createRequestedSongAudioLink(title);
345
- assert.equal(link, `${client.getRequestProtocol()}://${client.workerAddress}/client/request-song?type=audio&title=${title}`);
325
+ describe('.removeSong()', function () {
326
+ it('should throw an error because of a wrong title', async function () {
327
+ try {
328
+ await client.getSongAudioLink('wrong');
329
+ throw new Error('Fail');
330
+ }
331
+ catch (err) {
332
+ assert.isOk(err.message.match('Wrong song title'));
333
+ }
334
+ });
335
+
336
+ it('should return the link', async function () {
337
+ const title = 'artist - title';
338
+ const doc = await node.db.getMusicByPk(title);
339
+ const res = await client.removeSong(title);
340
+ assert.equal(res.removed, 1, 'check the result');
341
+ assert.isNull(await node.db.getMusicByPk(title), 'check the database');
342
+ assert.isFalse(await node.hasFile(doc.fileHash), 'check the file');
343
+ });
346
344
  });
347
- });
348
345
 
349
- describe('.createRequestedSongCoverLink()', () => {
350
- it('should return the right link', async () => {
351
- const title = 'artist-title';
352
- const link = client.createRequestedSongCoverLink(title);
353
- assert.equal(link, `${client.getRequestProtocol()}://${client.workerAddress}/client/request-song?type=cover&title=${title}`);
346
+ describe('.createRequestedSongAudioLink()', () => {
347
+ it('should return the right link', async () => {
348
+ const title = 'artist-title';
349
+ const link = client.createRequestedSongAudioLink(title);
350
+ assert.equal(link, `${client.getRequestProtocol()}://${client.workerAddress}/client/request-song?type=audio&title=${title}`);
351
+ });
354
352
  });
355
- });
356
353
 
357
- describe('.deinit()', function () {
358
- it('should not throw an exception', async function () {
359
- await client.deinit();
354
+ describe('.createRequestedSongCoverLink()', () => {
355
+ it('should return the right link', async () => {
356
+ const title = 'artist-title';
357
+ const link = client.createRequestedSongCoverLink(title);
358
+ assert.equal(link, `${client.getRequestProtocol()}://${client.workerAddress}/client/request-song?type=cover&title=${title}`);
359
+ });
360
+ });
361
+
362
+ describe('.deinit()', function () {
363
+ it('should not throw an exception', async function () {
364
+ await client.deinit();
365
+ });
360
366
  });
361
367
  });
362
- });
368
+ }