import * as shortid from 'shortid'; import * as _ from 'lodash'; import { Constants } from './constants'; import { Models } from './models'; export namespace Mockers { export function mockUser(options: { _id?: string, role?: Models.UserRoles, email?: string, password?: string, saved_plays?: Models.IIdTime[], streams_following?: Models.IIdTime[], channel_stream?: string, player_stream?: string } = {}): Models.IUser { let user: Models.IUser = { _id: options._id || shortid.generate(), role: options.role || Models.UserRoles.User, email: options.email || 'mock@gmail.com', hashed_password: options.password || 'mock-password', user_name: 'mock-username', join_date: new Date().toISOString(), saved_plays: options.saved_plays || [], streams_following: options.streams_following || [], device_ids: [] }; if (!_.isEmpty(options.channel_stream)) { user.channel_stream = options.channel_stream; } if (!_.isEmpty(options.player_stream)) { user.player_stream = options.player_stream; } return user; } export function mockPlay(options: { _id?: string, uploader_id?: string, released_at?: Models.ISOString, streams?: string[] } = {}): Models.IPlay { return { _id: options._id || shortid.generate(), caption: 'Mock Play title...', uploader_id: options.uploader_id || shortid.generate(), released_at: options.released_at || new Date().toISOString(), thumbnail_url: 'some-url', source_video_url: 'some-url', encoded_video_url: 'some-url', blurred_thumbnail_url: 'some-url', streams: options.streams || [] }; } export function mockPlayDTO(options: { _id?: string, uploader_id?: string, released_at?: Models.ISOString, streams?: string[], num_comments?: number, avg_comm_rating?: number } = {}): Models.IPlayDTO { return _.assign(mockPlay(options), { num_ratings: _.random(0, 30), num_comments: _.random(0, 20), avg_comm_rating: _.random(4, 10) }); } export function mockUserReg(options: { user_name?: string, email?: string, password?: string } = {}): Models.IUserRegistration { return { user_name: options.user_name || 'some-user-name', email: options.email || 'mock@gmail.com', password: options.password || 'mock-password' }; } export function mockUserCreds(options: { email?: string, password?: string } = {}): Models.IUserCredentials { return { email: options.email || 'mock@gmail.com', password: options.password || 'mock-password' }; } export function mockRating(options: { _id?: string; time?: Models.ISOString; play_id?: string; user_id?: string; value?: number; } = {}): Models.IRating { return { _id: options._id || shortid.generate(), time: options.time || new Date().toISOString(), play_id: options.play_id || shortid.generate(), user_id: options.user_id || shortid.generate(), value: options.value || _.random(1, 10) }; } export function mockIdTime(options: { id?: string, time?: string } = {}): Models.IIdTime { return { id: options.id || shortid.generate(), time: options.time || new Date().toISOString() }; } export function mockComment(options: { _id?: string; user_id?: string; play_id?: string; text?: string; time?: Models.ISOString; likes?: Models.IIdTime[]; parent?: string; } = {}): Models.IComment { let comment: Models.IComment = { _id: options._id || shortid.generate(), user_rating: 8, user_name: 'mock-username', user_id: options.user_id || shortid.generate(), play_id: options.play_id || shortid.generate(), text: options.text || 'some mock comment text...', time: options.time || new Date().toISOString(), likes: (!!options.likes && options.likes.length > 0) ? options.likes : [] }; // dont want to store comment.parent = undefined in mongo // which happens if you do 'parent: options.parent' above. if (options.parent) { comment.parent = options.parent; } return comment; } export function mockStream(options: { _id?: string; type?: Models.StreamTypes; is_suggestion?: boolean; } = {}): Models.IStream { return { _id: options._id || shortid.generate(), type: _.isUndefined(options.type) ? Models.StreamTypes.Mainstream : options.type, name: 'mock-name', photo_url: 'mock-url', is_suggestion: _.isBoolean(options.is_suggestion) && options.is_suggestion }; } export function mockPlayerStream(options: { _id?: string; } = {}): Models.IStream { return { _id: options._id || shortid.generate(), type: Models.StreamTypes.Player, photo_url: 'http://some-url', name: 'Mock Player Stream', player_info: { height: _.sample(Constants.VALID_HEIGHTS_IN) as number, weight: _.sample(Constants.VALID_WEIGHTS_LB) as number, school_name: 'Mock School name', position: _.sample(Constants.PLAYER_POSITIONS) as string, grad_year: _.sample(Constants.PLAYER_GRAD_YEARS) as number, city: 'San Diego', state: _.sample(_.map(Constants.VALID_STATES, 'abbr')) as string }, is_suggestion: false }; } export function mockChannelStream(options: { _id?: string; } = {}): Models.IStream { return { _id: options._id || shortid.generate(), type: Models.StreamTypes.Channel, photo_url: 'http://some-url', name: 'Mock Channel Stream', channel_info: { owner: 'Mock owner', description: 'mock description', youtube_link: 'https://www.youtube.com/user/Arizonasfinestmixtap' }, is_suggestion: false }; } }