Skip to content

Commit

Permalink
Add support to lorempixel image provider
Browse files Browse the repository at this point in the history
  • Loading branch information
passkey1510 committed Jan 7, 2014
1 parent 1bd1d73 commit 41688ef
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ exports.Address = require('./lib/address');
exports.PhoneNumber = require('./lib/phone_number');
exports.Internet = require('./lib/internet');
exports.Company = require('./lib/company');
exports.Image = require('./lib/image');
exports.Lorem = require('./lib/lorem');
exports.Helpers = require('./lib/helpers');
exports.random = require('./lib/random');
Expand Down
56 changes: 56 additions & 0 deletions lib/image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
var Faker = require('../index');
var imageProviderUrl = 'http://lorempixel.com/';
var image = {
imageUrl: function (width, height, category) {
var width = width || 640;
var height = height || 480;

var url = imageProviderUrl + width + '/' + height;
if (typeof category !== 'undefined') {
url += '/' + category;
}

return url;
},
abstract: function (width, height) {
return image.imageUrl(width, height, 'abstract');
},
animals: function(width, height) {
return image.imageUrl(width, height, 'animals');
},
business: function(width, height) {
return image.imageUrl(width, height, 'business');
},
cats: function(width, height) {
return image.imageUrl(width, height, 'cats');
},
city: function(width, height) {
return image.imageUrl(width, height, 'city');
},
food: function(width, height) {
return image.imageUrl(width, height, 'food');
},
nightlife: function(width, height) {
return image.imageUrl(width, height, 'nightlife');
},
fashion: function(width, height) {
return image.imageUrl(width, height, 'fashion');
},
people: function(width, height) {
return image.imageUrl(width, height, 'people');
},
nature: function(width, height) {
return image.imageUrl(width, height, 'nature');
},
sports: function(width, height) {
return image.imageUrl(width, height, 'sports');
},
technics: function(width, height) {
return image.imageUrl(width, height, 'technics');
},
transport: function(width, height) {
return image.imageUrl(width, height, 'transport');
}
};

module.exports = image;
35 changes: 35 additions & 0 deletions test/image.unit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
if (typeof module !== 'undefined') {
var assert = require('assert');
var sinon = require('sinon');
var Faker = require('../index');
}

describe("image.js", function () {
describe("imageUrl()", function () {
it("returns a random image url from lorempixel", function () {
var imageUrl = Faker.Image.imageUrl();

assert.equal(imageUrl, 'http://lorempixel.com/640/480');
});
it("returns a random image url from lorempixel with width and height", function () {
var imageUrl = Faker.Image.imageUrl(100, 100);

assert.equal(imageUrl, 'http://lorempixel.com/100/100');
});
it("returns a random image url in a abstract category", function () {
var imageUrl = Faker.Image.imageUrl(100, 100, 'abstract');

assert.equal(imageUrl, 'http://lorempixel.com/100/100/abstract');
});
it("returns a random image url in a category via proxy methods", function () {
var nightlife = Faker.Image.nightlife();
assert.equal(nightlife, 'http://lorempixel.com/640/480/nightlife');

var city = Faker.Image.city();
assert.equal(city, 'http://lorempixel.com/640/480/city');

var fashion = Faker.Image.fashion();
assert.equal(fashion, 'http://lorempixel.com/640/480/fashion');
});
});
});

0 comments on commit 41688ef

Please sign in to comment.