2016-05-25 21:03:07 +01:00
|
|
|
import path from 'path';
|
2015-07-09 23:01:43 +01:00
|
|
|
import assert from 'assert';
|
2016-05-24 21:33:09 +01:00
|
|
|
import sizeOf from 'image-size';
|
2015-07-09 23:01:43 +01:00
|
|
|
import { agent } from 'supertest';
|
2015-08-22 16:16:15 +01:00
|
|
|
import app from '../../app';
|
2015-07-09 23:01:43 +01:00
|
|
|
|
2015-08-22 16:16:15 +01:00
|
|
|
const request = agent(app.listen());
|
2015-07-09 23:01:43 +01:00
|
|
|
|
|
|
|
let file = {};
|
|
|
|
describe('setup hostr-web file', function() {
|
|
|
|
describe('when POSTing a file to /file', function() {
|
|
|
|
it('should receive a new file object', function(done) {
|
|
|
|
this.timeout(30000);
|
2015-08-22 16:16:15 +01:00
|
|
|
request
|
|
|
|
.post('/api/file')
|
2016-05-25 21:03:07 +01:00
|
|
|
.attach('file', path.join(__dirname, '..', 'fixtures', 'utah-arches.jpg'))
|
2015-07-09 23:01:43 +01:00
|
|
|
.auth('test@hostr.co', 'test-password')
|
|
|
|
.expect(201)
|
|
|
|
.expect(function(response) {
|
|
|
|
assert(response.body.name === 'utah-arches.jpg');
|
|
|
|
file = response.body;
|
|
|
|
})
|
|
|
|
.end(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('hostr-web file', function() {
|
|
|
|
describe('when GET /file/:id/:name', function() {
|
|
|
|
it('should receive an image', function(done) {
|
|
|
|
request
|
|
|
|
.get('/file/' + file.id + '/' + file.name)
|
|
|
|
.expect(200)
|
|
|
|
.expect('Content-type', 'image/jpeg')
|
|
|
|
.expect(function(response) {
|
|
|
|
assert(response.body.length === 194544);
|
|
|
|
})
|
|
|
|
.end(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when GET /file/150/:id/:name', function() {
|
2016-05-25 21:03:07 +01:00
|
|
|
it('should receive a 150px wide thumbnail of the image', function() {
|
2015-07-09 23:01:43 +01:00
|
|
|
request
|
|
|
|
.get('/file/150/' + file.id + '/' + file.name)
|
|
|
|
.expect(200)
|
|
|
|
.expect('Content-type', 'image/jpeg')
|
|
|
|
.expect(function(response) {
|
2016-05-25 21:03:07 +01:00
|
|
|
const width = sizeOf(response.body).width;
|
|
|
|
assert(width === 150);
|
|
|
|
});
|
2015-07-09 23:01:43 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when GET /file/970/:id/:name', function() {
|
2016-05-25 21:03:07 +01:00
|
|
|
it('should receive a 970px wide thumbnail of the image', function() {
|
2015-07-09 23:01:43 +01:00
|
|
|
request
|
|
|
|
.get('/file/970/' + file.id + '/' + file.name)
|
|
|
|
.expect(200)
|
|
|
|
.expect('Content-type', 'image/jpeg')
|
|
|
|
.expect(function(response) {
|
2016-05-25 21:03:07 +01:00
|
|
|
const width = sizeOf(response.body).width;
|
|
|
|
assert(width === 970);
|
|
|
|
});
|
2015-07-09 23:01:43 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when GET /:id', function() {
|
2016-05-25 21:03:07 +01:00
|
|
|
it('should receive some HTML', function() {
|
2015-07-09 23:01:43 +01:00
|
|
|
request
|
|
|
|
.get('/' + file.id)
|
|
|
|
.expect(200)
|
|
|
|
.expect('Content-type', /text\/html/) // Could include charset
|
|
|
|
.expect(function(response) {
|
|
|
|
assert(response.text.indexOf('src="/file/970/' + file.id + '/' + file.name + '"') > -1);
|
2016-05-25 21:03:07 +01:00
|
|
|
});
|
2015-07-09 23:01:43 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when GET /file/:badid/:name', function() {
|
|
|
|
it('should receive 404 and some HTML', function(done) {
|
|
|
|
request
|
|
|
|
.get('/notarealid')
|
|
|
|
.expect(404)
|
|
|
|
.expect('Content-type', /text\/html/) // Could include charset
|
|
|
|
.end(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when GET /:bad-id', function() {
|
|
|
|
it('should receive 404 and some HTML', function(done) {
|
|
|
|
request
|
|
|
|
.get('/file/notarealid/orname')
|
|
|
|
.expect(404)
|
|
|
|
.expect('Content-type', /text\/html/) // Could include charset
|
|
|
|
.end(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|