1 | var downloader = require('./../lib/downloader');
|
2 | var assert = require('assert');
|
3 | var os = require('os');
|
4 | var path = require('path');
|
5 |
|
6 | describe('Downloader', function() {
|
7 | it('should download a file correctly', function(done) {
|
8 | var destinationPath = path.join(os.tmpdir(), "test_" + Math.round(Math.random()*10000));
|
9 | downloader.get('https://testingbot.com/assets/about.png', { destination: destinationPath }, function(err, downloadedFilePath) {
|
10 | assert.equal(err, null);
|
11 | assert.equal(downloadedFilePath, destinationPath);
|
12 | done();
|
13 | });
|
14 | });
|
15 |
|
16 | it('should return an error when a download fails (bad http code)', function(done) {
|
17 | var destinationPath = path.join(os.tmpdir(), "test_" + Math.round(Math.random()*10000));
|
18 | downloader.get('https://testingbot.com/assets/this_does_not_exist.png', { destination: destinationPath }, function(err, downloadedFilePath) {
|
19 | assert.equal(err.message, 'Could not download https://testingbot.com/assets/this_does_not_exist.png, statusCode: 404');
|
20 | assert.equal(downloadedFilePath, null);
|
21 | done();
|
22 | });
|
23 | });
|
24 | }); |
\ | No newline at end of file |