mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Add redirect test back for image-size test 🙈 (#8984)
no issue Adds redirect test back, which was accidentially removed with PR #8900
This commit is contained in:
parent
56d64e53bf
commit
c64c56f1dc
1 changed files with 47 additions and 5 deletions
|
@ -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: '<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();
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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,
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue