Created
October 23, 2015 20:52
-
-
Save polerin/10148c3e1aebced61565 to your computer and use it in GitHub Desktop.
Generate fake users for Parse.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
/** | |
* This assumes emails.js is something like | |
* modules.export = ["[email protected]", "[email protected]",...]; | |
* | |
* | |
* @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