diff --git a/core/test/unit/utils/image-size_spec.js b/core/test/unit/utils/image-size_spec.js index e4695a495d7..9b5e2ff4122 100644 --- a/core/test/unit/utils/image-size_spec.js +++ b/core/test/unit/utils/image-size_spec.js @@ -16,6 +16,7 @@ describe('Image Size', function () { var sizeOfStub, result, requestMock, + secondRequestMock, originalStoragePath; beforeEach(function () { @@ -77,7 +78,7 @@ describe('Image Size', function () { requestMock = nock('https://static.wixstatic.com') .get('/media/355241_d31358572a2542c5a44738ddcb59e7ea.jpg_256') .reply(200, { - data: '' + body: '' }); sizeOfStub = sandbox.stub(); @@ -109,7 +110,7 @@ describe('Image Size', function () { requestMock = nock('https://super-website.com') .get('/media/icon.ico') .reply(200, { - data: '' + body: '' }); sizeOfStub = sandbox.stub(); @@ -150,7 +151,7 @@ describe('Image Size', function () { requestMock = nock('http://www.gravatar.com') .get('/avatar/ef6dcde5c99bb8f685dd451ccc3e050a?s=250&d=mm&r=x') .reply(200, { - data: '' + body: '' }); sizeOfStub = sandbox.stub(); @@ -170,6 +171,47 @@ describe('Image Size', function () { }).catch(done); }); + it('[success] can handle redirect', function (done) { + var url = 'http://noimagehere.com/files/f/feedough/x/11/1540353_20925115.jpg', + expectedImageObject = + { + height: 100, + url: 'http://noimagehere.com/files/f/feedough/x/11/1540353_20925115.jpg', + width: 100 + }; + + requestMock = nock('http://noimagehere.com') + .get('/files/f/feedough/x/11/1540353_20925115.jpg') + .reply(301, { + body: '' + }, + { + location: 'http://someredirectedurl.com/files/f/feedough/x/11/1540353_20925115.jpg' + }); + + secondRequestMock = nock('http://someredirectedurl.com') + .get('/files/f/feedough/x/11/1540353_20925115.jpg') + .reply(200, { + body: '' + }); + + sizeOfStub.returns({width: 100, height: 100, type: 'jpg'}); + imageSize.__set__('sizeOf', sizeOfStub); + + result = imageSize.getImageSizeFromUrl(url).then(function (res) { + requestMock.isDone().should.be.true(); + secondRequestMock.isDone().should.be.true(); + should.exist(res); + should.exist(res.width); + res.width.should.be.equal(expectedImageObject.width); + should.exist(res.height); + res.height.should.be.equal(expectedImageObject.height); + should.exist(res.url); + res.url.should.be.equal(expectedImageObject.url); + done(); + }).catch(done); + }); + it('[success] should switch to local file storage if available', function (done) { var url = '/content/images/favicon.png', urlForStub, @@ -191,7 +233,7 @@ describe('Image Size', function () { requestMock = nock('http://myblog.com') .get('/content/images/favicon.png') .reply(200, { - data: '' + body: '' }); result = imageSize.getImageSizeFromUrl(url).then(function (res) { @@ -245,7 +287,7 @@ describe('Image Size', function () { requestMock = nock('https://static.wixstatic.com') .get('/media/355241_d31358572a2542c5a44738ddcb59e7ea.jpg_256') .reply(200, { - data: '' + body: '' }); sizeOfStub = sandbox.stub();