var rewire = require('rewire');
var modulePath = '../../lib/client/S3Client.js';

describe('S3Client', function () {
    describe('require', function () {
        it('should be truthy', function () {
            var S3Client = require(modulePath).S3Client;
            expect(S3Client).toBeTruthy();
        });
        it('should not throw exception ', function () {
            expect(function () {
                var S3Client = require(modulePath).S3Client;
            }).not.toThrow();
        });
    });

    describe('methods', function () {
        var S3ClientMock;
        var S3Client;
        var cb;
        var instance;
        var nativeClient;

        beforeEach(function () {
            S3ClientMock = rewire(modulePath);
            S3Client = S3ClientMock.S3Client;

            cb = jasmine.createSpy('callback');

            var clientRequestMock = jasmine.createSpyObj('knox request', ['setTimeout', 'on', 'once', 'end', 'abort']);

            nativeClient = jasmine.createSpyObj('knox client', ['get', 'put', 'copy', 'head', 'del']);
            nativeClient.get.andReturn(clientRequestMock);

            var knoxMock = jasmine.createSpyObj('knox mock', ['createClient']);
            knoxMock.createClient.andReturn(nativeClient);

            S3ClientMock.__set__('knox', knoxMock);

            instance = new S3Client({}, {});
        });

        describe('get', function () {
            it('should pass range header when provided in params', function () {
                instance.get('/key/to/get', { range: 'bytes=0-5' }, cb);

                expect(nativeClient.get).toHaveBeenCalledWith('/key/to/get', { range: 'bytes=0-5' });
            });
        });
    });
});
