Esempio n. 1
0
        it('faker should success', function(done) {
            
            var firstName = Faker.Name.firstName();
            console.log(firstName);
            
            var userName = Faker.Internet.userName();
            console.log(userName);

            var color1 = Faker.Internet.color(1);
            console.log(color1);

            var companyName = Faker.Company.companyName();
            console.log(companyName);

            var recent = Faker.Date.recent(10);
            console.log(recent);

            var past = Faker.Date.past(1);
            console.log(past);

            var number = Faker.random.number(110);
            console.log(number);

            done();
        });
Esempio n. 2
0
    app.get('/faker/date', function (req, res) {
        var fakerDateDetails = {
            past: Faker.Date.past(),
            future: Faker.Date.future(),
            between: Faker.Date.between(),
            recent: Faker.Date.recent()
        };

        res.json(fakerDateDetails);
    });
Esempio n. 3
0
var sessions = _.times(100, function(index) {

    // Fetch 1-4 random speakers

    var sessionSpeakers = _.times(_.random(1, 4), function() {
        return Faker.random.array_element(speakers);
    });

    return {
        id: index + 1,
        title: Faker.Lorem.sentence(3),
        thumbnail:Faker.random.array_element(youtubeVideos),
        summery: Faker.Lorem.sentence(10),
        detail: Faker.Lorem.paragraphs(4),
        topics: _.unique(_.times(_.random(7, 17), function() {
            return Faker.random.array_element(topics);
        })),
        date: Faker.Date.recent(300),
        attendees: {
            confirmed: Faker.random.number(80),
            tentative: Faker.random.number(80)
        },
        speakers: _.map(sessionSpeakers, function(speaker) {
            return {
                id: speaker.id,
                name: speaker.name,
                avatar: speaker.avatar
            }
        }),

        comments: _.times(_.random(1, 5), function() {
            var commenter = Faker.random.array_element(speakers);
            return {
                id: commenter.id,
                name: commenter.name,
                avatar: commenter.avatar,
                comment: Faker.Lorem.sentence(20)
            }
        })


    }
});
  mentions: function (count) {
    count = count || 4;

    var mentions = [], i, author;

    for (i = 0; i < count; i++) {
      author = !i || faker.random.number(4);
      mentions.push({
        author: {
          name: author ? faker.Name.findName() : null,
          photo: (!i || (author && faker.random.number(2))) ? faker.Image.avatar() : null,
          url: (!i || (author && faker.random.number(3))) ? 'http://' + faker.Internet.domainName() + '/' : null
        },
        name: (!i || faker.random.number(6)) ? null : faker.Lorem.words(1 + faker.random.number(4)).join(' '),
        published: new Date(faker.Date.recent(30)).getTime(),
        summary: faker.Lorem.paragraph(),
        url: 'http://' + faker.Internet.domainName() + '/' + faker.Lorem.words(1 + faker.random.number(4)).join('/')
      });
    }

    return mentions;
  }
Esempio n. 5
0
  {
    _id: 'p2a',
    consent: true,
    name: 'p2'
  },
  {
    _id: 'p3a',
    consent: true,
    name: 'p3'
  }
]

var testMeeting = {
  _id: 'turn-job-meeting-0',
  participants: ['p1a', 'p2a', 'p3a'],
  startTime: Faker.Date.recent(),
  active: true
}

