import { getGrpcClientAsync } from 'killrvideo-nodejs-common';
import { USER_MANAGEMENT_SERVICE } from '../services/user-management';

/**
 * Adds a sample user.
 */
export function addSampleUser() {
  return getGrpcClientAsync(USER_MANAGEMENT_SERVICE)
    .then(client => {
      throw new Error('Not implemented');
    });
};

export default addSampleUser;
import uuid from 'uuid';
import { internet, name, random } from 'faker';
import { getGrpcClientAsync } from 'killrvideo-nodejs-common';
import { USER_MANAGEMENT_SERVICE } from '../services/user-management';
import { stringToUuid } from '../utils/protobuf-conversions';
import { getCassandraClient } from '../utils/cassandra';

/**
 * Adds a sample user.
 */
export async function addSampleUser() {
  // Generate a user and add using Grpc service
  let client = await getGrpcClientAsync(USER_MANAGEMENT_SERVICE);

  let userId = uuid.v4();
  let firstName = name.firstName();
  let lastName = name.lastName();
  let request = {
    userId: stringToUuid(userId),
    firstName,
    lastName,
    password: internet.password(random.number({ min: 7, max: 20 })),
    email: internet.exampleEmail(firstName, lastName)
  };
  await client.createUserAsync(request);

  // Save the User's Id so we can use it in other sample data
  let cass = getCassandraClient();
  await cass.executeAsync('INSERT INTO users (userid) VALUES (?)', [ userId ]);
};

export default addSampleUser;
Add sample user impl