Skip to content
This repository was archived by the owner on Feb 27, 2022. It is now read-only.

Commit 1fbca88

Browse files
author
Elad Gil
committed
more "downloader" fixes
1 parent 1d1e3bb commit 1fbca88

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

__mocks__/RNBackgroundDownload.js renamed to __mocks__/RNBackgroundDownloader.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { NativeModules } from 'react-native';
88
// 2 - Cancelled / Failed
99
// 3 - Completed (not necessarily successfully)
1010

11-
NativeModules.RNBackgroundDownload = {
11+
NativeModules.RNBackgroundDownloader = {
1212
download: jest.fn(),
1313
pauseTask: jest.fn(),
1414
resumeTask: jest.fn(),
@@ -21,42 +21,42 @@ NativeModules.RNBackgroundDownload = {
2121
foundDownloads = [
2222
{
2323
id: 'taskRunning',
24-
state: NativeModules.RNBackgroundDownload.TaskRunning,
24+
state: NativeModules.RNBackgroundDownloader.TaskRunning,
2525
percent: 0.5,
2626
bytesWritten: 50,
2727
totalBytes: 100
2828
},
2929
{
3030
id: 'taskPaused',
31-
state: NativeModules.RNBackgroundDownload.TaskSuspended,
31+
state: NativeModules.RNBackgroundDownloader.TaskSuspended,
3232
percent: 0.7,
3333
bytesWritten: 70,
3434
totalBytes: 100
3535
},
3636
{
3737
id: 'taskCancelled',
3838
percent: 0.9,
39-
state: NativeModules.RNBackgroundDownload.TaskCanceling,
39+
state: NativeModules.RNBackgroundDownloader.TaskCanceling,
4040
bytesWritten: 90,
4141
totalBytes: 100
4242
},
4343
{
4444
id: 'taskCompletedExplicit',
45-
state: NativeModules.RNBackgroundDownload.TaskCompleted,
45+
state: NativeModules.RNBackgroundDownloader.TaskCompleted,
4646
percent: 1,
4747
bytesWritten: 100,
4848
totalBytes: 100
4949
},
5050
{
5151
id: 'taskCompletedImplicit',
52-
state: NativeModules.RNBackgroundDownload.TaskCompleted,
52+
state: NativeModules.RNBackgroundDownloader.TaskCompleted,
5353
percent: 1,
5454
bytesWritten: 100,
5555
totalBytes: 100
5656
},
5757
{
5858
id: 'taskFailed',
59-
state: NativeModules.RNBackgroundDownload.TaskCompleted,
59+
state: NativeModules.RNBackgroundDownloader.TaskCompleted,
6060
percent: 0.9,
6161
bytesWritten: 90,
6262
totalBytes: 100

__tests__/mainTest.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,27 @@ jest.mock('NativeEventEmitter', () => {
1010
};
1111
});
1212

13-
import RNBackgroundDownload from '../index';
13+
import RNBackgroundDownloader from '../index';
1414
import DownloadTask from '../lib/downloadTask';
1515
import { NativeEventEmitter, NativeModules } from 'react-native';
1616

17-
const RNBackgroundDownloadNative = NativeModules.RNBackgroundDownload;
17+
const RNBackgroundDownloaderNative = NativeModules.RNBackgroundDownloader;
1818

1919
let downloadTask;
2020

2121
test('download function', () => {
22-
downloadTask = RNBackgroundDownload.download({
22+
downloadTask = RNBackgroundDownloader.download({
2323
id: 'test',
2424
url: 'test',
2525
destination: 'test'
2626
});
2727
expect(downloadTask).toBeInstanceOf(DownloadTask);
28-
expect(RNBackgroundDownloadNative.download).toHaveBeenCalled();
28+
expect(RNBackgroundDownloaderNative.download).toHaveBeenCalled();
2929
});
3030

3131
test('begin event', () => {
3232
return new Promise(resolve => {
33-
const beginDT = RNBackgroundDownload.download({
33+
const beginDT = RNBackgroundDownloader.download({
3434
id: 'testBegin',
3535
url: 'test',
3636
destination: 'test'
@@ -48,7 +48,7 @@ test('begin event', () => {
4848

4949
test('progress event', () => {
5050
return new Promise(resolve => {
51-
RNBackgroundDownload.download({
51+
RNBackgroundDownloader.download({
5252
id: 'testProgress',
5353
url: 'test',
5454
destination: 'test'
@@ -69,7 +69,7 @@ test('progress event', () => {
6969

7070
test('done event', () => {
7171
return new Promise(resolve => {
72-
const doneDT = RNBackgroundDownload.download({
72+
const doneDT = RNBackgroundDownloader.download({
7373
id: 'testDone',
7474
url: 'test',
7575
destination: 'test'
@@ -85,7 +85,7 @@ test('done event', () => {
8585

8686
test('fail event', () => {
8787
return new Promise(resolve => {
88-
const failDT = RNBackgroundDownload.download({
88+
const failDT = RNBackgroundDownloader.download({
8989
id: 'testFail',
9090
url: 'test',
9191
destination: 'test'
@@ -102,45 +102,45 @@ test('fail event', () => {
102102
});
103103

104104
test('pause', () => {
105-
const pauseDT = RNBackgroundDownload.download({
105+
const pauseDT = RNBackgroundDownloader.download({
106106
id: 'testPause',
107107
url: 'test',
108108
destination: 'test'
109109
});
110110

111111
pauseDT.pause();
112112
expect(pauseDT.state).toBe('PAUSED');
113-
expect(RNBackgroundDownloadNative.pauseTask).toHaveBeenCalled();
113+
expect(RNBackgroundDownloaderNative.pauseTask).toHaveBeenCalled();
114114
});
115115

116116
test('resume', () => {
117-
const resumeDT = RNBackgroundDownload.download({
117+
const resumeDT = RNBackgroundDownloader.download({
118118
id: 'testResume',
119119
url: 'test',
120120
destination: 'test'
121121
});
122122

123123
resumeDT.resume();
124124
expect(resumeDT.state).toBe('DOWNLOADING');
125-
expect(RNBackgroundDownloadNative.resumeTask).toHaveBeenCalled();
125+
expect(RNBackgroundDownloaderNative.resumeTask).toHaveBeenCalled();
126126
});
127127

128128
test('stop', () => {
129-
const stopDT = RNBackgroundDownload.download({
129+
const stopDT = RNBackgroundDownloader.download({
130130
id: 'testStop',
131131
url: 'test',
132132
destination: 'test'
133133
});
134134

135135
stopDT.stop();
136136
expect(stopDT.state).toBe('STOPPED');
137-
expect(RNBackgroundDownloadNative.stopTask).toHaveBeenCalled();
137+
expect(RNBackgroundDownloaderNative.stopTask).toHaveBeenCalled();
138138
});
139139

140140
test('checkForExistingDownloads', () => {
141-
return RNBackgroundDownload.checkForExistingDownloads()
141+
return RNBackgroundDownloader.checkForExistingDownloads()
142142
.then(foundDownloads => {
143-
expect(RNBackgroundDownloadNative.checkForExistingDownloads).toHaveBeenCalled();
143+
expect(RNBackgroundDownloaderNative.checkForExistingDownloads).toHaveBeenCalled();
144144
expect(foundDownloads.length).toBe(4);
145145
foundDownloads.forEach(foundDownload => {
146146
expect(foundDownload).toBeInstanceOf(DownloadTask);
@@ -151,7 +151,7 @@ test('checkForExistingDownloads', () => {
151151
});
152152

153153
test('wrong handler type', () => {
154-
let dt = RNBackgroundDownload.download({
154+
let dt = RNBackgroundDownloader.download({
155155
id: 'test22222',
156156
url: 'test',
157157
destination: 'test'

lib/downloadTask.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { NativeModules } from 'react-native';
2-
const { RNBackgroundDownload } = NativeModules;
2+
const { RNBackgroundDownloader } = NativeModules;
33

44
function validateHandler(handler) {
55
if (!(typeof handler === 'function')) {
6-
throw new TypeError(`[RNBackgroundDownload] expected argument to be a function, got: ${typeof handler}`);
6+
throw new TypeError(`[RNBackgroundDownloader] expected argument to be a function, got: ${typeof handler}`);
77
}
88
}
99
export default class DownloadTask {
@@ -79,16 +79,16 @@ export default class DownloadTask {
7979

8080
pause() {
8181
this.state = 'PAUSED';
82-
RNBackgroundDownload.pauseTask(this.id);
82+
RNBackgroundDownloader.pauseTask(this.id);
8383
}
8484

8585
resume() {
8686
this.state = 'DOWNLOADING';
87-
RNBackgroundDownload.resumeTask(this.id);
87+
RNBackgroundDownloader.resumeTask(this.id);
8888
}
8989

9090
stop() {
9191
this.state = 'STOPPED';
92-
RNBackgroundDownload.stopTask(this.id);
92+
RNBackgroundDownloader.stopTask(this.id);
9393
}
9494
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"jest": {
5252
"preset": "react-native",
5353
"setupFiles": [
54-
"./__mocks__/RNBackgroundDownload.js",
54+
"./__mocks__/RNBackgroundDownloader.js",
5555
"./node_modules/react-native/Libraries/EventEmitter/__mocks__/NativeEventEmitter.js"
5656
]
5757
}

0 commit comments

Comments
 (0)