create-sample-users

1.1.0 • Public • Published

Generate Sample Users

Overview

This was written to generate sample "user" fixture data for a project where Users author Posts and make Comments on Posts authored by other Users. Any User can become a Follower of another User, and that relationship is noted both in the data associated with the Follower and the User being Followed.

This is presently hard-coded to get input from the file /tmp/generated-users.json, with data generated by https://randomuser.me/ using code equivalent to the following:

var fs = require('fs');
var SyncRequest = require('sync-request');
url = 'https://randomuser.me/api/?format=pretty&inc=email,login,registered,picture&nat=au,br,ca,ch,de,dk,es,fi,fr,gb,ie,nl,nz,us&results=100&seed=7c93110b8c5d4c87'
resp = SyncRequest('GET', url);
data = resp.getBody().toString();
fs.writeSync(1, data);

To write fully-formed user data to, e.g., /tmp/users.json, from this project's project root, run the following:

$ node demoCreateSampleUsers.js > /tmp/users.json

It's Not as Simple As It Looks

First, notice that all IDs (for users, comments, posts) are UUIDs. Each following and follower user ID matches an actual id property of a different, unique user. Getting that right took a downright embarrassing amount of flail.

Future Enhancements

Rather than rely on input provided by a separate script, It Would Be Very Nice If this package incorporated the data-generation code, becoming far more self-contained in the process. It Would Also Be Very Nice If, when doing so, the randomisation seed fed to randomuser.me could be specified, making the generated data repeatable. This would in turn be highly useful for, e.g., CI.

By default, we generate 99 users using the randomuser.me script. Ideally, this should also be configurable.

Legalities

Copyright © 2017 by Jeff Dickey, and made freely available under the MIT License.

Participants in this project agree to uphold and be bound by the Contributor Covenant 1.4 Version 1.4 or any later version.

Readme

Keywords

none

Package Sidebar

Install

npm i create-sample-users

Weekly Downloads

2

Version

1.1.0

License

MIT

Last publish

Collaborators

  • jdickey