diff options
| author | Kieu Anh Tuan <[email protected]> | 2014-01-07 17:03:03 +0100 |
|---|---|---|
| committer | Kieu Anh Tuan <[email protected]> | 2014-01-07 17:11:31 +0100 |
| commit | 41688effa91319121a7fe8a981c4a7ebb986339b (patch) | |
| tree | 57296829cca4b3bef922858c50378094895ae251 | |
| parent | 1bd1d73d29222c4e2f52d63a4282345b63a324df (diff) | |
| download | faker-41688effa91319121a7fe8a981c4a7ebb986339b.tar.xz faker-41688effa91319121a7fe8a981c4a7ebb986339b.zip | |
Add support to lorempixel image provider
| -rw-r--r-- | index.js | 1 | ||||
| -rw-r--r-- | lib/image.js | 56 | ||||
| -rw-r--r-- | test/image.unit.js | 35 |
3 files changed, 92 insertions, 0 deletions
@@ -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'); diff --git a/lib/image.js b/lib/image.js new file mode 100644 index 00000000..0456dd84 --- /dev/null +++ b/lib/image.js @@ -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; diff --git a/test/image.unit.js b/test/image.unit.js new file mode 100644 index 00000000..005f15f7 --- /dev/null +++ b/test/image.unit.js @@ -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'); + }); + }); +}); |
