How to use describeErrors method in stryker-parent

Best JavaScript code snippet using stryker-parent

users.js

Source:users.js Github

copy

Full Screen

...5const NotFoundError = require('../errors/NotFoundError'); // 4046const UnauthorizedError = require('../errors/UnauthorizedError'); // 4017const ValidationError = require('../errors/ValidationError'); // 4008const SECRET_KEY = 'some-secret-key';9function describeErrors(err, res, next) {10 if (err.name === 'ValidationError' || err.name === 'CastError') {11 next(new ValidationError('Переданы некорректные данные'));12 } else {13 next(err);14 }15}16module.exports.login = (req, res, next) => {17 const { email, password } = req.body;18 User.findOne({ email }).select('+password') // вызвать метод select, так получаем хэш пароля19 .then((user) => {20 if (!user) { // пользователь не найден - отклоняем промис21 throw new UnauthorizedError('Неправильные почта или пароль');22 }23 return bcrypt.compare(password, user.password)24 .then((matched) => {25 if (!matched) { // хэши не совпали - отклоняем промис26 throw new UnauthorizedError('Неправильные почта или пароль');27 }28 return user;29 });30 })31 .then((user) => {32 const token = jwt.sign({ _id: user._id }, SECRET_KEY, { expiresIn: '7d' });33 res.cookie('jwt', token, { httpOnly: true, sameSite: true }).send({ message: 'Авторизация прошла успешно!' });34 })35 .catch((err) => next(err));36};37module.exports.createUser = (req, res, next) => { // создать пользователя38 const {39 name, about, avatar, email, password,40 } = req.body;41 bcrypt.hash(password, 10) // хешируем пароль42 .then((hash) => User.create({43 name, about, avatar, email, password: hash,44 })) // записываем данные в базу45 .then((user) => res.status(201).send({46 name: user.name,47 about: user.about,48 avatar: user.avatar,49 email: user.email,50 })) // возвращаем записанные данные в базу пользователю51 .catch((err) => {52 if (err.code === 11000) { // если пользователь регистрируется по существующему в базе email53 next(new ConflictError('Данный email уже существует'));54 } else {55 describeErrors(err, res, next);56 }57 });58};59module.exports.getUsers = (req, res, next) => {60 User.find({}) // поиск всех документов по параметрам61 .then((users) => res.status(200).send(users))62 .catch((err) => next(err));63};64module.exports.getInfoAboutMe = (req, res, next) => {65 User.findById(req.user._id) // находит текущего пользователя по _id66 .then((user) => {67 if (!user) {68 throw new NotFoundError('Пользователь по указанному Id не найден');69 } else {70 res.status(200).send(user);71 }72 })73 .catch((err) => describeErrors(err, res, next));74};75module.exports.getUserById = (req, res, next) => {76 User.findById(req.params.userId) // возвращает первого пользователя из базы по _id77 .then((user) => {78 if (!user) {79 throw new NotFoundError('Пользователь по указанному Id не найден');80 } else {81 res.status(200).send(user);82 }83 })84 .catch((err) => describeErrors(err, res, next));85};86module.exports.updateProfile = (req, res, next) => {87 const { name, about } = req.body;88 User.findByIdAndUpdate(89 req.user._id,90 { name, about },91 {92 new: true,93 runValidators: true,94 },95 )96 .then((user) => res.status(200).send(user))97 .catch((err) => describeErrors(err, res, next));98};99module.exports.updateAvatar = (req, res, next) => {100 const { avatar } = req.body;101 User.findByIdAndUpdate(102 req.user._id,103 { avatar },104 {105 new: true,106 runValidators: true,107 },108 )109 .then((user) => res.status(200).send(user))110 .catch((err) => describeErrors(err, res, next));...

Full Screen

Full Screen

cards.js

Source:cards.js Github

copy

Full Screen

