Skip to content

Instantly share code, notes, and snippets.

@polerin
Created October 23, 2015 20:52
Show Gist options
  • Save polerin/10148c3e1aebced61565 to your computer and use it in GitHub Desktop.
Save polerin/10148c3e1aebced61565 to your computer and use it in GitHub Desktop.
Generate fake users for Parse.
"use strict";
/**
* This assumes emails.js is something like
* modules.export = ["email1@whdfafdasdf.no", "email2@whdasdfasdf.never",...];
*
*
* @param request
* @param status
*/
exports.generateFakeUserData = function (request, status) {
var emails = require('cloud/data/emails.js');
var userProcessCount = 0;
var promisesPromises = [];
var errors = false;
var errorsLog = [];
var startingPoint = 0;
var maxNew = 200;
var endingPoint = startingPoint + maxNew;
for (var i = startingPoint ; i < endingPoint; i++) {
promisesPromises.push(
//create a new user without assigning it to local var
(new Parse.User())
// set the actual values
.set("username", emails[i])
.set("password", emails[i] + emails[i-i])
.set("email", emails[i])
// Save them, return a promise to the array
.signUp(null,
{
"success": function () {
userProcessCount++;
},
"error": function (error) {
errors = true;
errorsLog.push(error);
}
})
);
}
console.log("saves set" + userProcessCount);
// When all the saves are set, pass it to the when() to check on completion
Parse.Promise.when(promisesPromises).then(
function() {
if (errors) {
console.log(errorsLog);
status.error('feo!');
}
status.success("Yup: " + userProcessCount);
},
function(error) {
console.log(error);
status.error("Nope");
}
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment