Skip to content

Commit

Permalink
Add redirect test back for image-size test 馃檲 (#8984)
Browse files Browse the repository at this point in the history
no issue

Adds redirect test back, which was accidentially removed with PR #8900
  • Loading branch information
aileen authored and ErisDS committed Sep 7, 2017
1 parent 56d64e5 commit c64c56f
Showing 1 changed file with 47 additions and 5 deletions.
52 changes: 47 additions & 5 deletions core/test/unit/utils/image-size_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('Image Size', function () {
var sizeOfStub,
result,
requestMock,
secondRequestMock,
originalStoragePath;

beforeEach(function () {
Expand Down Expand Up @@ -77,7 +78,7 @@ describe('Image Size', function () {
requestMock = nock('https://static.wixstatic.com')
.get('/media/355241_d31358572a2542c5a44738ddcb59e7ea.jpg_256')
.reply(200, {
data: '<Buffer 2c be a4 40 f7 87 73 1e 57 2c c1 e4 0d 79 03 95 42 f0 42 2e 41 95 27 c9 5c 35 a7 71 2c 09 5a 57 d3 04 1e 83 03 28 07 96 b0 c8 88 65 07 7a d1 d6 63 50>'
body: '<Buffer 2c be a4 40 f7 87 73 1e 57 2c c1 e4 0d 79 03 95 42 f0 42 2e 41 95 27 c9 5c 35 a7 71 2c 09 5a 57 d3 04 1e 83 03 28 07 96 b0 c8 88 65 07 7a d1 d6 63 50>'
});

sizeOfStub = sandbox.stub();
Expand Down Expand Up @@ -109,7 +110,7 @@ describe('Image Size', function () {
requestMock = nock('https://super-website.com')
.get('/media/icon.ico')
.reply(200, {
data: '<Buffer 2c be a4 40 f7 87 73 1e 57 2c c1 e4 0d 79 03 95 42 f0 42 2e 41 95 27 c9 5c 35 a7 71 2c 09 5a 57 d3 04 1e 83 03 28 07 96 b0 c8 88 65 07 7a d1 d6 63 50>'
body: '<Buffer 2c be a4 40 f7 87 73 1e 57 2c c1 e4 0d 79 03 95 42 f0 42 2e 41 95 27 c9 5c 35 a7 71 2c 09 5a 57 d3 04 1e 83 03 28 07 96 b0 c8 88 65 07 7a d1 d6 63 50>'
});

sizeOfStub = sandbox.stub();
Expand Down Expand Up @@ -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: '<Buffer 2c be a4 40 f7 87 73 1e 57 2c c1 e4 0d 79 03 95 42 f0 42 2e 41 95 27 c9 5c 35 a7 71 2c 09 5a 57 d3 04 1e 83 03 28 07 96 b0 c8 88 65 07 7a d1 d6 63 50>'
body: '<Buffer 2c be a4 40 f7 87 73 1e 57 2c c1 e4 0d 79 03 95 42 f0 42 2e 41 95 27 c9 5c 35 a7 71 2c 09 5a 57 d3 04 1e 83 03 28 07 96 b0 c8 88 65 07 7a d1 d6 63 50>'
});

sizeOfStub = sandbox.stub();
Expand All @@ -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: '<Buffer 2c be a4 40 f7 87 73 1e 57 2c c1 e4 0d 79 03 95 42 f0 42 2e 41 95 27 c9 5c 35 a7 71 2c 09 5a 57 d3 04 1e 83 03 28 07 96 b0 c8 88 65 07 7a d1 d6 63 50>'
},
{
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: '<Buffer 2c be a4 40 f7 87 73 1e 57 2c c1 e4 0d 79 03 95 42 f0 42 2e 41 95 27 c9 5c 35 a7 71 2c 09 5a 57 d3 04 1e 83 03 28 07 96 b0 c8 88 65 07 7a d1 d6 63 50>'
});

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,
Expand All @@ -191,7 +233,7 @@ describe('Image Size', function () {
requestMock = nock('http://myblog.com')
.get('/content/images/favicon.png')
.reply(200, {
data: '<Buffer 2c be a4 40 f7 87 73 1e 57 2c c1 e4 0d 79 03 95 42 f0 42 2e 41 95 27 c9 5c 35 a7 71 2c 09 5a 57 d3 04 1e 83 03 28 07 96 b0 c8 88 65 07 7a d1 d6 63 50>'
body: '<Buffer 2c be a4 40 f7 87 73 1e 57 2c c1 e4 0d 79 03 95 42 f0 42 2e 41 95 27 c9 5c 35 a7 71 2c 09 5a 57 d3 04 1e 83 03 28 07 96 b0 c8 88 65 07 7a d1 d6 63 50>'
});

result = imageSize.getImageSizeFromUrl(url).then(function (res) {
Expand Down Expand Up @@ -245,7 +287,7 @@ describe('Image Size', function () {
requestMock = nock('https://static.wixstatic.com')
.get('/media/355241_d31358572a2542c5a44738ddcb59e7ea.jpg_256')
.reply(200, {
data: '<Buffer 2c be a4 40 f7 87 73 1e 57 2c c1 e4 0d 79 03 95 42 f0 42 2e 41 95 27 c9 5c 35 a7 71 2c 09 5a 57 d3 04 1e 83 03 28 07 96 b0 c8 88 65 07 7a d1 d6 63 50>'
body: '<Buffer 2c be a4 40 f7 87 73 1e 57 2c c1 e4 0d 79 03 95 42 f0 42 2e 41 95 27 c9 5c 35 a7 71 2c 09 5a 57 d3 04 1e 83 03 28 07 96 b0 c8 88 65 07 7a d1 d6 63 50>'
});

sizeOfStub = sandbox.stub();
Expand Down

0 comments on commit c64c56f

Please sign in to comment.