1const Cards = require('../models/card');2const NotFoundError = require('../errors/NotFoundError');3const ForbiddenError = require('../errors/ForbiddenError');4const ValidationError = require('../errors/ValidationError');5function describeErrors(err, res, next) {6 if (err.name === 'ValidationError' || err.name === 'CastError') {7 next(new ValidationError('Переданы некорректные данные'));8 } else {9 next(err);10 }11}12function addError(req, res, card) {13 if (!card) {14 throw new NotFoundError('Карточка с указанным _id не найдена');15 } else {16 res.status(200).send(card);17 }18}19module.exports.createCard = (req, res, next) => {20 const { name, link } = req.body;21 const id = req.user._id; // id пользователя взяли из мидлвэры в файле app.js22 Cards.create({ name, link, owner: id })23 .then((card) => res.status(201).send({ card }))24 .catch((err) => describeErrors(err, res, next));25};26module.exports.getCards = (req, res, next) => {27 Cards.find({}) // поиск всех документов по параметрам28 .then((cards) => res.status(200).send(cards))29 .catch((err) => describeErrors(err, res, next));30};31module.exports.deleteCard = (req, res, next) => {32 Cards.findById(req.params.cardId) // удаление карточки по Id33 .then((card) => {34 if (!card) {35 throw new NotFoundError('Карточка с указанным _id не найдена');36 }37 if (req.user._id !== card.owner.toString()) { // нет прав удалять крточку другого пользователя38 throw new ForbiddenError('Вы не можете удалить эту карточку');39 }40 Cards.findByIdAndRemove(req.params.cardId)41 .then(() => res.status(200).send({ message: 'Карточка удалена' }))42 .catch(next);43 })44 .catch((err) => describeErrors(err, res, next));45};46module.exports.likeCard = (req, res, next) => {47 Cards.findByIdAndUpdate(48 (req.params.cardId),49 { $addToSet: { likes: req.user._id } }, // добавить _id в массив, если его там нет50 {51 new: true,52 },53 )54 .then((card) => {55 addError(req, res, card);56 })57 .catch((err) => describeErrors(err, res, next));58};59module.exports.dislikeCard = (req, res, next) => {60 Cards.findByIdAndUpdate( // удалит первое совпадение по id61 (req.params.cardId),62 { $pull: { likes: req.user._id } }, // убрать _id из массива63 {64 new: true,65 },66 )67 .then((card) => {68 addError(req, res, card);69 })70 .catch((err) => describeErrors(err, res, next));...

Full Screen

Full Screen

fancy_forms.js

Source:fancy_forms.js Github

copy

Full Screen

...35 });36 it('describes 0 errors', function () {37 $scope.val = 'someting';38 $scope.$apply();39 expect(ngForm.describeErrors()).to.be('0 Errors');40 });41 it('describes 0 error when the model is invalid but untouched', function () {42 $scope.$apply();43 expect(ngForm.describeErrors()).to.be('0 Errors');44 });45 it('describes 1 error when the model is touched', function () {46 $el.find('input').blur();47 $scope.$apply();48 expect(ngForm.describeErrors()).to.be('1 Error');49 });50 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { describeErrors } = require('stryker-parent');2describeErrors(() => {3 console.log('describeErrors');4});5const { describeErrors } = require('stryker-parent');6describeErrors(() => {7 console.log('describeErrors');8});9const { describeErrors } = require('stryker-parent');10describeErrors(() => {11 console.log('describeErrors');12});13const { describeErrors } = require('stryker-parent');14describeErrors(() => {15 console.log('describeErrors');16});17const { describeErrors } = require('stryker-parent');18describeErrors(() => {19 console.log('describeErrors');20});21const { describeErrors } = require('stryker-parent');22describeErrors(() => {23 console.log('describeErrors');24});25const { describeErrors } = require('stryker-parent');26describeErrors(() => {27 console.log('describeErrors');28});29const { describeErrors } = require('stryker-parent');30describeErrors(() => {31 console.log('describeErrors');32});33const { describeErrors } = require('stryker-parent');34describeErrors(() => {35 console.log('describeErrors');36});37const { describeErrors } = require('stryker-parent');38describeErrors(() => {39 console.log('describeErrors');40});41const { describeErrors } = require('stryker-parent');42describeErrors(() => {43 console.log('describeErrors');44});45const { describeErrors

Full Screen

Using AI Code Generation

copy

Full Screen

1const { describeErrors } = require('stryker-parent');2describeErrors();3module.exports = require('stryker-parent').describeErrors;4import { describeErrors } from 'stryker-parent';5export { describeErrors };6import { describeErrors } from 'stryker-parent';7export { describeErrors };8const { describeErrors } = require('stryker-parent');9module.exports = { describeErrors };10const { describeErrors } = require('stryker-parent');11module.exports = { describeErrors };12const { describeErrors } = require('stryker-parent');13module.exports = { describeErrors };14const { describeErrors } = require('stryker-parent');15module.exports = { describeErrors };16const { describeErrors } = require('stryker-parent');17module.exports = { describeErrors };18const { describeErrors } = require('stryker-parent');19module.exports = { describeErrors };20const { describeErrors } = require('stryker-parent');21module.exports = { describeErrors };22const { describeErrors } = require('stryker-parent');23module.exports = { describeErrors };24const { describeErrors } = require('stryker-parent');25module.exports = { describeErrors };26const { describeErrors } = require('stry

Full Screen

Using AI Code Generation

copy

Full Screen

1var strykerParent = require('stryker-parent');2var errors = strykerParent.describeErrors(['SOME_ERROR']);3console.log(errors.SOME_ERROR);4var strykerApi = require('stryker-api');5var errors = strykerApi.describeErrors(['SOME_ERROR']);6console.log(errors.SOME_ERROR);

Full Screen

Using AI Code Generation

copy

Full Screen

1var describeErrors = require('stryker-parent').describeErrors;2describeErrors('my error', function() {3});4var describeErrors = require('stryker-parent').describeErrors;5describeErrors('my error', function() {6});7var describeErrors = require('stryker-parent').describeErrors;8describeErrors('my error', function() {9});10var describeErrors = require('stryker-parent').describeErrors;11describeErrors('my error', function() {12});13var describeErrors = require('stryker-parent').describeErrors;14describeErrors('my error', function() {15});16var describeErrors = require('stryker-parent').describeErrors;17describeErrors('my error', function() {18});19var describeErrors = require('stryker-parent').describeErrors;20describeErrors('my error', function() {21});22var describeErrors = require('stryker-parent').describeErrors;23describeErrors('my error', function() {24});25var describeErrors = require('stryker-parent').describeErrors;26describeErrors('my error', function() {27});28var describeErrors = require('stryker-parent').describeErrors;29describeErrors('my error', function() {30});

Full Screen

Using AI Code Generation

copy

Full Screen

1describeErrors(1, 2, 3)2function describeErrors(...errors) {3 console.log(errors)4}5cloneArray([1, 2, 3])6function cloneArray(array) {7 console.log(clone)8}9combineArrays([1, 2, 3], [4, 5, 6], [7, 8, 9])10function combineArrays(...arrays) {11 console.log(combined)12}13combineObjects({ a: 1, b: 2, c: 3 }, { d: 4, e: 5, f: 6 }, { g: 7, h: 8, i: 9 })14function combineObjects(...objects) {15 const combined = { ...objects }16 console.log(combined)17}18combineObjects({ a: 1, b: 2, c: 3 }, { d: 4, e: 5, f: 6 }, { g: 7, h: 8, i: 9 })

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run stryker-parent automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful