/** @overview nodeunit test case. */

var testResource = require('../../../test_resource'),
    request = require('request'),
    mockInjector = require('../../../mock_injector'),
    fetchHtml = require('../../../../lib/fetch/fetch_html.js');

exports.setUp = function (done) {
    done();
};

exports.tearDown = function (done) {
    mockInjector.restoreAll();
    done();
};


exports['Fetch html.'] = function (test) {
    mockInjector.inject(request, 'get', function (config, callback) {
        callback(null, {statusCode: 404});
    });
    fetchHtml('http://google.com/not_found', function (err, data) {
        mockInjector.restore();
        test.ok(err);
        mockInjector.inject(request, 'get', function (config, callback) {
            callback(null, {statusCode: 200}, 'foo');
        });
        fetchHtml('http://google.com', function (err, data) {
            mockInjector.restore();
            test.ifError(err);
            test.ok(data);
            test.done();
        });
    });
};