Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
describe('methods', () => {
const userId = Random.id();
let taskId;
beforeEach(() => {
Tasks.remove({});
taskId = Tasks.insert({
text: 'test task',
createdAt: new Date(),
owner: userId,
username: 'tmeasday',
});
});
it('can delete owned task', () => {
// Find the internal implementation of the task method so we can
// test it in isolation
const deleteTask = Meteor.server.method_handlers['tasks.remove'];
export function convertAdLibToPiece (adLibPiece: AdLibPiece | Piece, part: Part, queue: boolean): Piece {
let duration: number | string | undefined = undefined
if (adLibPiece['expectedDuration']) {
duration = adLibPiece['expectedDuration']
} else if (adLibPiece['enable'] && adLibPiece['enable'].duration) {
duration = adLibPiece['enable'].duration
}
const newId = Random.id()
const newPiece = literal({
..._.omit(adLibPiece, '_rank', 'expectedDuration', 'startedPlayback', 'stoppedPlayback'), // TODO - this could be typed stronger
_id: newId,
enable: {
start: (queue ? 0 : 'now'),
duration: duration
},
partId: part._id,
adLibSourceId: adLibPiece._id,
dynamicallyInserted: !queue,
// expectedDuration: adLibPiece.expectedDuration || 0, // set duration to infinite if not set by AdLibItem
timings: {
take: [getCurrentTime()],
startedPlayback: [],
next: [],
stoppedPlayback: [],
Meteor.runAsUser(startedByUserId, () => {
const existantUser = Users.findOneByEmailAddress(u.email) || Users.findOneByUsername(u.username);
let userId;
if (existantUser) {
// since we have an existing user, let's try a few things
userId = existantUser._id;
u.rocketId = existantUser._id;
Users.update({ _id: u.rocketId }, { $addToSet: { importIds: u.id } });
Users.setEmail(existantUser._id, u.email);
Users.setEmailVerified(existantUser._id, u.email);
} else {
userId = Accounts.createUser({ username: u.username + Random.id(), password: Date.now() + u.name + u.email.toUpperCase() });
if (!userId) {
console.warn('An error happened while creating a user.');
return;
}
Meteor.runAsUser(userId, () => {
Meteor.call('setUsername', u.username, { joinDefaultChannelsSilenced: true });
Users.setName(userId, u.name);
Users.update({ _id: userId }, { $addToSet: { importIds: u.id } });
Users.setEmail(userId, u.email);
Users.setEmailVerified(userId, u.email);
u.rocketId = userId;
});
}
const room = param.trim();
const user = Meteor.user();
// if there is not a param, hide the current room
let { rid } = item;
if (room !== '') {
const [strippedRoom] = room.replace(/#|@/, '').split(' ');
const [type] = room;
const roomObject = type === '#' ? Rooms.findOneByName(strippedRoom) : Rooms.findOne({
t: 'd',
usernames: { $all: [user.username, strippedRoom] },
});
if (!roomObject) {
return Notifications.notifyUser(user._id, 'message', {
_id: Random.id(),
rid: item.rid,
ts: new Date,
msg: TAPi18n.__('Channel_doesnt_exist', {
postProcess: 'sprintf',
sprintf: [room],
}, user.language),
});
}
if (!Subscriptions.findOneByRoomIdAndUserId(room._id, user._id, { fields: { _id: 1 } })) {
return Notifications.notifyUser(user._id, 'message', {
_id: Random.id(),
rid: item.rid,
ts: new Date,
msg: TAPi18n.__('error-logged-user-not-in-room', {
postProcess: 'sprintf',
Tinytest.addAsync('Cursor', function (test, done) {
var quotes = new Mongo.Collection(Random.id()),
publish = Random.id(),
docs = data.quotes;
for (var doc in docs) {
quotes.insert(docs[doc]);
};
PublishRelations(publish, function () {
this.cursor(quotes.find());
});
var client = Client();
client._livedata_data = function (msg) {
if (msg.msg == 'added') {
test.equal(msg.fields, quotes.findOne({_id: msg.id}, {fields: {_id: 0}}));
} else if (msg.msg == 'ready') {
client.disconnect();
function assertListAndTodoArePrivate() {
assert.equal(Lists.findOne(listId).userId, userId);
assert.isTrue(Lists.findOne(listId).isPrivate());
assert.isTrue(Todos.findOne(todoId).editableBy(userId));
assert.isFalse(Todos.findOne(todoId).editableBy(Random.id()));
}
function createSystemSnapshot (studioId: string | null): SystemSnapshot {
let snapshotId = Random.id()
logger.info(`Generating System snapshot "${snapshotId}"` + (studioId ? `for studio "${studioId}"` : ''))
const coreSystem = getCoreSystem()
if (!coreSystem) throw new Meteor.Error(500, `coreSystem not set up`)
const studios = Studios.find((studioId ? { _id: studioId } : {})).fetch()
let queryShowStyleBases: MongoSelector = {}
let queryShowStyleVariants: MongoSelector = {}
let queryRundownLayouts: MongoSelector = {}
let queryDevices: MongoSelector = {}
let queryBlueprints: MongoSelector = {}
if (studioId) {
let showStyleBaseIds: string[] = []
_.each(studios, (studio) => {
showStyleBaseIds = showStyleBaseIds.concat(studio.supportedShowStyleBase)
function createDebugSnapshot (studioId: string): DebugSnapshot {
let snapshotId = Random.id()
logger.info(`Generating Debug snapshot "${snapshotId}" for studio "${studioId}"`)
const studio = Studios.findOne(studioId)
if (!studio) throw new Meteor.Error(404,`Studio ${studioId} not found`)
let systemSnapshot = createSystemSnapshot(studioId)
let activeROs = Rundowns.find({
studioId: studio._id,
active: true,
}).fetch()
let activeRundownSnapshots = _.map(activeROs, (rundown) => {
return createRundownSnapshot(rundown._id)
})
function addReport (suiteId, name, ...args) {
const _id = Random.id();
const rawReport = {
_id,
name,
suiteId,
args,
index: reports.length,
};
reports.push(rawReport);
listeners.forEach(listener => {
listener(rawReport);
});
}
user_id: Random.id(),
user_name: 'rocket.cat',
text: 'Sample text 1',
trigger_word: 'Sample',
}, {
token: Random.id(24),
channel_id: Random.id(),
channel_name: 'general',
timestamp: new Date(),
user_id: Random.id(),
user_name: 'rocket.cat',
text: 'Sample text 2',
trigger_word: 'Sample',
}, {
token: Random.id(24),
channel_id: Random.id(),
channel_name: 'general',
timestamp: new Date(),
user_id: Random.id(),
user_name: 'rocket.cat',
text: 'Sample text 3',
trigger_word: 'Sample',
},
],
};
}