var testUtterances = [
  { meeting: testMeeting._id,
    participant: testMeeting.participants[0],
    startTime: new Date(startTime),
    endTime: new Date(startTime + 1 * 50),
    volumes: _(10).times((n) => { return { 'timestamp': '1', 'vol': Faker.Helpers.randomNumber(5) } })
  },
  { meeting: testMeeting._id,
    participant: testMeeting.participants[0],
    startTime: new Date(startTime + 2 * 50),
    endTime: new Date(startTime + 3 * 50),
    volumes: _(10).times((n) => { return { 'timestamp': '1', 'vol': Faker.Helpers.randomNumber(5) } })
 fakery.generator('date', function (future) {
   return future ? Faker.Date.future(0) : Faker.Date.past(0);
 });
Esempio n. 7
0
 (function(){return Faker.Date.future(2016)}()),
Esempio n. 8
0
 (function(){return Faker.Date.past(2016)}()),
Esempio n. 9
0
function _valueForKeyInDictionary(key, dictionary) {
	if (typeof dictionary[key] === "string") {
		var value = undefined;
		switch(dictionary[key]) {

			// Basic
			case "Number":
				value = Math.random()*Number.MAX_VALUE;
				break;
			case "-Number":
				value = (Math.random()*Number.MAX_VALUE) * -1;
				break;
			case "?Number":
				value = (Math.random()*Number.MAX_VALUE) * (Math.random() < 0.5 ? -1 : 1);
				break;
			case "Integer" :
				value = Math.round(Math.random()*Number.MAX_VALUE);
				break;
			case "-Integer" :
				value = Math.round(Math.random()*Number.MAX_VALUE) * -1;
				break;
			case "?Integer" :
				value = Math.round(Math.random()*Number.MAX_VALUE) * (Math.random() < 0.5 ? -1 : 1);
				break;
			case "Boolean":
				value = chance.bool();
				break;
			case "Character":
				value = chance.character();
				break;

			// Text
			case "Word":
				value = chance.word();
				break;
			case "Words":
				value = faker.Lorem.words();
				break;
			case "Sentence":
				value = faker.Lorem.sentence();
				break;
			case "Sentences":
				// chance doesnt have sentences, its the same as a paragraph essentially
				value = lorem({
					count : 2 + Math.round(Math.random()*5),
					units : "sentences",
					format : "plain"
				});
				break;
			case "Paragraph":
				value = chance.paragraph();
				break;
			case "Paragraphs":
				// Keep using lorem because it includes line breaks
				value = lorem({
					count : Math.round(Math.random()*5),
					units : "paragraphs",
					format : "plain"
				});
				break;

			// Finance
			case "Dollar":
				value = chance.dollar();
				break;
			case "CreditCardNumber":
				value = chance.cc();
				break;
			case "CreditCardType":
				value = chance.cc_type();
				break;
			case "CreditCardExpiration":
				value = chance.exp();
				break;
			case "CreditCardExpirationMonth":
				value = chance.exp_month();
				break;
			case "CreditCardExpirationYear":
				value = chance.exp_year();
				break;

			// Person
			case "Name":
				value = chance.name();
				break;
			case "FirstName":
				value = chance.first();
				break;
			case "LastName":
				value = chance.last();
				break;
			case "Gender":
				value = chance.gender();
				break;
			case "Birthday":
				value = chance.birthday();
				break;
			case "Age":
				value = chance.age();
				break;

			// Personal info
			case "Address":
				value = chance.address();
				break;
			case "Zip":
				value = chance.zip();
				break;
			case "City":
				value = chance.city();
				break;
			case "Street":
				value = chance.street();
				break;
			case "State":
				value = chance.state();
				break;
			case "LongState":
				value = chance.state({full: true});
				break;
			case "Coordinates":
				value = chance.coordinates();
				break;
			case "Latitude":
				value = chance.latitude();
				break;
			case "Longitude":
				value = chance.longitude();
				break;
			case "AreaCode":
				value = chance.areacode();
				break;
			case "Phone":
				value = chance.phone();
				break;
			case "Email":
				value = chance.email();
				break;
			case "Company":
				value = faker.Company.companyName();
				break;

			// Internet
			case "Username":
				value = faker.Internet.userName();
				break;
			case "Domain":
				value = chance.domain();
				break;
			case "TLD":
				value = chance.tld();
				break;
			case "IP":
				value = chance.ip();
				break;
			case "IPv6":
				value = chance.ipv6();
				break;
			case "Avatar":
				value = faker.Image.avatar();
				break;
			case "Image":
				value = "http://instasrc.com/"+Math.round(400+(Math.random()*100))+"x"+Math.round(400+(Math.random()*100));
				break;
			case "FacebookID":
				value = chance.fbid();
				break;
			case "TwitterHandle":
				value = chance.twitter();
				break;
			case "Hashtag":
				value = chance.hashtag();
				break;

			// Color
			case "HexColor":
				value = chance.color({format: "hex"});
				break;
			case "RGBColor":
				value = chance.color({format: "rgb"});
				break;

			
			// Dates
			case "-Date":
				value = faker.Date.past(1 + Math.round(Math.random()*100));
				break;
			case "Date":
				value = new Date();
				break;
			case "+Date":
				value = faker.Date.future(1 + Math.round(Math.random()*100));
				break;
			case "?Date":
				if (Math.random() < 0.5) {
					value = faker.Date.past(1 + Math.round(Math.random()*100));
				} else {
					value = faker.Date.future(1 + Math.round(Math.random()*100));
				}
				break;
			case "Day":
				value = moment().dayOfYear();
				break;
			case "Month":
				value = chance.month();
				break;
			case "Year":
				value = chance.year();
				break;
			
			// Other
			case "Hash":
				value = chance.hash({length:25});
				break;
			case "GUID":
				value = chance.guid();
				break;

			default:
				value = "Undefined data type.";
				break;
		}
		return value;
	} else if (typeof dictionary[key] === "object") {
		if (Array.isArray(dictionary[key])) {
			if (dictionary[key].length < 1) {
				return [];
			}
			var subdictionary = dictionary[key][0];
			var count = dictionary[key][1] ? dictionary[key][1] : (1 + Math.round(Math.random()*10));

			var data = [];
			var subdictionary = JSON.parse(JSON.stringify(subdictionary));
			for (var i=0; i<count; i++) {
				var newDict = {};
				for (var subkey in subdictionary) {
					newDict[subkey] = _valueForKeyInDictionary(subkey, subdictionary);
				}
				data.push(newDict);
			}
			return data;
		} else {
			var value = {};
			for (var subkey in dictionary[key]) {
				value[subkey] = _valueForKeyInDictionary(subkey, dictionary[key]);
			}
			return value;
		}

	}
}