Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
before((done) => {
let adminProfileId = '';
User.findOne({
where: {
name: {
[Op.iLike]: OBAdminUser.name,
},
},
})
.then((OBAdminUser) => adminProfileId = OBAdminUser.profileId)
// create a normal user
.then(() => User.create({
profileId: profileOneId,
name: userZero,
email: userZero,
password: userZero,
}))
// create a normal user
.then(() => User.create({
profileId: profileOneId,
function whereClauseForUser(userNameOrId) {
const whr = {};
if (u.looksLikeId(userNameOrId)) {
/*
* need to use '$table.field$' for association fields. User IDs in the url
* are case-sensitve.
*/
whr.where = { '$user.id$': {} };
whr.where['$user.id$'] = userNameOrId;
} else {
whr.where = { '$user.name$': {} };
whr.where['$user.name$'][Op.iLike] = userNameOrId;
}
return whr;
} // whereClauseForUser
if (optsWhereOR && Array.isArray(optsWhereOR)) { // multiple values
let isWildCardExp = false;
optsWhereOR.forEach((orObj) => {
if (orObj[Op.iLike] &&
orObj[Op.iLike].indexOf('%') > MINUS_ONE) {
isWildCardExp = true;
}
});
if (!isWildCardExp) { // if no wildcard value, set limit to no. of values
opts.limit = optsWhereOR.length;
}
}
// single value
const optsWhereFieldLike = opts.where[uniqueFieldName][Op.iLike];
if (optsWhereFieldLike && optsWhereFieldLike.indexOf('%') < ZERO) {
opts.limit = 1; // set limit to 1 if no wildcard value
}
}
}
.then((samp) => {
const subjectName = samp.name.split('|')[0].toLowerCase();
return Subject.findOne({ where: { name: { [Op.iLike]: subjectName } } });
})
.then((sub) => {
.then((botData) => {
testBotData = botData;
return BotData.findOne({ where: { name: { [Op.iLike]: testBotData.name } } });
})
.then((rt) => rt.addWriters(user))
before((done) => {
Profile.findOne({
where: {
name: {
[Op.iLike]: conf.db.adminProfile.name,
},
},
})
.then((found) => {
ap = found;
done();
});
});
setTimeout(() => {
Sample.findOne({
where: {
name: {
[Op.iLike]: updatedSubjectName + '|' + aspectName,
},
},
})
.then((sample) => {
expect(sample).to.equal(null);
done();
});
}, 500);
})
.then(() => Sample.findAll({
where: {
name: {
[Op.iLike]: `${tu.namePrefix}Subject|%`,
},
},
})
.each((s) => {
switch (s.name) {
case `${tu.namePrefix}Subject|${tu.namePrefix}OneSecond`:
expect(s.status).to.equal(defaultForStatus);
break;
case `${tu.namePrefix}Subject|${tu.namePrefix}TwoMinutes`:
expect(s.status).to.equal(defaultForStatus);
break;
case `${tu.namePrefix}Subject|${tu.namePrefix}ThreeHours`:
expect(s.status).to.equal(defaultForStatus);
break;
case `${tu.namePrefix}Subject|${tu.namePrefix}NinetyDays`:
expect(s.status).to.not.equal(defaultForStatus);
export const createUser = (inputValues) => {
const email = inputValues.email.toLowerCase().trim();
const firstName = inputValues.firstName.trim();
const lastName = inputValues.lastName.trim();
const fullName = `${firstName} ${lastName}`;
const initials = `${firstName[0]}${lastName[0]}`;
const newSlug = slugifyString(fullName);
return User.count({
where: {
slug: { [Op.iLike]: `${newSlug}%` },
},
})
.then((existingSlugCount) => {
const newUser = {
slug: `${newSlug}${existingSlugCount ? `-${existingSlugCount + 1}` : ''}`,
firstName: firstName,
lastName: lastName,
fullName: fullName,
initials: initials,
email: email,
avatar: inputValues.avatar,
title: inputValues.title,
bio: inputValues.bio,
location: inputValues.location,
website: inputValues.website,
orcid: inputValues.orcid,
function initializeAdminUserAndProfile() {
const profileFinder = {
where: { name: { [Op.iLike]: conf.db.adminProfile.name } },
};
const userFinder = {
where: {
name: {
[Op.iLike]: conf.db.adminUser.name,
},
},
};
let pid;
return seq.models.Profile.upsert(conf.db.adminProfile)
.then(() => seq.models.Profile.findOne(profileFinder))
.then((profile) => {
pid = profile.id;
return seq.models.User.findOne(userFinder);
})
.then((u) => {