@@ -4,7 +4,8 @@ import fs from 'fs';
4
4
5
5
import { Deluge } from '../src/index' ;
6
6
7
- const baseURL = 'http://localhost:8112/' ;
7
+ const host = 'http://localhost:8112/' ;
8
+ const port = 8112 ;
8
9
const torrentFile = path . join ( __dirname , '/ubuntu-18.04.1-desktop-amd64.iso.torrent' ) ;
9
10
10
11
async function setupTorrent ( deluge : Deluge ) {
@@ -23,7 +24,7 @@ async function setupTorrent(deluge: Deluge) {
23
24
24
25
describe ( 'Deluge' , ( ) => {
25
26
afterEach ( async ( ) => {
26
- const deluge = new Deluge ( { baseURL } ) ;
27
+ const deluge = new Deluge ( { host , port } ) ;
27
28
const torrents = await deluge . listTorrents ( ) ;
28
29
const ids = Object . keys ( torrents . result . torrents ) ;
29
30
for ( const id of ids ) {
@@ -32,23 +33,23 @@ describe('Deluge', () => {
32
33
}
33
34
} ) ;
34
35
it ( 'should be instantiable' , async ( ) => {
35
- const deluge = new Deluge ( { baseURL } ) ;
36
+ const deluge = new Deluge ( { host , port } ) ;
36
37
expect ( deluge ) . toBeTruthy ( ) ;
37
38
} ) ;
38
39
it ( 'should disconnect' , async ( ) => {
39
- const deluge = new Deluge ( { baseURL } ) ;
40
+ const deluge = new Deluge ( { host , port } ) ;
40
41
await deluge . connect ( ) ;
41
42
const res = await deluge . disconnect ( ) ;
42
43
expect ( res ) . toBe ( true ) ;
43
44
} ) ;
44
45
it ( 'should connect' , async ( ) => {
45
- const deluge = new Deluge ( { baseURL } ) ;
46
+ const deluge = new Deluge ( { host , port } ) ;
46
47
const res = await deluge . connect ( ) ;
47
48
// tslint:disable-next-line:no-null-keyword
48
49
expect ( res . result ) . toBe ( null ) ;
49
50
} ) ;
50
51
it ( 'should get plugins' , async ( ) => {
51
- const deluge = new Deluge ( { baseURL } ) ;
52
+ const deluge = new Deluge ( { host , port } ) ;
52
53
const res = await deluge . getPlugins ( ) ;
53
54
expect ( res . result . enabled_plugins ) . toEqual ( [ ] ) ;
54
55
expect ( res . result . available_plugins ) . toBeDefined ( ) ;
@@ -64,7 +65,7 @@ describe('Deluge', () => {
64
65
] ) ;
65
66
} ) ;
66
67
it ( 'should get plugins info' , async ( ) => {
67
- const deluge = new Deluge ( { baseURL } ) ;
68
+ const deluge = new Deluge ( { host , port } ) ;
68
69
const res = await deluge . getPluginInfo ( [ 'Label' ] ) ;
69
70
expect ( res . result . License ) . toEqual ( 'GPLv3' ) ;
70
71
} ) ;
@@ -77,12 +78,12 @@ describe('Deluge', () => {
77
78
// await deluge.disablePlugin(['Label']);
78
79
// });
79
80
it ( 'should get config' , async ( ) => {
80
- const deluge = new Deluge ( { baseURL } ) ;
81
+ const deluge = new Deluge ( { host , port } ) ;
81
82
const res = await deluge . getConfig ( ) ;
82
83
expect ( res . result . dht ) . toBeDefined ( ) ;
83
84
} ) ;
84
85
it ( 'should set config' , async ( ) => {
85
- const deluge = new Deluge ( { baseURL } ) ;
86
+ const deluge = new Deluge ( { host , port } ) ;
86
87
const startConfig = await deluge . getConfig ( ) ;
87
88
expect ( startConfig . result . upnp ) . toBe ( true ) ;
88
89
await deluge . setConfig ( { upnp : false } ) ;
@@ -91,18 +92,18 @@ describe('Deluge', () => {
91
92
await deluge . setConfig ( { upnp : true } ) ;
92
93
} ) ;
93
94
it ( 'should login' , async ( ) => {
94
- const deluge = new Deluge ( { baseURL } ) ;
95
+ const deluge = new Deluge ( { host , port } ) ;
95
96
const success = await deluge . login ( ) ;
96
97
expect ( success ) . toBe ( true ) ;
97
98
} ) ;
98
99
it ( 'should logout' , async ( ) => {
99
- const deluge = new Deluge ( { baseURL } ) ;
100
+ const deluge = new Deluge ( { host , port } ) ;
100
101
await deluge . login ( ) ;
101
102
const success = await deluge . logout ( ) ;
102
103
expect ( success ) . toBe ( true ) ;
103
104
} ) ;
104
105
it ( 'should change password' , async ( ) => {
105
- const deluge = new Deluge ( { baseURL } ) ;
106
+ const deluge = new Deluge ( { host , port } ) ;
106
107
const oldPassword = 'deluge' ;
107
108
const newPassword = 'deluge1' ;
108
109
// change password
@@ -119,35 +120,35 @@ describe('Deluge', () => {
119
120
expect ( deluge . changePassword ( 'shouldfail' ) ) . rejects . toThrowError ( ) ;
120
121
} ) ;
121
122
it ( 'should list methods' , async ( ) => {
122
- const deluge = new Deluge ( { baseURL } ) ;
123
+ const deluge = new Deluge ( { host , port } ) ;
123
124
const methods = await deluge . listMethods ( ) ;
124
125
expect ( Array . isArray ( methods . result ) ) . toEqual ( true ) ;
125
126
expect ( methods . result . length ) . toBeGreaterThanOrEqual ( 88 ) ;
126
127
} ) ;
127
128
it ( 'should upload torrent from full path' , async ( ) => {
128
- const deluge = new Deluge ( { baseURL } ) ;
129
+ const deluge = new Deluge ( { host , port } ) ;
129
130
const res = await deluge . upload ( torrentFile ) ;
130
131
expect ( res . files . length ) . toBe ( 1 ) ;
131
132
expect ( res . success ) . toBe ( true ) ;
132
133
} ) ;
133
134
it ( 'should add torrent from file path string' , async ( ) => {
134
- const deluge = new Deluge ( { baseURL } ) ;
135
+ const deluge = new Deluge ( { host , port } ) ;
135
136
const res = await deluge . addTorrent ( torrentFile ) ;
136
137
expect ( res . result ) . toBe ( true ) ;
137
138
} ) ;
138
139
it ( 'should add torrent from file buffer' , async ( ) => {
139
- const deluge = new Deluge ( { baseURL } ) ;
140
+ const deluge = new Deluge ( { host , port } ) ;
140
141
const res = await deluge . addTorrent ( fs . readFileSync ( torrentFile ) ) ;
141
142
expect ( res . result ) . toBe ( true ) ;
142
143
} ) ;
143
144
it ( 'should add torrent from file contents base64' , async ( ) => {
144
- const deluge = new Deluge ( { baseURL } ) ;
145
+ const deluge = new Deluge ( { host , port } ) ;
145
146
const contents = Buffer . from ( fs . readFileSync ( torrentFile ) ) . toString ( 'base64' ) ;
146
147
const res = await deluge . addTorrent ( contents ) ;
147
148
expect ( res . result ) . toBe ( true ) ;
148
149
} ) ;
149
150
it ( 'should get torrent status' , async ( ) => {
150
- const deluge = new Deluge ( { baseURL } ) ;
151
+ const deluge = new Deluge ( { host , port } ) ;
151
152
const res = await setupTorrent ( deluge ) ;
152
153
const keys = Object . keys ( res . result . torrents ) ;
153
154
for ( const key of keys ) {
@@ -156,7 +157,7 @@ describe('Deluge', () => {
156
157
}
157
158
} ) ;
158
159
it ( 'should list torrents' , async ( ) => {
159
- const deluge = new Deluge ( { baseURL } ) ;
160
+ const deluge = new Deluge ( { host , port } ) ;
160
161
await setupTorrent ( deluge ) ;
161
162
const res = await deluge . listTorrents ( ) ;
162
163
expect ( res . result . torrents ) . toBeDefined ( ) ;
@@ -168,7 +169,7 @@ describe('Deluge', () => {
168
169
}
169
170
} ) ;
170
171
it ( 'should move torrents in queue' , async ( ) => {
171
- const deluge = new Deluge ( { baseURL } ) ;
172
+ const deluge = new Deluge ( { host , port } ) ;
172
173
const res = await setupTorrent ( deluge ) ;
173
174
const key = Object . keys ( res . result . torrents ) [ 0 ] ;
174
175
await deluge . queueUp ( key ) ;
@@ -177,13 +178,13 @@ describe('Deluge', () => {
177
178
await deluge . queueBottom ( key ) ;
178
179
} ) ;
179
180
it ( 'should force recheck torrent' , async ( ) => {
180
- const deluge = new Deluge ( { baseURL } ) ;
181
+ const deluge = new Deluge ( { host , port } ) ;
181
182
const res = await setupTorrent ( deluge ) ;
182
183
const key = Object . keys ( res . result . torrents ) [ 0 ] ;
183
184
await deluge . verifyTorrent ( key ) ;
184
185
} ) ;
185
186
it ( 'should pause/resume torrents' , async ( ) => {
186
- const deluge = new Deluge ( { baseURL } ) ;
187
+ const deluge = new Deluge ( { host , port } ) ;
187
188
const res = await setupTorrent ( deluge ) ;
188
189
const keys = Object . keys ( res . result . torrents ) ;
189
190
for ( const key of keys ) {
@@ -195,7 +196,7 @@ describe('Deluge', () => {
195
196
}
196
197
} ) ;
197
198
it ( 'should set torrent options' , async ( ) => {
198
- const deluge = new Deluge ( { baseURL } ) ;
199
+ const deluge = new Deluge ( { host , port } ) ;
199
200
const res = await setupTorrent ( deluge ) ;
200
201
const keys = Object . keys ( res . result . torrents ) ;
201
202
for ( const key of keys ) {
0 commit comments