is a function.
expect(ImageMagickCommand).to.be.an.instanceOf(Function);
assigns first param to #options.
var im = new ImageMagickCommand('first');
expect(im.options).to.equal('first');
assigns second param to #files.
var im = new ImageMagickCommand('first', 'second');
expect(im.files).to.equal('second');
assigns third param to #convertCmd.
var im = new ImageMagickCommand(
'first',
'second',
'convertCmd'
);
expect(im.convertCmd).to.equal('convertCmd');
assigns "convert" to #convertCmd if third param is missing .
var im = new ImageMagickCommand(
'first',
'second'
);
expect(im.convertCmd).to.equal('convert');
has a property gravityName.
var im = new ImageMagickCommand();
expect(im.gravityName).to.exist;
has a method buildDimensionString.
var im = new ImageMagickCommand();
expect(im.buildDimensionString).to.be.an.instanceOf(Function);
has a method buildActionString.
var im = new ImageMagickCommand();
expect(im.buildActionString).to.be.an.instanceOf(Function);
has a method buildCommandString.
var im = new ImageMagickCommand();
expect(im.buildCommandString).to.be.an.instanceOf(Function);
has properties tmp and cache.
var files = {
tmp: 'tmp',
cache: 'cache'
};
var im = new ImageMagickCommand('first', files);
expect(im.files.tmp).to.equal('tmp');
expect(im.files.cache).to.equal('cache');
returns a dimension string "200x400".
var options = {
width: '200',
height: '400'
};
var im = new ImageMagickCommand(options, 'second');
expect(im.buildDimensionString()).to.equal('200x400');
returns a string.
var im = new ImageMagickCommand('first', 'second');
expect(im.buildActionString()).to.be.a('string');
returns a string.
var im = new ImageMagickCommand(
'first',
'second'
);
expect(im.buildCommandString()).to.be.a('string');
is a function.
expect(RequestSplitter).to.be.an.instanceOf(Function);
has a url property.
var rs = new RequestSplitter();
expect(rs.url).to.exist;
has a query property.
var rs = new RequestSplitter();
expect(rs.query).to.exist;
assigns first param to #url.
var rs = new RequestSplitter('first');
expect(rs.url).to.equal('first');
assigns second param to #query.
var rs = new RequestSplitter('first', 'second');
expect(rs.query).to.equal('second');
has a urlMatch property.
var rs = new RequestSplitter();
expect(rs.urlMatch).to.exist;
has a mapOptions() method.
var rs = new RequestSplitter();
expect(rs.mapOptions).to.be.an.instanceOf(Function);
is a regular expression.
var rs = new RequestSplitter();
expect(rs.urlMatch).to.be.instanceOf(RegExp);
matches "/c200x200n/jpg,75/http://trakt.us/images/posters/892.jpg".
var rs = new RequestSplitter();
var url = '/c200x200n/jpg,75/http://trakt.us/images/posters/892.jpg';
var result = rs.urlMatch.test(url);
expect(result).to.equal(true);
treats leading slash as optional.
var rs = new RequestSplitter();
var url = 'c200x200n/jpg,75/http://trakt.us/images/posters/892.jpg';
var result = rs.urlMatch.test(url);
expect(result).to.equal(true);
returns an options map.
var url = 'c200x400n/jpg,75/http://trakt.us/images/posters/892.jpg';
var query = {
demo: 'asd asd'
};
var rs = new RequestSplitter(url, query);
var options = rs.mapOptions();
expect(options).to.exist;
expect(options.action).to.equal('crop');
expect(options.width).to.equal('200');
expect(options.height).to.equal('400');
expect(options.gravity).to.equal('n');
expect(options.format).to.equal('jpg');
expect(options.quality).to.equal('75');
expect(options.imagefile).to.equal(
'http://trakt.us/images/posters/892.jpg'
);
expect(options.url).to.equal(
'http://trakt.us/images/posters/892.jpg?demo=asd%20asd'
);
expect(options.suffix).to.equal('.jpg');
is a function.
expect(ResizeJob).to.be.an.instanceOf(Function);
has a method generateCacheFilename.
var rj = new ResizeJob();
expect(rj.generateCacheFilename).to.be.an.instanceOf(Function);
has a method isAlreadyCached.
var rj = new ResizeJob();
expect(rj.isAlreadyCached).to.be.an.instanceOf(Function);
has a method validateRemoteSource.
var rj = new ResizeJob();
expect(rj.validateRemoteSource).to.be.an.instanceOf(Function);
has a method downloadRemoteImage.
var rj = new ResizeJob();
expect(rj.downloadRemoteImage).to.be.an.instanceOf(Function);
has a method convertImage.
var rj = new ResizeJob();
expect(rj.convertImage).to.be.an.instanceOf(Function);
returns a string.
var options = {
imagefile: 'teststring',
suffix: '.jpg'
};
var rj = new ResizeJob(options);
expect(rj.generateCacheFilename()).to.be.a('string');
returns correct shasum of options + suffix.
var options = {
imagefile: 'teststring',
format: 'png',
suffix: '.jpg'
};
var rj = new ResizeJob(options);
var shasum = crypto.createHash('sha1');
shasum.update(JSON.stringify(options));
var cache = shasum.digest('hex') + '.' + options.format;
expect(rj.generateCacheFilename()).to.equal(cache);
returns a boolean.
var options = {
imagefile: 'teststring',
suffix: '.jpg'
};
var filename = 'resize.js';
var rj = new ResizeJob(options);
rj.isAlreadyCached(filename, function (result) {
if (typeof result === 'boolean') {
done();
} else {
throw new Error('returned ' + typeof result);
}
});
returns false if file does not exists.
var options = {
imagefile: 'teststring',
suffix: '.jpg'
};
var filename = 'xxx.yy';
var rj = new ResizeJob(options);
rj.isAlreadyCached(filename, function (result) {
if (! result) {
done();
} else {
throw new Error('returned ' + result);
}
});
returns true if file does exists.
var options = {
imagefile: 'teststring',
suffix: '.jpg'
};
var filename = __filename;
var rj = new ResizeJob(options);
rj.isAlreadyCached(filename, function (result) {
if (result) {
done();
} else {
throw new Error('returned ' + result);
}
});
returns a boolean.
var options = {
url: ''
};
var rj = new ResizeJob(options, function () {});
expect(rj.validateRemoteSource()).to.be.a('boolean');
returns false on invalid #options.url.
var options = {
url: 'domain.com/path/image.jog'
};
var rj = new ResizeJob(options, function () {});
expect(rj.validateRemoteSource()).to.equal(false);
returns true on valid #options.url.
var options = {
url: 'http://domain.com/path/image.jog'
};
var rj = new ResizeJob(options, function () {});
expect(rj.validateRemoteSource()).to.equal(true);