Best JavaScript code snippet using cypress
users.js
Source:users.js
1const db = require('../helpers/db')2const table = 'users'3module.exports = {4 getUser: (data = []) => {5 return new Promise((resolve, reject) => {6 db.query(`SELECT * FROM ${table} LIMIT ? OFFSET ?`, data, (err, results, _fields) => {7 if (err) {8 reject(err)9 } else {10 resolve(results)11 }12 })13 })14 },15 countUsers: () => {16 return new Promise((resolve, reject) => {17 db.query(`SELECT COUNT(*) as count FROM ${table}`, (err, results, _fields) => {18 if (err) {19 reject(err)20 } else {21 resolve(results[0].count)22 }23 })24 })25 },26 validateUser: (arr, cb) => {27 db.query(`SELECT * FROM ${table} WHERE email LIKE '%${arr[0]}%'`, (_err, result, _fields) => {28 cb(result)29 })30 },31 getUserByCondition: (data = {}) => {32 return new Promise((resolve, reject) => {33 db.query(`SELECT * FROM ${table} WHERE ?`, data, (err, results, _fields) => {34 if (err) {35 reject(err)36 } else {37 resolve(results)38 }39 })40 })41 },42 createUsers: (data = {}) => {43 return new Promise((resolve, reject) => {44 db.query(`INSERT INTO ${table} SET ?`, data, (err, results, _fields) => {45 if (err) {46 reject(err)47 } else {48 resolve(results)49 }50 })51 })52 },53 createSeller: (arr, cb) => {54 db.query(`INSERT INTO ${table} (role_id, email, password) VALUES (${arr[0]}, '${arr[1]}', '${arr[2]}')`, (_err, result, _fields) => {55 cb(result)56 })57 },58 createDetailUsers: (arr, cb) => {59 db.query(`INSERT INTO user_details (email, name, balance, user_id) VALUES ('${arr[0]}', '${arr[1]}', 500000, ${arr[2]})`, (_err, results, _fields) => {60 cb(results)61 })62 },63 createDetailSeller: (arr, cb) => {64 db.query(`INSERT INTO store (name, phone_number, user_id, email) VALUES ('${arr[0]}', ${arr[1]}, ${arr[2]}, '${arr[3]}')`, (_err, results, _fields) => {65 cb(results)66 })67 },68 getProfile: (id, cb) => {69 db.query(`SELECT * FROM ${table} WHERE id=${id}`, (_err, result, _field) => {70 cb(result)71 })72 },73 getDetailProfile: (id, cb) => {74 db.query(`SELECT * FROM user_details WHERE user_id=${id}`, (_err, result, _field) => {75 cb(result)76 })77 },78 postPictModel: (arr, cb) => {79 db.query(`UPDATE user_details SET picture='${arr[1]}' where user_id=${arr[0]} `, (_err, result, _field) => {80 cb(result)81 })82 },83 updateEmail: (arr, cb) => {84 db.query(`UPDATE ${table} SET email='${arr[1]}' where id=${arr[0]}`)85 },86 updatePartialProfile: (arr, id) => {87 return new Promise((resolve, reject) => {88 db.query('UPDATE user_details SET ? WHERE user_id = ?', [arr, id], (_err, result, _fields) => {89 if (_err) {90 reject(_err)91 } else {92 resolve(result)93 }94 })95 })96 },97 addAddress: (arr, cb) => {98 db.query(`INSERT INTO user_address (addr_name, recipient, address, city, telephone, postal_code, status, user_id) VALUES ('${arr[0]}', '${arr[1]}', '${arr[2]}', '${arr[3]}', ${arr[4]}, ${arr[5]}, '${arr[6]}', ${arr[7]})`, (_err, result, _fields) => {99 cb(result)100 })101 },102 editAddress: (arr, id) => {103 return new Promise((resolve, reject) => {104 db.query(`UPDATE user_address SET ? WHERE id = ${id}`, arr, (_err, result, _fields) => {105 if (_err) {106 reject(_err)107 } else {108 resolve(result)109 }110 })111 })112 },113 addCheckout: (arr, cb) => {114 db.query(`INSERT INTO checkout (user_id) VALUES (${arr[0]})`, (_err, result, _field) => {115 cb(result)116 })117 },118 getCheckout: (arr, cb) => {119 db.query(`SELECT * FROM checkout WHERE user_id=${arr[0]}`, (_err, result, _field) => {120 cb(result)121 })122 },123 getCart: (id, cb) => {124 db.query(`SELECT product, quantity, price, total_price FROM cart WHERE user_id=${id}`, (_err, result, _field) => {125 cb(result)126 })127 },128 getNewCart: (id, cb) => {129 db.query(`SELECT * FROM cart WHERE user_id=${id}`, (_err, result, _field) => {130 cb(result)131 })132 },133 getAddress: (id, cb) => {134 db.query(`SELECT * FROM user_address WHERE user_id=${id} ORDER BY status asc`, (_err, result, _field) => {135 cb(result)136 })137 },138 getAddressCount: (id, cb) => {139 db.query(`SELECT COUNT(*) AS count FROM user_address WHERE user_id=${id} ORDER BY status asc`, (_err, result, _field) => {140 cb(result)141 })142 },143 getAddressByUser: (id) => {144 return new Promise((resolve, reject) => {145 db.query(`SELECT * FROM user_address WHERE user_id=${id} ORDER BY id asc`, (_err, result, _field) => {146 if (_err) {147 reject(_err)148 } else {149 resolve(result)150 }151 })152 })153 },154 getPriAddress: (id, cb) => {155 db.query(`SELECT * FROM user_address WHERE user_id=${id} AND status='primary'`, (_err, result, _field) => {156 cb(result)157 })158 },159 getPriAddressByUser: (id) => {160 return new Promise((resolve, reject) => {161 db.query(`SELECT * FROM user_address WHERE user_id=${id} AND status='primary'`, (_err, result, _field) => {162 if (_err) {163 reject(_err)164 } else {165 resolve(result)166 }167 })168 })169 },170 getPriAddressById: (id) => {171 return new Promise((resolve, reject) => {172 db.query(`SELECT * FROM user_address WHERE id=${id} AND status='primary'`, (_err, result, _field) => {173 if (_err) {174 reject(_err)175 } else {176 resolve(result)177 }178 })179 })180 },181 deleteAddress: (id) => {182 return new Promise((resolve, reject) => {183 db.query(`DELETE FROM user_address WHERE id=${id}`, (_err, result, _field) => {184 if (_err) {185 reject(_err)186 } else {187 resolve(result)188 }189 })190 })191 },192 deleteCart: (id, cb) => {193 db.query(`DELETE FROM cart WHERE user_id=${id}`, (_err, result, _field) => {194 cb(result)195 })196 },197 updateOrderId: (arr, cb) => {198 db.query(`UPDATE order_details SET order_id=${arr[0]}, isBuy=1 WHERE user_id=${arr[1]} AND isBuy=0`, (_err, result, _field) => {199 cb(result)200 })201 },202 createTransaction: (arr, cb) => {203 db.query(`INSERT INTO transaction (item, amount, delivery, summary, order_no, no_tracking, user_id) VALUES ('${arr[0]}', ${arr[1]}, 30000, ${arr[2]}, ${arr[3]}, '${arr[4]}', ${arr[5]})`, (_err, result, _field) => {204 cb(result)205 })206 },207 updateTransaction: (arr, cb) => {208 db.query(`UPDATE transaction SET item='${arr[0]}', amount=${arr[1]}, delivery=30000, summary=${arr[2]}, order_no=${arr[3]}, no_tracking='${arr[4]}', isBuy=1 WHERE user_id=${arr[5]} AND isBuy = 0`, (_err, result, _field) => {209 cb(result)210 })211 },212 createTransactionId: (arr, cb) => {213 db.query(`INSERT INTO transaction (user_id) VALUES (${arr[0]})`, (_err, result, _field) => {214 cb(result)215 })216 },217 deleteTransaction: (id, cb) => {218 db.query(`DELETE FROM transaction WHERE user_id=${id} AND isBuy=0`, (_err, result, _field) => {219 cb(result)220 })221 },222 updateBalance: (arr, cb) => {223 db.query(`UPDATE user_details SET balance=${arr[1]} WHERE user_id=${arr[0]}`, (_err, result, _field) => {224 cb(result)225 })226 },227 getHistoryTransaction: (id, cb) => {228 db.query(`SELECT * FROM transaction WHERE user_id=${id} ORDER BY id desc`, (_err, result, _field) => {229 cb(result)230 })231 },232 getHistoryDetail: (id, cb) => {233 db.query(`SELECT * FROM transaction WHERE id=${id}`, (_err, result, _field) => {234 cb(result)235 })236 },237 getHistoryCount: (id, cb) => {238 db.query(`SELECT COUNT(*) AS count FROM transaction WHERE user_id=${id}`, (_err, result, _field) => {239 cb(result)240 })241 },242 createOrderDetail: (arr, cb) => {243 db.query(`INSERT INTO order_details (order_id, user_id, product_id, quantity, price, total_price) VALUES ('${arr[0]}', ${arr[1]}, ${arr[2]}, ${arr[3]}, ${arr[4]}, ${arr[5]}, ${arr[6]})`, (_err, result, _fields) => {244 cb(result)245 })246 },247 createNewOrderDetail: (arr = {}) => {248 return new Promise((resolve, reject) => {249 db.query('INSERT INTO order_details SET ?', arr, (_err, result, _fields) => {250 if (_err) {251 reject(_err)252 } else {253 resolve(result)254 }255 })256 })257 }...
update_aliases.js
Source:update_aliases.js
1"use strict";2Object.defineProperty(exports, "__esModule", {3 value: true4});5exports.updateAliases = void 0;6var Either = _interopRequireWildcard(require("fp-ts/lib/Either"));7var _elasticsearch = require("@elastic/elasticsearch");8var _catch_retryable_es_client_errors = require("./catch_retryable_es_client_errors");9function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }10function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }11/*12 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one13 * or more contributor license agreements. Licensed under the Elastic License14 * 2.0 and the Server Side Public License, v 1; you may not use this file except15 * in compliance with, at your election, the Elastic License 2.0 or the Server16 * Side Public License, v 1.17 */18/**19 * Calls the Update index alias API `_alias` with the provided alias actions.20 */21const updateAliases = ({22 client,23 aliasActions24}) => () => {25 return client.indices.updateAliases({26 body: {27 actions: aliasActions28 }29 }, {30 maxRetries: 031 }).then(() => {32 // Ignore `acknowledged: false`. When the coordinating node accepts33 // the new cluster state update but not all nodes have applied the34 // update within the timeout `acknowledged` will be false. However,35 // retrying this update will always immediately result in `acknowledged:36 // true` even if there are still nodes which are falling behind with37 // cluster state updates.38 // The only impact for using `updateAliases` to mark the version index39 // as ready is that it could take longer for other Kibana instances to40 // see that the version index is ready so they are more likely to41 // perform unnecessary duplicate work.42 return Either.right('update_aliases_succeeded');43 }).catch(err => {44 if (err instanceof _elasticsearch.errors.ResponseError) {45 var _err$body, _err$body$error, _err$body2, _err$body2$error, _err$body3, _err$body3$error, _err$body3$error$reas, _err$body4, _err$body4$error, _err$body5, _err$body5$error, _err$body6, _err$body6$error, _err$body6$error$reas;46 if ((err === null || err === void 0 ? void 0 : (_err$body = err.body) === null || _err$body === void 0 ? void 0 : (_err$body$error = _err$body.error) === null || _err$body$error === void 0 ? void 0 : _err$body$error.type) === 'index_not_found_exception') {47 return Either.left({48 type: 'index_not_found_exception',49 index: err.body.error.index50 });51 } else if ((err === null || err === void 0 ? void 0 : (_err$body2 = err.body) === null || _err$body2 === void 0 ? void 0 : (_err$body2$error = _err$body2.error) === null || _err$body2$error === void 0 ? void 0 : _err$body2$error.type) === 'illegal_argument_exception' && err !== null && err !== void 0 && (_err$body3 = err.body) !== null && _err$body3 !== void 0 && (_err$body3$error = _err$body3.error) !== null && _err$body3$error !== void 0 && (_err$body3$error$reas = _err$body3$error.reason) !== null && _err$body3$error$reas !== void 0 && _err$body3$error$reas.match(/The provided expression \[.+\] matches an alias, specify the corresponding concrete indices instead./)) {52 return Either.left({53 type: 'remove_index_not_a_concrete_index'54 });55 } else if ((err === null || err === void 0 ? void 0 : (_err$body4 = err.body) === null || _err$body4 === void 0 ? void 0 : (_err$body4$error = _err$body4.error) === null || _err$body4$error === void 0 ? void 0 : _err$body4$error.type) === 'aliases_not_found_exception' || (err === null || err === void 0 ? void 0 : (_err$body5 = err.body) === null || _err$body5 === void 0 ? void 0 : (_err$body5$error = _err$body5.error) === null || _err$body5$error === void 0 ? void 0 : _err$body5$error.type) === 'resource_not_found_exception' && err !== null && err !== void 0 && (_err$body6 = err.body) !== null && _err$body6 !== void 0 && (_err$body6$error = _err$body6.error) !== null && _err$body6$error !== void 0 && (_err$body6$error$reas = _err$body6$error.reason) !== null && _err$body6$error$reas !== void 0 && _err$body6$error$reas.match(/required alias \[.+\] does not exist/)) {56 return Either.left({57 type: 'alias_not_found_exception'58 });59 }60 }61 throw err;62 }).catch(_catch_retryable_es_client_errors.catchRetryableEsClientErrors);63};...
generateTrigger.js
Source:generateTrigger.js
1const fs = require('fs');2const path = require('path');3const EMA = require('../indicators/ema');4const generateZigZag = require('./zigZag/generateZigZag');5const getCycleMagnitude = require('./zigZag/zzGenerators/cycleMagnitude');6const getCycleDuration = require('./zigZag/zzGenerators/cycleDuration');7function generateTrigger(seedData, { writeToFiles = true }) {8 const { rsi, data } = seedData;9 const rsiAvgSmall = new EMA({10 values: rsi.map(({ value }) => value * 1.7),11 period: 8,12 });13 const rsiAvgBig = new EMA({14 values: rsi.map(({ value }) => value * 1.7),15 period: 34,16 });17 const rsiAvg = rsiAvgSmall.map((val, i) => val - rsiAvgBig[i]).filter(Boolean);18 const bulletValues = rsiAvg.map((val, i) => {19 if (rsiAvg[i + 1]) {20 return (val - rsiAvg[i + 1]) * 10;21 }22 return '';23 });24 const bullet = new EMA({25 values: bulletValues,26 period: 5,27 });28 const zigZag = generateZigZag({29 times: data.map(({ time }) => time),30 data: bullet,31 reversalAmount: 10,32 });33 const { states, metrics, plots } = zigZag;34 const bulletFastEma = new EMA({35 values: bullet,36 period: 8,37 });38 const bulletSlowEma = new EMA({39 values: plots.map(val => val * 3),40 period: 34,41 });42 const zzDurations = getCycleDuration(metrics);43 const zzMagnitudes = getCycleMagnitude(metrics);44 if (writeToFiles) {45 fs.writeFile(46 path.resolve('./server/models/techAnalysis/trigger/trigger-bullet.txt'),47 bullet.map(val => val + '\n').join(''), // eslint-disable-line48 _err => {49 if (_err) throw new Error('_err: ', _err);50 },51 );52 fs.writeFile(53 path.resolve('./server/models/techAnalysis/trigger/trigger-bulletFastEma.txt'),54 bulletFastEma.map(val => val + '\n').join(''), // eslint-disable-line55 _err => {56 if (_err) throw new Error('_err: ', _err);57 },58 );59 fs.writeFile(60 path.resolve('./server/models/techAnalysis/trigger/trigger-bulletSlowEma.txt'),61 bulletSlowEma.map(val => val + '\n').join(''), // eslint-disable-line62 _err => {63 if (_err) throw new Error('_err: ', _err);64 },65 );66 fs.writeFile(67 path.resolve('./server/models/techAnalysis/trigger/trigger-zigZag-mode.txt'),68 states.map(val => (val.mode === 'uptrend' ? `${1}\n` : `${-1}\n`)).join(''), // eslint-disable-line69 _err => {70 if (_err) throw new Error('_err: ', _err);71 },72 );73 fs.writeFile(74 path.resolve('./server/models/techAnalysis/trigger/trigger-zigZag-plots.txt'),75 plots.map(val => val + '\n').join(''), // eslint-disable-line76 _err => {77 if (_err) throw new Error('_err: ', _err);78 },79 );80 fs.writeFile(81 path.resolve('./server/models/techAnalysis/trigger/trigger-zigZag-metrics.txt'),82 metrics.map(val => JSON.stringify(val, null, 2) + '\n').join(''), // eslint-disable-line83 _err => {84 if (_err) throw new Error('_err: ', _err);85 },86 );87 fs.writeFile(88 path.resolve('./server/models/techAnalysis/trigger/trigger-zigZag-magnitude.txt'),89 metrics.map(val => val.magnitude + '\n').join(''), // eslint-disable-line90 _err => {91 if (_err) throw new Error('_err: ', _err);92 },93 );94 fs.writeFile(95 path.resolve('./server/models/techAnalysis/trigger/trigger-zigZag-duration.txt'),96 metrics97 .map(val =>98 val.slope > 0 ? `${val.endState.duration}\n` : `${val.endState.duration * -1}\n`,99 )100 .join(''), // eslint-disable-line101 _err => {102 if (_err) throw new Error('_err: ', _err);103 },104 );105 fs.writeFile(106 path.resolve('./server/models/techAnalysis/trigger/trigger-zigZag-cycleDuration.txt'),107 zzDurations.map(val => `${val}\n`).join(''), // eslint-disable-line108 _err => {109 if (_err) throw new Error('_err: ', _err);110 },111 );112 fs.writeFile(113 path.resolve('./server/models/techAnalysis/trigger/trigger-zigZag-cycleMagnitude.txt'),114 zzMagnitudes.map(val => `${val}\n`).join(''), // eslint-disable-line115 _err => {116 if (_err) throw new Error('_err: ', _err);117 },118 );119 }120 return {121 average: rsiAvg,122 averageSmall: rsiAvgSmall,123 averageBig: rsiAvgBig,124 zigZag,125 zzDurations,126 zzMagnitudes,127 };128}...
database_query.js
Source:database_query.js
1const db = require('./db')2module.exports = {3 createData: (table, data) => {4 return new Promise((resolve, reject) => {5 db.query('INSERT INTO ?? SET ?', [table, data], (_err, result, _field) => {6 console.log(_err)7 if (!_err) {8 resolve(result)9 }10 reject(_err)11 })12 })13 },14 getDataById: (table, id) => {15 return new Promise((resolve, reject) => {16 db.query('SELECT * FROM ?? WHERE ?', [table, id], (_err, result, _field) => {17 if (!_err) {18 resolve(result)19 }20 reject(_err)21 })22 })23 },24 getDataByIdTwo: (table, id1, id2) => {25 return new Promise((resolve, reject) => {26 db.query('SELECT * FROM ?? WHERE ? AND ?', [table, id1, id2], (_err, result, _field) => {27 if (!_err) {28 resolve(result)29 }30 reject(_err)31 })32 })33 },34 deleteDataById: (table, id) => {35 return new Promise((resolve, reject) => {36 db.query('DELETE FROM ?? WHERE id=?', [table, id], (_err, result, _field) => {37 if (_err) {38 reject(_err)39 } else {40 resolve(result)41 }42 })43 })44 },45 updateData: (table, id, data) => {46 return new Promise((resolve, reject) => {47 db.query('UPDATE ?? SET ? WHERE id= ?', [table, data, id], (_err, result, _field) => {48 console.log(_err)49 if (_err) {50 reject(_err)51 } else {52 resolve(result)53 }54 })55 })56 },57 listData: (data, sortTo) => {58 return new Promise((resolve, reject) => {59 db.query(`SELECT * FROM ?? WHERE name LIKE ? ORDER BY name ${sortTo} LIMIT ? OFFSET ?`,60 data, (_err, result, _field) => {61 if (_err) {62 reject(_err)63 } else {64 resolve(result)65 }66 })67 })68 },69 countData: (data) => {70 return new Promise((resolve, reject) => {71 db.query('SELECT COUNT("*") as count FROM ?? WHERE name LIKE ?', data, (_err, result, _field) => {72 if (_err) {73 reject(_err)74 } else {75 resolve(result)76 }77 })78 })79 },80 updateDataPart: (table, id, data) => {81 return new Promise((resolve, reject) => {82 db.query('UPDATE ?? SET ? WHERE ?', [table, data, id], (_err, result, _field) => {83 console.log(_err)84 if (_err) {85 reject(_err)86 } else {87 resolve(result)88 }89 })90 })91 },92 listDataDymc: (data, sortBy, sortTo) => {93 return new Promise((resolve, reject) => {94 db.query(`SELECT * FROM ?? WHERE name LIKE ? ORDER BY ${sortBy} ${sortTo} LIMIT ? OFFSET ?`,95 data, (_err, result, _field) => {96 if (_err) {97 reject(_err)98 } else {99 resolve(result)100 }101 })102 })103 },104 updateTwoCondst: (table, id1, id2, data) => {105 return new Promise((resolve, reject) => {106 db.query('UPDATE ?? SET ? WHERE ? AND ?', [table, data, id1, id2], (_err, result, _field) => {107 console.log(_err)108 if (_err) {109 reject(_err)110 } else {111 resolve(result)112 }113 })114 })115 },116 deleteData: (table, id) => {117 return new Promise((resolve, reject) => {118 db.query('DELETE FROM ?? WHERE ?', [table, id], (_err, result, _field) => {119 if (_err) {120 reject(_err)121 } else {122 resolve(result)123 }124 })125 })126 },127 getAllData: (table) => {128 return new Promise((resolve, reject) => {129 db.query('SELECT id, name, picture FROM ??', [table], (_err, result, _field) => {130 if (_err) {131 reject(_err)132 } else {133 resolve(result)134 }135 })136 })137 },138 listAdress: (data) => {139 return new Promise((resolve, reject) => {140 db.query('SELECT * FROM user_adress WHERE user_id = ? ORDER BY primary_adress DESC LIMIT ? OFFSET ?',141 data, (_err, result, _field) => {142 console.log(_err)143 if (_err) {144 reject(_err)145 } else {146 resolve(result)147 }148 })149 })150 }...
generateDirection.js
Source:generateDirection.js
1const fs = require('fs');2const path = require('path');3const generateHigherTimeRsi = require('./generateHigherTimeRsi');4const generateZigZag = require('./zigZag/generateZigZag');5const getCycleDuration = require('./zigZag/zzGenerators/cycleDuration');6const getCycleMagnitude = require('./zigZag/zzGenerators/cycleMagnitude');7const EMA = require('../indicators/ema');8function generateDirection(options, { writeToFiles = true }) {9 const { zigZagReversal, zigZagReversalSlow, data } = options;10 const fastRsiDirection = generateHigherTimeRsi({11 ...options,12 rsiEmaLength: 13,13 });14 const slowRsiDirection = generateHigherTimeRsi({15 ...options,16 rsiEmaLength: 21,17 });18 const zigZag = generateZigZag({19 times: data.map(({ time }) => time),20 data: fastRsiDirection,21 reversalAmount: zigZagReversal,22 });23 const zigZagSlow = generateZigZag({24 times: data.map(({ time }) => time),25 data: fastRsiDirection,26 reversalAmount: zigZagReversalSlow,27 });28 const rsiAverage = new EMA({29 values: slowRsiDirection,30 period: 21,31 });32 const {33 // states,34 metrics,35 plots,36 } = zigZag;37 const rsiBull = new EMA({38 values: plots.map(val => val),39 period: 13,40 });41 const rsiBear = new EMA({42 values: plots.map(val => val),43 period: 34,44 });45 const zzMagnitudes = getCycleMagnitude(metrics);46 const zzDurations = getCycleDuration(metrics);47 if (writeToFiles) {48 fs.writeFile(49 path.resolve('./server/models/techAnalysis/direction/direction-rsi.txt'),50 slowRsiDirection.map(val => `${val}\n`).join(''), // eslint-disable-line51 _err => {52 if (_err) throw new Error('_err: ', _err);53 },54 );55 fs.writeFile(56 path.resolve(57 './server/models/techAnalysis/direction/direction-rsiAverage.txt',58 ),59 rsiAverage.map(val => `${val}\n`).join(''), // eslint-disable-line60 _err => {61 if (_err) throw new Error('_err: ', _err);62 },63 );64 fs.writeFile(65 path.resolve(66 './server/models/techAnalysis/direction/direction-rsiBull.txt',67 ),68 rsiBull.map(val => `${val}\n`).join(''), // eslint-disable-line69 _err => {70 if (_err) throw new Error('_err: ', _err);71 },72 );73 fs.writeFile(74 path.resolve(75 './server/models/techAnalysis/direction/direction-rsiBear.txt',76 ),77 rsiBear.map(val => `${val}\n`).join(''), // eslint-disable-line78 _err => {79 if (_err) throw new Error('_err: ', _err);80 },81 );82 fs.writeFile(83 path.resolve(84 './server/models/techAnalysis/direction/direction-zigZag.txt',85 ),86 plots.map(val => `${val}\n`).join(''), // eslint-disable-line87 _err => {88 if (_err) throw new Error('_err: ', _err);89 },90 );91 fs.writeFile(92 path.resolve(93 './server/models/techAnalysis/direction/direction-zigZag-metrics.txt',94 ),95 metrics.map(val => JSON.stringify(val, null, 2) + '\n').join(''), // eslint-disable-line96 _err => {97 if (_err) throw new Error('_err: ', _err);98 },99 );100 fs.writeFile(101 path.resolve(102 './server/models/techAnalysis/direction/direction-zigZag-cycleDuration.txt',103 ),104 zzDurations.map(duration => `${duration}\n`).join(''), // eslint-disable-line105 _err => {106 if (_err) throw new Error('_err: ', _err);107 },108 );109 fs.writeFile(110 path.resolve(111 './server/models/techAnalysis/direction/direction-zigZag-cycleMagnitude.txt',112 ),113 zzMagnitudes.map(val => `${val}\n`).join(''), // eslint-disable-line114 _err => {115 if (_err) throw new Error('_err: ', _err);116 },117 );118 }119 return {120 average: rsiAverage,121 averageSmall: rsiBull,122 averageBig: rsiBear,123 zigZag,124 zzDurations,125 zzMagnitudes,126 };127}...
cart.js
Source:cart.js
1const db = require('../helpers/db')2const table = 'cart'3module.exports = {4 getDetailCartModel: (id, cb) => {5 db.query(`SELECT cart.id, cart.product, cart.quantity, cart.price, cart.total_price, cart.user_id, cart.product_id, product_images.url FROM ${table} INNER JOIN product_images ON cart.product_id=product_images.product_id WHERE user_id=${id} ORDER BY id desc`, (_err, result, _field) => {6 cb(result)7 })8 },9 getOrderDetails: (id, cb) => {10 db.query(`SELECT order_details.id, order_details.order_id, order_details.product, order_details.quantity, order_details.price, order_details.total_price, order_details.user_id, order_details.product_id, product_images.url FROM order_details INNER JOIN product_images ON order_details.product_id=product_images.product_id WHERE order_id=${id}`, (_err, result, _field) => {11 cb(result)12 })13 },14 getDetailCartModelById: (id) => {15 return new Promise((resolve, reject) => {16 db.query(`SELECT * FROM ${table} WHERE id=${id}`, (_err, result, _field) => {17 if (_err) {18 reject(_err)19 } else {20 resolve(result)21 }22 })23 })24 },25 getDetailCartModelByProduct: (id, product) => {26 return new Promise((resolve, reject) => {27 db.query(`SELECT * FROM ${table} WHERE user_id=${id} AND product_id=${product}`, (_err, result, _field) => {28 if (_err) {29 reject(_err)30 } else {31 resolve(result)32 }33 })34 })35 },36 createCartModel: (arr, cb) => {37 db.query(`SELECT * FROM products WHERE id=${arr[0]}`, (_err, result, _fields) => {38 cb(result)39 })40 },41 createCartModel1: (arr, cb) => {42 db.query(`INSERT INTO ${table} (product, quantity, price, total_price, user_id, product_id) VALUES ('${arr[0]}', ${arr[1]}, ${arr[2]}, ${arr[3]}, ${arr[4]}, ${arr[5]})`, (_err, result, _fields) => {43 cb(result)44 })45 },46 createOrderDetails: (arr, cb) => {47 db.query(`INSERT INTO order_details (user_id, product_id, quantity, price, total_price, product, cart_id) VALUES (${arr[0]}, ${arr[1]}, ${arr[2]}, ${arr[3]}, ${arr[4]}, '${arr[5]}', ${arr[6]})`, (_err, result, _fields) => {48 cb(result)49 })50 },51 getCartModel: (arr, cb) => {52 const query = `SELECT * FROM ${table} WHERE ${arr[0]} LIKE '%${arr[1]}%' ORDER BY ${arr[4]} ${arr[5]} LIMIT ${arr[2]} OFFSET ${(arr[3] - 1) * arr[2]}`53 db.query(query, (err, result, _field) => {54 cb(err, result)55 })56 },57 getCartModel1: (arr, cb) => {58 const query = `SELECT COUNT(*) AS count FROM ${table} WHERE ${arr[0]} LIKE '%${arr[1]}%'`59 db.query(query, (_err, data, _field) => {60 cb(data)61 })62 },63 deleteCartModel: (id, cb) => {64 const query = `SELECT * FROM ${table} WHERE id=${id}`65 db.query(query, (_err, result, _fields) => {66 cb(result)67 })68 },69 deleteCartModel1: (id, cb) => {70 const query = `DELETE FROM ${table} WHERE id=${id}`71 db.query(query, (_err, result, _fields) => {72 cb(result)73 })74 },75 deleteOrderDetail: (id, cb) => {76 const query = `DELETE FROM order_details WHERE cart_id=${id}`77 db.query(query, (_err, result, _fields) => {78 cb(result)79 })80 },81 update: (data, id) => {82 return new Promise((resolve, reject) => {83 db.query(`UPDATE ${table} SET ? WHERE id = ?`, [data, id], (_err, result, _field) => {84 if (_err) {85 reject(_err)86 } else {87 resolve(result)88 }89 })90 })91 },92 updateOrder: (data, id) => {93 return new Promise((resolve, reject) => {94 db.query('UPDATE order_details SET ? WHERE cart_id = ?', [data, id], (_err, result, _field) => {95 if (_err) {96 reject(_err)97 } else {98 resolve(result)99 }100 })101 })102 }...
items.js
Source:items.js
1const db = require('../helpers/db')2const table = 'products'3module.exports = {4 getItemModel: (id) => {5 return new Promise((resolve, reject) => {6 const rowSubQuery = `i.id,i.name AS 'name',i.price,i.quantity,c.name AS 'condition' 7 ,ct.name AS 'category',p.url,i.description,FORMAT(AVG(r.rating),1) as ratings,i.create_at,i.update_at`8 const query = `SELECT ${rowSubQuery} FROM products i LEFT JOIN categories ct on i.category_id = ct.id 9 LEFT JOIN conditions c ON i.condition_id = c.id 10 LEFT JOIN product_picture p ON i.id = p.productId LEFT JOIN ratings r ON i.id = r.product_id WHERE i.id = ? GROUP BY i.id`11 db.query(`${query}`, id, (_err, result, _field) => {12 console.log(_err)13 if (!_err) {14 resolve(result)15 }16 reject(_err)17 })18 })19 },20 createItemModel: (data) => {21 return new Promise((resolve, reject) => {22 db.query(`INSERT INTO ${table} SET ?`, data, (_err, result, _field) => {23 console.log(_err)24 if (!_err) {25 resolve(result)26 }27 reject(_err)28 })29 })30 },31 updateItemModel: (id, data) => {32 return new Promise((resolve, reject) => {33 db.query(`UPDATE ${table} SET ? 34 WHERE id= ?`, [data, id], (_err, result, _field) => {35 console.log(_err)36 if (_err) {37 reject(_err)38 } else {39 resolve(result)40 }41 })42 })43 },44 deleteItemModel: (id) => {45 return new Promise((resolve, reject) => {46 db.query(`DELETE FROM ${table} WHERE id=?`, id, (_err, result, _field) => {47 console.log(_err)48 if (_err) {49 reject(_err)50 } else {51 resolve(result)52 }53 })54 })55 },56 searchItemModel: (searchKey, sort, data) => {57 return new Promise((resolve, reject) => {58 const rowSubQuery = `i.id as id,i.name AS 'name',p.url as picture,p.indexOf,i.price,i.quantity,c.name AS 'condition' 59 ,ct.name AS 'category',i.description,FORMAT(AVG(r.rating),1) as ratings,i.create_at,i.update_at`60 const subQuery = `SELECT ${rowSubQuery} FROM products i LEFT JOIN categories ct on i.category_id = ct.id 61 LEFT JOIN conditions c ON i.condition_id = c.id LEFT JOIN product_picture p ON i.id = p.productId 62 LEFT JOIN ratings r on i.id = r.product_id WHERE p.indexOf = 0 AND (r.rating > 0 or r.rating is null) GROUP BY i.id`63 db.query(`SELECT * 64 FROM (${subQuery}) as table_1 WHERE ${searchKey} LIKE ? 65 ORDER BY ${sort[0]} ${sort[1]} LIMIT ? OFFSET ?`, data, (_err, result, _field) => {66 console.log(_err)67 if (_err) {68 reject(_err)69 } else {70 resolve(result)71 }72 })73 })74 },75 countGetItemModel: (arr) => {76 return new Promise((resolve, reject) => {77 const rowSubQuery = `i.id,i.name AS 'name',i.price,i.description,i.quantity,c.name AS 'condition' 78 ,ct.name AS 'category',i.create_at,i.update_at`79 const subQuery = `SELECT ${rowSubQuery} FROM products i INNER JOIN categories ct on i.category_id = ct.id 80 INNER JOIN conditions c ON i.condition_id = c.id`81 db.query(`SELECT COUNT('*') as count FROM (${subQuery}) as table1 WHERE ${arr[0]} LIKE '%${arr[1]}%'`, (_err, result, _field) => {82 if (_err) {83 reject(_err)84 } else {85 resolve(result)86 }87 })88 })89 },90 createImageModel: (arr) => {91 return new Promise((resolve, reject) => {92 db.query('INSERT INTO product_picture (productId,url,indexOf) VALUES ?', [arr], (_err, result, _field) => {93 console.log(_err)94 if (!_err) {95 resolve(result)96 }97 reject(_err)98 })99 })100 }...
user.js
Source:user.js
1import uuid from 'uuid';2export default {3 createUser: function(_userData, _callback) {4 let UserModel = this.getModel('user');5 UserModel.create(_userData, function(_err, _doc) {6 if (_err !== null) {7 agent.log.error("Mongodb Fail createUser");8 _callback(_err, null);9 } else {10 agent.log.info("Mongodb Created New User");11 _callback(null, _doc);12 }13 })14 },15 updateUser: function(_condition, _descObject, _callback) {16 let UserModel = this.getModel('user');17 UserModel.findOneAndUpdate(_condition, _descObject, (_err, _userData) => {18 if (_err !== null) {19 agent.log.error("Mongodb Fail update user");20 _callback(_err, null);21 } else {22 _callback(null, _userData);23 }24 });25 },26 updateUserById: function(_id, _descObject, _callback) {27 this.updateUser({28 _id: _id29 }, _descObject, (_err, _userData) => {30 _callback(_err, _userData);31 });32 },33 getUserCount: function(_callback) {34 let UserModel = this.getModel('user');35 UserModel.count(function(_err, _c) {36 if (_err !== null) {37 agent.log.error("Mongodb Get User Count :" + _err);38 }39 _callback(_err, _c);40 });41 },42 getUserByEmail: function(_email, _callback) {43 let UserModel = this.getModel('user');44 UserModel.findOne({45 email: _email46 }, function(_err, _userDoc) {47 if (_err !== null) {48 agent.log.error("MongoDB get user by email :[" + _email + "] " + _err);49 }50 _callback(_err, _userDoc);51 });52 },53 getUserById: function(_id, _callback) {54 let UserModel = this.getModel('user');55 UserModel.findOne({56 _id: _id57 }, function(_err, _userDoc) {58 if (_err !== null) {59 agent.log.error("MongoDB get user by id :[" + _id + "] " + _err);60 }61 _callback(_err, _userDoc);62 });63 },64 createUserEmailCertification: function(_id, _callback) {65 let key = uuid.v4() + uuid.v1() + uuid.v4();66 let ECModel = this.getModel('EmailCertification');67 ECModel.create({68 user_id: _id,69 key: key,70 issue_date: new Date()71 }, (_err, _certi) => {72 if (_err !== null) {73 agent.log.error("MongoDB create email certification :" + _err);74 }75 _callback(_err, _certi);76 });77 },78 getEmailCertification: function(_key, _callback) {79 let ECModel = this.getModel('EmailCertification');80 ECModel.findOne({81 key: _key82 }, function(_err, _cert) {83 if (_err !== null) {84 agent.log.error("MongoDB findOne email certification key [" + _key + "]:" + _err);85 }86 _callback(_err, _cert);87 });88 },89 deleteEmailCertification: function(_key, _callback) {90 let ECModel = this.getModel('EmailCertification');91 ECModel.findOneAndRemove({92 key: _key93 }, function(_err, _cert) {94 if (_err !== null) {95 agent.log.error("MongoDB remove email certification key [" + _key + "]:" + _err);96 }97 _callback(_err, _cert);98 });99 }...
Using AI Code Generation
1describe('My First Test', () => {2 it('Does not do much!', () => {3 cy.contains('type').click()4 cy.url().should('include', '/commands/actions')5 cy.get('.action-email')6 .type('
Using AI Code Generation
1Cypress.Commands.add('_err', (msg) => {2 throw new Error(msg)3})4Cypress.Commands.add('_log', (msg) => {5 Cypress.log({message: msg})6})7Cypress.Commands.add('_info', (msg) => {8 Cypress.log({message: msg, consoleProps: () => msg})9})10Cypress.Commands.add('_warn', (msg) => {11 Cypress.log({message: msg, consoleProps: () => msg, warning: true})12})13Cypress.Commands.add('_debug', (msg) => {14 Cypress.log({message: msg, consoleProps: () => msg})15})16Cypress.Commands.add('_dir', (msg) => {17 Cypress.log({message: msg, consoleProps: () => msg})18})19Cypress.Commands.add('_table', (msg) => {20 Cypress.log({message: msg, consoleProps: () => msg})21})22Cypress.Commands.add('_group', (msg) => {23 Cypress.log({message: msg, consoleProps: () => msg})24})25Cypress.Commands.add('_groupEnd', (msg) => {26 Cypress.log({message: msg, consoleProps: () => msg})27})28Cypress.Commands.add('_groupCollapsed', (msg) => {29 Cypress.log({message: msg, consoleProps: () => msg})30})31Cypress.Commands.add('_groupEndCollapsed', (msg) => {32 Cypress.log({message: msg, consoleProps: () => msg})33})34Cypress.Commands.add('_time', (msg) => {35 Cypress.log({message: msg, consoleProps: () => msg})36})37Cypress.Commands.add('_timeEnd', (msg) => {38 Cypress.log({message: msg, consoleProps: () => msg})39})40Cypress.Commands.add('_time
Using AI Code Generation
1Cypress.Commands.add('_err', (err) => {2 throw new Error(err)3})4Cypress.Commands.add('_warn', (msg) => {5 Cypress.log({6 consoleProps: () => {7 return {8 }9 },10 })11})12Cypress.Commands.add('_info', (msg) => {13 Cypress.log({14 consoleProps: () => {15 return {16 }17 },18 })19})20Cypress.Commands.add('_debug', (msg) => {21 Cypress.log({22 consoleProps: () => {23 return {24 }25 },26 })27})28Cypress.Commands.add('_log', (msg) => {29 Cypress.log({30 consoleProps: () => {31 return {32 }33 },34 })35})36Cypress.Commands.add('_clear', () => {37 cy.get('.reporter-wrap').then(($reporter) => {38 })39})40Cypress.Commands.add('_logAndThrow', (err) => {41 Cypress.log({42 consoleProps: () => {43 return {44 }45 },46 })47 throw new Error(err)48})49Cypress.Commands.add('_logAndWarn', (msg) => {50 Cypress.log({51 consoleProps: () => {52 return {53 }54 },55 })56})57Cypress.Commands.add('_logAndInfo', (msg) => {58 Cypress.log({
Using AI Code Generation
1describe('Test', () => {2 it('Test', () => {3 cy.get('input[name="q"]').type('test');4 cy.get('input[name="btnK"]').click();5 cy.get('div.g').should('have.length', 10);6 cy.get('div.g').eq(0).should('contain', 'Test');7 cy.get('div.g').eq(0).find('a').should('have.attr', 'href').and('include', 'google.com');8 cy.get('div.g').eq(0).find('a').should('have.attr', 'href').and('include', 'google.com')._err('Test');9 });10});11Cypress.Commands.add('_err', { prevSubject: true }, (subject, message) => {12 if (subject) {13 return subject;14 }15 throw new Error(message);16});17Cypress.Commands.add('_err', { prevSubject: true }, (subject, message) => {18 if (subject) {19 return subject;20 }21 throw new Error(message);22});23declare namespace Cypress {24 interface Chainable<Subject> {25 _err(message: string): Chainable<Subject>;26 }27}28declare namespace Cypress {29 interface Chainable<Subject> {30 _err(message: string): Chainable<Subject>;31 }32}33{34 "compilerOptions": {35 }36}37module.exports = (on, config) => {38 require('@cypress/code-coverage/task')(on, config);39 return config;40};41{42 "env": {43 },
Using AI Code Generation
1Cypress.Commands.add('_err', (msg) => {2 throw new Error(msg);3});4it('test', () => {5 cy._err('some error message');6});
Using AI Code Generation
1import { _err } from "@cypress/code-coverage/task";2function _err(message) {3 console.log(message);4}5_err("This is a message");6import { _err } from "@cypress/code-coverage/task";7function _err(message) {8 console.log(message);9}10_err("This is a message");11import { _err } from "@cypress/code-coverage/task";12function _err(message) {13 console.log(message);14}15_err("This is a message");16import { _err } from "@cypress/code-coverage/task";17function _err(message) {18 console.log(message);19}20_err("This is a message");21import { _err } from "@cypress/code-coverage/task";22function _err(message) {23 console.log(message);24}25_err("This is a message");26import { _err } from "@cypress/code-coverage/task";27function _err(message) {28 console.log(message);29}30_err("This is a message");31import { _err } from "@cypress/code-coverage/task";32function _err(message) {33 console.log(message);34}35_err("This is a message");36import { _err } from "@cypress/code-coverage/task";37function _err(message) {38 console.log(message);39}40_err("This is a message");41import { _err } from "@cypress/code-coverage/task";42function _err(message) {43 console.log(message);44}45_err("This is a message");46import { _err } from "@cypress/code-coverage/task";47function _err(message) {48 console.log(message);49}50_err("This is a message");51import { _err } from "@cypress/code-coverage/task";52function _err(message) {53 console.log(message);54}55_err("This is a message");56import { _err } from "@cypress/code-coverage/task";57function _err(message) {58 console.log(message);59}
Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.
You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.
Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.
Get 100 minutes of automation test minutes FREE!!