How to use sendResponse method in Cypress

Best JavaScript code snippet using cypress

browser.js

Source:browser.js Github

copy

Full Screen

...32 }33 };34 this.page.onLoadFinished = function(status) {35 if (_this.state === 'loading') {36 _this.sendResponse({37 status: status,38 position: _this.last_mouse_event39 });40 return _this.setState('default');41 } else if (_this.state === 'awaiting_frame_load') {42 _this.sendResponse(true);43 return _this.setState('default');44 }45 };46 this.page.onInitialized = function() {47 return _this.page_id += 1;48 };49 return this.page.onPageCreated = function(sub_page) {50 var name;51 if (_this.state === 'awaiting_sub_page') {52 name = _this.page_name;53 _this.page_name = null;54 _this.setState('default');55 return setTimeout((function() {56 return _this.push_window(name);57 }), 0);58 }59 };60 };61 Browser.prototype.runCommand = function(name, args) {62 this.setState("default");63 return this[name].apply(this, args);64 };65 Browser.prototype.debug = function(message) {66 if (this._debug) {67 return console.log("poltergeist [" + (new Date().getTime()) + "] " + message);68 }69 };70 Browser.prototype.setState = function(state) {71 if (this.state === state) {72 return;73 }74 this.debug("state " + this.state + " -> " + state);75 return this.state = state;76 };77 Browser.prototype.sendResponse = function(response) {78 var errors;79 errors = this.page.errors();80 this.page.clearErrors();81 if (errors.length > 0 && this.js_errors) {82 return this.owner.sendError(new Poltergeist.JavascriptError(errors));83 } else {84 return this.owner.sendResponse(response);85 }86 };87 Browser.prototype.add_extension = function(extension) {88 this.page.injectExtension(extension);89 return this.sendResponse('success');90 };91 Browser.prototype.node = function(page_id, id) {92 if (page_id === this.page_id) {93 return this.page.get(id);94 } else {95 throw new Poltergeist.ObsoleteNode;96 }97 };98 Browser.prototype.visit = function(url) {99 var prev_url;100 this.setState('loading');101 prev_url = this.page.source() === null ? 'about:blank' : this.page.currentUrl();102 this.page.open(url);103 if (/#/.test(url) && prev_url.split('#')[0] === url.split('#')[0]) {104 this.setState('default');105 return this.sendResponse('success');106 }107 };108 Browser.prototype.current_url = function() {109 return this.sendResponse(this.page.currentUrl());110 };111 Browser.prototype.status_code = function() {112 return this.sendResponse(this.page.statusCode());113 };114 Browser.prototype.body = function() {115 return this.sendResponse(this.page.content());116 };117 Browser.prototype.source = function() {118 return this.sendResponse(this.page.source());119 };120 Browser.prototype.title = function() {121 return this.sendResponse(this.page.title());122 };123 Browser.prototype.find = function(method, selector) {124 return this.sendResponse({125 page_id: this.page_id,126 ids: this.page.find(method, selector)127 });128 };129 Browser.prototype.find_within = function(page_id, id, method, selector) {130 return this.sendResponse(this.node(page_id, id).find(method, selector));131 };132 Browser.prototype.all_text = function(page_id, id) {133 return this.sendResponse(this.node(page_id, id).allText());134 };135 Browser.prototype.visible_text = function(page_id, id) {136 return this.sendResponse(this.node(page_id, id).visibleText());137 };138 Browser.prototype.delete_text = function(page_id, id) {139 return this.sendResponse(this.node(page_id, id).deleteText());140 };141 Browser.prototype.attribute = function(page_id, id, name) {142 return this.sendResponse(this.node(page_id, id).getAttribute(name));143 };144 Browser.prototype.value = function(page_id, id) {145 return this.sendResponse(this.node(page_id, id).value());146 };147 Browser.prototype.set = function(page_id, id, value) {148 this.node(page_id, id).set(value);149 return this.sendResponse(true);150 };151 Browser.prototype.select_file = function(page_id, id, value) {152 var node;153 node = this.node(page_id, id);154 this.page.beforeUpload(node.id);155 this.page.uploadFile('[_poltergeist_selected]', value);156 this.page.afterUpload(node.id);157 return this.sendResponse(true);158 };159 Browser.prototype.select = function(page_id, id, value) {160 return this.sendResponse(this.node(page_id, id).select(value));161 };162 Browser.prototype.tag_name = function(page_id, id) {163 return this.sendResponse(this.node(page_id, id).tagName());164 };165 Browser.prototype.visible = function(page_id, id) {166 return this.sendResponse(this.node(page_id, id).isVisible());167 };168 Browser.prototype.disabled = function(page_id, id) {169 return this.sendResponse(this.node(page_id, id).isDisabled());170 };171 Browser.prototype.evaluate = function(script) {172 return this.sendResponse(this.page.evaluate("function() { return " + script + " }"));173 };174 Browser.prototype.execute = function(script) {175 this.page.execute("function() { " + script + " }");176 return this.sendResponse(true);177 };178 Browser.prototype.push_frame = function(name, timeout) {179 var _this = this;180 if (timeout == null) {181 timeout = new Date().getTime() + 2000;182 }183 if (this.page.pushFrame(name)) {184 if (this.page.currentUrl() === 'about:blank') {185 return this.setState('awaiting_frame_load');186 } else {187 return this.sendResponse(true);188 }189 } else {190 if (new Date().getTime() < timeout) {191 return setTimeout((function() {192 return _this.push_frame(name, timeout);193 }), 50);194 } else {195 return this.owner.sendError(new Poltergeist.FrameNotFound(name));196 }197 }198 };199 Browser.prototype.pages = function() {200 return this.sendResponse(this.page.pages());201 };202 Browser.prototype.pop_frame = function() {203 return this.sendResponse(this.page.popFrame());204 };205 Browser.prototype.push_window = function(name) {206 var sub_page,207 _this = this;208 sub_page = this.page.getPage(name);209 if (sub_page) {210 if (sub_page.currentUrl() === 'about:blank') {211 return sub_page.onLoadFinished = function() {212 sub_page.onLoadFinished = null;213 return _this.push_window(name);214 };215 } else {216 this.page_stack.push(this.page);217 this.page = sub_page;218 this.page_id += 1;219 return this.sendResponse(true);220 }221 } else {222 this.page_name = name;223 return this.setState('awaiting_sub_page');224 }225 };226 Browser.prototype.pop_window = function() {227 var prev_page;228 prev_page = this.page_stack.pop();229 if (prev_page) {230 this.page = prev_page;231 }232 return this.sendResponse(true);233 };234 Browser.prototype.mouse_event = function(page_id, id, name) {235 var node,236 _this = this;237 node = this.node(page_id, id);238 this.setState('mouse_event');239 this.last_mouse_event = node.mouseEvent(name);240 return setTimeout(function() {241 if (_this.state !== 'loading') {242 _this.setState('default');243 return _this.sendResponse(_this.last_mouse_event);244 }245 }, 5);246 };247 Browser.prototype.click = function(page_id, id) {248 return this.mouse_event(page_id, id, 'click');249 };250 Browser.prototype.double_click = function(page_id, id) {251 return this.mouse_event(page_id, id, 'doubleclick');252 };253 Browser.prototype.hover = function(page_id, id) {254 return this.mouse_event(page_id, id, 'mousemove');255 };256 Browser.prototype.click_coordinates = function(x, y) {257 this.page.sendEvent('click', x, y);258 return this.sendResponse({259 click: {260 x: x,261 y: y262 }263 });264 };265 Browser.prototype.drag = function(page_id, id, other_id) {266 this.node(page_id, id).dragTo(this.node(page_id, other_id));267 return this.sendResponse(true);268 };269 Browser.prototype.trigger = function(page_id, id, event) {270 this.node(page_id, id).trigger(event);271 return this.sendResponse(event);272 };273 Browser.prototype.equals = function(page_id, id, other_id) {274 return this.sendResponse(this.node(page_id, id).isEqual(this.node(page_id, other_id)));275 };276 Browser.prototype.reset = function() {277 this.resetPage();278 return this.sendResponse(true);279 };280 Browser.prototype.scroll_to = function(left, top) {281 this.page.setScrollPosition({282 left: left,283 top: top284 });285 return this.sendResponse(true);286 };287 Browser.prototype.send_keys = function(page_id, id, keys) {288 var key, sequence, _i, _len;289 this.node(page_id, id).mouseEvent('click');290 for (_i = 0, _len = keys.length; _i < _len; _i++) {291 sequence = keys[_i];292 key = sequence.key != null ? this.page["native"].event.key[sequence.key] : sequence;293 this.page.sendEvent('keypress', key);294 }295 return this.sendResponse(true);296 };297 Browser.prototype.render_base64 = function(format, full, selector) {298 var encoded_image;299 if (selector == null) {300 selector = null;301 }302 this.set_clip_rect(full, selector);303 encoded_image = this.page.renderBase64(format);304 return this.sendResponse(encoded_image);305 };306 Browser.prototype.render = function(path, full, selector) {307 var dimensions;308 if (selector == null) {309 selector = null;310 }311 dimensions = this.set_clip_rect(full, selector);312 this.page.setScrollPosition({313 left: 0,314 top: 0315 });316 this.page.render(path);317 this.page.setScrollPosition({318 left: dimensions.left,319 top: dimensions.top320 });321 return this.sendResponse(true);322 };323 Browser.prototype.set_clip_rect = function(full, selector) {324 var dimensions, document, rect, viewport, _ref;325 dimensions = this.page.validatedDimensions();326 _ref = [dimensions.document, dimensions.viewport], document = _ref[0], viewport = _ref[1];327 rect = full ? {328 left: 0,329 top: 0,330 width: document.width,331 height: document.height332 } : selector != null ? this.page.elementBounds(selector) : {333 left: 0,334 top: 0,335 width: viewport.width,336 height: viewport.height337 };338 this.page.setClipRect(rect);339 return dimensions;340 };341 Browser.prototype.set_paper_size = function(size) {342 this.page.setPaperSize(size);343 return this.sendResponse(true);344 };345 Browser.prototype.resize = function(width, height) {346 this.page.setViewportSize({347 width: width,348 height: height349 });350 return this.sendResponse(true);351 };352 Browser.prototype.network_traffic = function() {353 return this.sendResponse(this.page.networkTraffic());354 };355 Browser.prototype.clear_network_traffic = function() {356 this.page.clearNetworkTraffic();357 return this.sendResponse(true);358 };359 Browser.prototype.get_headers = function() {360 return this.sendResponse(this.page.getCustomHeaders());361 };362 Browser.prototype.set_headers = function(headers) {363 if (headers['User-Agent']) {364 this.page.setUserAgent(headers['User-Agent']);365 }366 this.page.setCustomHeaders(headers);367 return this.sendResponse(true);368 };369 Browser.prototype.add_headers = function(headers) {370 var allHeaders, name, value;371 allHeaders = this.page.getCustomHeaders();372 for (name in headers) {373 value = headers[name];374 allHeaders[name] = value;375 }376 return this.set_headers(allHeaders);377 };378 Browser.prototype.add_header = function(header, permanent) {379 if (!permanent) {380 this.page.addTempHeader(header);381 }382 return this.add_headers(header);383 };384 Browser.prototype.response_headers = function() {385 return this.sendResponse(this.page.responseHeaders());386 };387 Browser.prototype.cookies = function() {388 return this.sendResponse(this.page.cookies());389 };390 Browser.prototype.set_cookie = function(cookie) {391 phantom.addCookie(cookie);392 return this.sendResponse(true);393 };394 Browser.prototype.remove_cookie = function(name) {395 this.page.deleteCookie(name);396 return this.sendResponse(true);397 };398 Browser.prototype.cookies_enabled = function(flag) {399 phantom.cookiesEnabled = flag;400 return this.sendResponse(true);401 };402 Browser.prototype.set_http_auth = function(user, password) {403 this.page.setHttpAuth(user, password);404 return this.sendResponse(true);405 };406 Browser.prototype.set_js_errors = function(value) {407 this.js_errors = value;408 return this.sendResponse(true);409 };410 Browser.prototype.set_debug = function(value) {411 this._debug = value;412 return this.sendResponse(true);413 };414 Browser.prototype.exit = function() {415 return phantom.exit();416 };417 Browser.prototype.noop = function() {};418 Browser.prototype.browser_error = function() {419 throw new Error('zomg');420 };421 Browser.prototype.go_back = function() {422 if (this.page.canGoBack) {423 this.page.goBack();424 }425 return this.sendResponse(true);426 };427 Browser.prototype.go_forward = function() {428 if (this.page.canGoForward) {429 this.page.goForward();430 }431 return this.sendResponse(true);432 };433 return Browser;...

Full Screen

Full Screen

users.controlller.js

Source:users.controlller.js Github

copy

Full Screen

...10 } = req;11 try {12 console.log("get api token started...");13 if (!username || !password) {14 sendResponse(res, 400, {15 message: "Request Failed",16 error: "username & password are required",17 });18 return;19 }20 const apiUserDoc = await apiUserSchema.findOne({21 username: username,22 });23 if (!apiUserDoc) {24 sendResponse(res, 401, {25 message: "Request Failed",26 error: "Unauthorized",27 });28 return;29 }30 if (apiUserDoc && apiUserDoc.password) {31 if (apiUserDoc.password === password) {32 const token = jwt.sign(req.body, process.env.apiKey, {33 expiresIn: "5h",34 });35 sendResponse(res, 200, {36 message: "Success",37 token: `Bearer ${token}`,38 });39 } else {40 sendResponse(res, 401, {41 message: "Unauthorized",42 error: "Invalid password",43 });44 return;45 }46 }47 } catch (err) {48 sendResponse(res, 400, {49 message: "Request Failed",50 error: err.toString(),51 });52 }53};54exports.userSignUp = async (req, res) => {55 const {56 body: { email, password },57 } = req;58 try {59 if (!email || !password) {60 sendResponse(res, 400, {61 message: "Missing Parameters",62 error: " email or password missing",63 });64 return;65 }66 let reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;67 if (reg.test(email) === false) {68 sendResponse(res, 400, {69 message: "email format is invalid",70 });71 return;72 }73 let userDoc = await userSchema.findOne({ email: email });74 if (userDoc && userDoc.id) {75 sendResponse(res, 400, { message: "User Already Exists" });76 return;77 }78 let encryptedPwd = aes.encrypt(password, process.env.keyBase64);79 if (!encryptedPwd) {80 sendResponse(res, 400, {81 message: "An Error Occured",82 error: "Error in encrypting",83 });84 return;85 }86 req.body.encryptedPassword = encryptedPwd;87 const createDoc = await new userSchema(req.body).save();88 if (createDoc && createDoc.id) {89 sendResponse(res, 200, {90 message:91 "User Created Successfully.Login with encrypted Password to proceed further",92 encrytedPassword: encryptedPwd,93 });94 return;95 } else {96 sendResponse(res, 400, {97 message: "User not created",98 error: createDoc.toString(),99 });100 return;101 }102 } catch (error) {103 sendResponse(res, 400, {104 message: "An Unkown Error Occured",105 error: error.toString(),106 });107 return;108 }109};110exports.userLogin = async (req, res) => {111 const {112 body: { email, encryptedPassword },113 } = req;114 try {115 if (!email || !encryptedPassword) {116 sendResponse(res, 400, {117 message: "Missing Parameters",118 error: " email or password missing",119 });120 return;121 }122 let userDoc = await userSchema.findOne({ email: email });123 if (!userDoc || !userDoc.id) {124 sendResponse(res, 404, {125 message: "User not found",126 });127 return;128 }129 let decryptedPassword = aes.decrypt(130 encryptedPassword,131 process.env.keyBase64132 );133 if (!decryptedPassword) {134 sendResponse(res, 400, {135 message: "An Error Occured",136 error: "Error in decrypting",137 });138 return;139 }140 if (decryptedPassword == userDoc.password) {141 let accesstoken = crypto.randomBytes(100);142 accesstoken = accesstoken.toString("hex");143 userDoc.loggedInDevices.push({ token: accesstoken });144 await userSchema.findByIdAndUpdate(145 userDoc.id,146 {147 $set: {148 loggedInDevices: userDoc.loggedInDevices,149 },150 },151 { new: true },152 (err, doc) => {153 if (doc && doc.id) {154 sendResponse(res, 200, {155 message: "Login Successfull",156 logintoken: accesstoken,157 });158 return;159 } else {160 sendResponse(res, 400, {161 message: "Login Failure",162 error: err,163 });164 }165 }166 );167 } else {168 sendResponse(res, 401, {169 message: "Unauthorized",170 error: "Invalid Password",171 });172 return;173 }174 } catch (error) {175 sendResponse(res, 400, {176 message: "An Unkown Error Occured",177 error: error.toString(),178 });179 return;180 }181};182exports.addEmployee = async (req, res) => {183 const { isLoggedIn, body } = req;184 try {185 if (!isLoggedIn) {186 sendResponse(res, 401, {187 message: "Unauthorized",188 error: "User not logged in",189 });190 return;191 }192 if (193 !body.email ||194 !body.name ||195 !body.mobileNo ||196 !body.skills ||197 !body.skills.length ||198 !body.role ||199 !["Admin", "User"].includes(body.role) ||200 !body.dob ||201 !["Male", "Female", "TransGender"].includes(body.gender)202 ) {203 sendResponse(res, 400, {204 message: "Invalid Parameters",205 error: "Parameters missinf in body",206 });207 return;208 }209 let newDoc = await new employeeSchema(req.body).save();210 if (newDoc && newDoc.id) {211 sendResponse(res, 200, { message: "User created successfully" });212 return;213 } else {214 sendResponse(res, 400, {215 message: "User not created",216 error: newDoc.toString(),217 });218 return;219 }220 } catch (error) {221 sendResponse(res, 400, {222 message: "An Unkown Error Occured",223 error: error.toString(),224 });225 return;226 }227};228exports.editEmployee = async (req, res) => {229 const { isLoggedIn, body } = req;230 try {231 if (!isLoggedIn) {232 sendResponse(res, 401, {233 message: "Unauthorized",234 error: "User not logged in",235 });236 return;237 }238 if (!body.id) {239 sendResponse(res, 401, {240 message: "Missing Parameters",241 error: "id missing in body",242 });243 return;244 }245 if (body.role && !["Admin", "User"].includes(body.role)) {246 sendResponse(res, 401, {247 message: "Invalid Parameters",248 error: "role should be either Admin or User only",249 });250 return;251 }252 if (253 body.gender &&254 !["Male", "Female", "TransGender"].includes(body.gender)255 ) {256 sendResponse(res, 401, {257 message: "Invalid Parameters",258 error: "gender should be either Male or Female or TransGender only",259 });260 return;261 }262 let employeeDoc = await employeeSchema.findOne({_id : body.id})263 if (!employeeDoc || !employeeDoc.id) {264 sendResponse(res, 404, { message: "User does not exist" });265 return;266 }267 employeeDoc.name = body.name ? body.name : employeeDoc.name;268 employeeDoc.email = body.email ? body.email : employeeDoc.email;269 employeeDoc.mobileNo = body.mobileNo ? body.mobileNo : employeeDoc.mobileNo;270 employeeDoc.skills = body.skills ? body.skills : employeeDoc.skills;271 employeeDoc.role = body.role ? body.role : employeeDoc.role;272 employeeDoc.DOB = body.DOB ? body.DOB : employeeDoc.DOB;273 employeeDoc.gender = body.gender ? body.gender : employeeDoc.gender;274 let updateDoc = await employeeSchema.findByIdAndUpdate(275 employeeDoc.id,276 {277 $set: employeeDoc,278 },279 {280 new: true,281 }282 );283 if (updateDoc && updateDoc.id) {284 sendResponse(res, 200, { message: "User updated successfully" });285 return;286 } else {287 sendResponse(res, 400, {288 message: "User update failed",289 error: updateDoc.toString(),290 });291 return;292 }293 } catch (error) {294 sendResponse(res, 400, {295 message: "An Unkown Error Occured",296 error: error.toString(),297 });298 return;299 }300};301exports.deleteEmployee = async (req, res) => {302 const { isLoggedIn, body } = req;303 try {304 if (!isLoggedIn) {305 sendResponse(res, 401, {306 message: "Unauthorized",307 error: "User not logged in",308 });309 return;310 }311 if (!body.id) {312 sendResponse(res, 401, {313 message: "Missing Parameters",314 error: "id missing in body",315 });316 return;317 }318 let employeeDoc = employeeSchema.findById(body.id);319 if (!employeeDoc || !employeeDoc.id) {320 sendResponse(res, 404, { message: "Employee does not exist" });321 return;322 }323 await employeeSchema.findByIdAndDelete(body.id);324 sendResponse(res, 200, { message: "User deleted successfully" });325 } catch (error) {326 sendResponse(res, 400, {327 message: "An Unkown Error Occured",328 error: error.toString(),329 });330 return;331 }332};333exports.getAllEmployee = async (req,res) =>{334 const { isLoggedIn, body } = req;335 try {336 if (!isLoggedIn) {337 sendResponse(res, 401, {338 message: "Unauthorized",339 error: "User not logged in",340 });341 return;342 }343 let employeesDoc = await employeeSchema.find();344 if(employeesDoc && employeesDoc.length){345 sendResponse(res,200,{message:"Success", result : employeesDoc})346 }347 if(employeesDoc && !employeesDoc.length){348 sendResponse(res,404,{message:"No records found"})349 }350 } catch (error) {351 sendResponse(res, 400, {352 message: "An Unkown Error Occured",353 error: error.toString(),354 });355 return;356 }...

Full Screen

Full Screen

background.js

Source:background.js Github

copy

Full Screen

...23 case InternalMessageTypes.PROMPT_IDENTITY: Background.promptIdentity(sendResponse, request.payload); break;24 case InternalMessageTypes.PROVE_IDENTITY: Background.proveIdentity(sendResponse, request.payload); break;25 case InternalMessageTypes.RECLAIM: Background.reclaim(sendResponse); break;26 case InternalMessageTypes.DESTROY_KEYCHAIN: Background.destroyKeychain(sendResponse); break;27 // default: sendResponse(null);28 }29 })30 }31 static setSeed(sendResponse, s){ seed = s; sendResponse(); }32 static load(sendResponse){33 StorageService.get().then(scatter => {34 console.log(scatter)35 sendResponse(scatter)36 })37 }38 static open(sendResponse, name){39 StorageService.get().then(scatter => {40 scatter.data.keychain.wallets.map(x => x.lastOpened = false);41 scatter.data.keychain.wallets.find(x => x.name === name).lastOpened = true;42 sendResponse(scatter);43 })44 }45 static unlock(sendResponse){46 StorageService.get().then(scatter => {47 scatter.unlock();48 StorageService.save(scatter).then(saved => {49 sendResponse(scatter);50 })51 })52 }53 static lock(sendResponse){54 StorageService.get().then(scatter => {55 scatter.lock();56 StorageService.save(scatter).then(saved => {57 seed = '';58 sendResponse(scatter);59 })60 })61 }62 static isLocked(sendResponse){63 sendResponse(seed.length === 0)64 }65 static requestUnlock(sendResponse){66 if(seed.length !== 0) this.isLocked(sendResponse);67 else Background.openPrompt(InternalMessageTypes.REQUEST_UNLOCK, {responder:sendResponse});68 }69 static keychain(sendResponse){70 StorageService.get().then(scatter => {71 scatter = this.decrypt(scatter);72 sendResponse(scatter);73 });74 }75 static publicToPrivate(sendResponse, publicKey){76 StorageService.get().then(scatter => {77 scatter = this.decrypt(scatter);78 let keys = scatter.data.keychain.wallets.map(x => x.keyPairs).reduce((a,b) => a.concat(b), []);79 let possiblePrivateKey = keys.find(x => x.publicKey === publicKey);80 if(possiblePrivateKey) sendResponse(possiblePrivateKey.privateKey);81 else sendResponse(null)82 })83 }84 static update(sendResponse, scatter){85 console.log('updating', scatter);86 //TODO: Only update editable things, to preserve integrity87 scatter = ScatterData.fromJson(scatter);88 scatter.data.keychain.wallets.map(x => {89 x.prepareForSaving();90 x.encrypt(seed);91 });92 StorageService.save(scatter).then(saved => {93 sendResponse(scatter)94 })95 }96 static promptAuthorization(sendResponse, message){97 Background.openPrompt(InternalMessageTypes.PROMPT_AUTH, {98 responder:sendResponse,99 network:message.network,100 transaction:message.payload.transaction,101 permission:message.payload.permission,102 allowedAccounts:(message.payload.hasOwnProperty('allowedAccounts')) ? message.payload.allowedAccounts : null103 }, 600);104 }105 static promptIdentity(sendResponse, message){106 Background.openPrompt(InternalMessageTypes.PROMPT_IDENTITY, {107 responder:sendResponse,108 network:message.network,109 location:message.payload.location110 }, 600);111 }112 static proveIdentity(sendResponse, message){113 sendResponse(null);114 }115 /***116 * Happens every time a user sends coins.117 * If there is an unreclaimed account lingering it will be paid for.118 * @param sendResponse119 */120 static reclaim(sendResponse){121 //TODO: Send notification about reclaiming ( from background to ui, needs to be persisted to queue for next time the extension is open )122 StorageService.get().then(scatter => {123 let keyPair = scatter.data.keychain.wallets.map(x => x.keyPairs).reduce((a,b) => a.concat(b), []).find(x => !x.reclaimed);124 if(keyPair && keyPair.accounts.length){125 this.publicToPrivate((privateKey) => {126 if(!privateKey) {127 console.warn('Something is wrong with private key encryption');128 return false;129 }130 AccountService.reclaim(keyPair.accounts[0], privateKey, keyPair.network)131 .then(reclaimed => {132 if(reclaimed) {133 keyPair.reclaimed = true;134 Background.update(sendResponse, scatter);135 }136 else sendResponse(false);137 })138 .catch(x => sendResponse(false))139 }, keyPair.publicKey)140 } else sendResponse(false);141 })142 }143 static destroyKeychain(sendResponse){144 chrome.storage.local.clear();145 seed = '';146 sendResponse({});147 }148 static decrypt(scatter){149 scatter = ScatterData.fromJson(scatter);150 scatter.data.keychain.wallets.map(x => {151 x.decrypt(seed);152 });153 return scatter;154 }155 static openPrompt(type, payload = {}, height = 500){156 let rightmost = window.screen.availWidth-5;157 let popup = window.open(chrome.runtime.getURL('prompt.html'), 'ScatterPrompt', `width=360,resizable=0,height=${height},dependent=true,top=50,left=${rightmost}`);158 console.log(type, payload);159 popup.scatterPrompt = { type, payload };160 }...

Full Screen

Full Screen

OwnerController.js

Source:OwnerController.js Github

copy

Full Screen

...4module.exports = {5 add: async function (req, res) {6 let result = await ownerServ.add(req.body);7 if(result.error){8 utils.sendResponse(result,req,res.status(401));9 }10 else{11 utils.sendResponse(result,req,res.status(200));12 }13 },14 check: async function (req,res){15 let result = await ownerServ.check(req.body);16 if(result.error){17 utils.sendResponse(result,req,res.status(401));18 }19 else{20 utils.sendResponse(result,req,res.status(200));21 }22 },23 edit: async function (req, res) {24 let result = await ownerServ.update(req);25 utils.sendResponse(result, req, res);26 },27 delete: async function (req, res) {28 let result = await ownerServ.delete(req);29 utils.sendResponse(result, req, res);30 },31 uploadavatar: async function (req,res) {32 let result = await ownerServ.uploadavatar(req);33 utils.sendResponse(result,req,res);34 },35 // get: async function (req, res) {36 // let {37 // id38 // } = req.params;39 // let result = await ownerServ.get(id);40 // utils.sendResponse(result, req, res);41 // },42 getProfile: async function (req, res) {43 let result = await ownerServ.getProfile(req);44 utils.sendResponse(result, req, res);45 },46 list: async function (req, res) {47 let result = await ownerServ.list();48 utils.sendResponse(result, req, res);49 },50 login: async function (req, res) {51 let result = await ownerServ.login(req.body)52 if(result.error){53 utils.sendResponse(result,req,res.status(401));54 }55 else{56 utils.sendResponse(result,req,res.status(200));57 }58 },59 forgetPassword: async function (req, res) {60 let result = await ownerServ.forgotPassword(req.body.email);61 utils.sendResponse(result, req, res);62 },63 resetPassword: async function (req, res) {64 let result = await ownerServ.resetPassword(req.body.passcode, req.body.email);65 if(result.error){66 utils.sendResponse(result,req,res.status(401));67 }68 else{69 utils.sendResponse(result,req,res.status(200));70 } 71 },72 changePassword: async function (req, res) {73 let result = await ownerServ.changePassword(req);74 if(result.error){75 utils.sendResponse(result,req,res.status(401));76 }77 else{78 utils.sendResponse(result,req,res.status(200));79 } 80 },81 register: async function (req, res) {82 let result = await ownerServ.register(req.body.phone);83 utils.sendResponse(result, req, res);84 },85 verify: async function (req, res) {86 let result = await ownerServ.register(req.body.otp);87 utils.sendResponse(result, req, res);88 },89 listofemployees: async function (req,res) {90 let result = await ownerServ.listofemployees(req);91 utils.sendResponse(result,req,res);92 },93 logout: async function (req, res) {94 let result = await ownerServ.logout(req);95 utils.sendResponse(result, req, res);96 },...

Full Screen

Full Screen

EmployeeController.js

Source:EmployeeController.js Github

copy

Full Screen

...3module.exports = {4 add: async function (req, res) {5 let result = await employeeServ.add(req.body);6 if(result.error){7 utils.sendResponse(result,req,res.status(400));8 }9 else{10 utils.sendResponse(result,req,res.status(200));11 }12 },13 check: async function (req,res){14 let result = await employeeServ.check(req.body);15 if(result.error){16 utils.sendResponse(result,req,res.status(401));17 }18 else{19 utils.sendResponse(result,req,res.status(200));20 }21 },22 23 edit: async function (req, res) {24 let result = await employeeServ.update(req);25 utils.sendResponse(result, req, res);26 },27 getProfile: async function (req, res) {28 let result = await employeeServ.getProfile(req);29 utils.sendResponse(result, req, res);30 },31 delete: async function (req, res) {32 let result = await employeeServ.delete(req);33 utils.sendResponse(result, req, res);34 },35 get: async function (req, res) {36 let {37 id38 } = req.params;39 let result = await employeeServ.get(id);40 utils.sendResponse(result, req, res);41 },42 list: async function (req, res) {43 let result = await employeeServ.list();44 utils.sendResponse(result, req, res);45 },46 login: async function (req, res) {47 let result = await employeeServ.login(req.body)48 if(result.error){49 utils.sendResponse(result,req,res.status(401));50 }51 else{52 utils.sendResponse(result,req,res.status(200));53 }54 },55 forgetPassword: async function (req, res) {56 let result = await employeeServ.forgotPassword(req.body.email);57 utils.sendResponse(result, req, res);58 },59 resetPassword: async function (req, res) {60 let result = await employeeServ.resetPassword(req.body.passcode, req.body.password, req.body.email);61 utils.sendResponse(result, req, res);62 },63 register: async function (req, res) {64 let result = await employeeServ.register(req.body.phone);65 utils.sendResponse(result, req, res);66 },67 verify: async function (req, res) {68 let result = await employeeServ.register(req.body.otp);69 utils.sendResponse(result, req, res);70 },71 logout: async function (req, res) {72 let result = await employeeServ.logout(req);73 utils.sendResponse(result, req, res);74 },75 getTasks: async function (req, res) {76 let result = await employeeServ.getTasks(req);77 utils.sendResponse(result, req, res);78 },79 editTask: async function (req, res) {80 let {81 id82 } = req.params;83 let result = await employeeServ.editTask(req.body, id);84 utils.sendResponse(result, req, res);85 }...

Full Screen

Full Screen

visitor.controller.js

Source:visitor.controller.js Github

copy

Full Screen

...4module.exports = {5 getAllVisitor: (req, res) => {6 // db transaction implementation7 Visitor.find({}).then( result => {8 sendResponse(res, 200, result, "Success fetching all visitors")9 }).catch( err => {10 sendResponse(res, 500, [], err.message)11 })12 },13 getVisitor: (req, res) => {14 // db transaction implementation15 let param = req.params.id16 Visitor.findById(param)17 .then( result => {18 sendResponse(res, 200, result, "Success fetching specified visitor")19 }).catch( err => {20 sendResponse(res, 500, [], err.message)21 })22 },23 postVisitor: (req, res) => {24 // db transaction implementation25 Visitor.create({26 npm: req.body.npm,27 name: req.body.name,28 faculty: req.body.faculty,29 major: req.body.major30 }).then( visitor => {31 sendResponse(res, 201, visitor, "New Visitor added!")32 }).catch( err => {33 sendResponse(res, 400, {}, err.message)34 })35 },36 putVisitor: (req, res) => {37 // db transaction implementation38 let param = req.params.id39 Visitor.findByIdAndUpdate(param, {40 npm: req.body.npm,41 name: req.body.name,42 faculty: req.body.faculty,43 major: req.body.major44 }).then( result => {45 if(Object.keys(result).length > 0) {46 sendResponse(res, 200, result, "Visitor successfully updated")47 } else {48 sendResponse(res, 500, {}, "Failed to update visitor")49 }50 }).catch( err => {51 sendResponse(res, 500, {}, err.message)52 })53 }, 54 deleteVisitor: (req, res) => {55 // db transaction implementation56 let param = req.params.id57 Visitor.findById(param)58 .then( visitor => {59 Visitor.deleteOne({60 _id: param61 }).orFail()62 .then( result => {63 sendResponse(res, 200, {}, "Visitor successfully deleted")64 }).catch( err => {65 sendResponse(res, 500, {}, "Failed to delete visitor")66 })67 }).catch( err => {68 sendResponse(res, 500, {}, `Failed to delete visitor: ${err.message}`)69 })70 }...

Full Screen

Full Screen

borrow.controller.js

Source:borrow.controller.js Github

copy

Full Screen

...4module.exports = {5 getAllBorrow: (req, res) => {6 // db transaction implementation7 Borrow.find({}).then( result => {8 sendResponse(res, 200, result, "Success fetching all borrows")9 }).catch( err => {10 sendResponse(res, 500, [], err.message)11 })12 },13 getBorrow: (req, res) => {14 // db transaction implementation15 let param = req.params.id16 Borrow.findById(param)17 .then( result => {18 sendResponse(res, 200, result, "Success fetching specified borrow")19 }).catch( err => {20 sendResponse(res, 500, [], err.message)21 })22 },23 postBorrow: (req, res) => {24 // db transaction implementation25 Borrow.create({26 id: req.body.id,27 npm: req.body.npm,28 isbn: req.body.isbn,29 borrow_date: req.body.borrow_date30 }).then( borrow => {31 sendResponse(res, 201, borrow, "New borrow added!")32 }).catch( err => {33 sendResponse(res, 400, {}, err.message)34 })35 },36 putBorrow: (req, res) => {37 // db transaction implementation38 let param = req.params.id39 Borrow.findByIdAndUpdate(param, {40 id: req.body.id,41 npm: req.body.npm,42 isbn: req.body.isbn,43 borrow_date: req.body.borrow_date44 }).then( result => {45 if(Object.keys(result).length > 0) {46 sendResponse(res, 200, result, "Borrow successfully updated")47 } else {48 sendResponse(res, 500, {}, "Failed to update borrow")49 }50 }).catch( err => {51 sendResponse(res, 500, {}, err.message)52 })53 }, 54 deleteBorrow: (req, res) => {55 // db transaction implementation56 let param = req.params.id57 Borrow.findById(param)58 .then( borrow => {59 Borrow.deleteOne({60 _id: param61 }).orFail()62 .then( result => {63 sendResponse(res, 200, {}, "Borrow successfully deleted")64 }).catch( err => {65 sendResponse(res, 500, {}, "Failed to delete borrow")66 })67 }).catch( err => {68 sendResponse(res, 500, {}, `Failed to delete borrow: ${err.message}`)69 })70 }...

Full Screen

Full Screen

book.controller.js

Source:book.controller.js Github

copy

Full Screen

...4module.exports = {5 getAllBook: (req, res) => {6 // db transaction implementation7 Book.find({}).then( result => {8 sendResponse(res, 200, result, "Success fetching all books")9 }).catch( err => {10 sendResponse(res, 500, [], err.message)11 })12 },13 getBook: (req, res) => {14 // db transaction implementation15 let param = req.params.id16 Book.findById(param)17 .then( result => {18 sendResponse(res, 200, result, "Success fetching specified book")19 }).catch( err => {20 sendResponse(res, 500, [], err.message)21 })22 },23 postBook: (req, res) => {24 // db transaction implementation25 Book.create({26 isbn: req.body.isbn,27 book_title: req.body.book_title,28 author: req.body.author,29 publisher: req.body.publisher30 }).then( book => {31 sendResponse(res, 201, book, "New book added!")32 }).catch( err => {33 sendResponse(res, 400, {}, err.message)34 })35 },36 putBook: (req, res) => {37 // db transaction implementation38 let param = req.params.id39 Book.findByIdAndUpdate(param, {40 isbn: req.body.isbn,41 book_title: req.body.book_title,42 author: req.body.author,43 publisher: req.body.publisher44 }).then( result => {45 if(Object.keys(result).length > 0) {46 sendResponse(res, 200, result, "Book successfully updated")47 } else {48 sendResponse(res, 500, {}, "Failed to update book")49 }50 }).catch( err => {51 sendResponse(res, 500, {}, err.message)52 })53 }, 54 deleteBook: (req, res) => {55 // db transaction implementation56 let param = req.params.id57 Book.findById(param)58 .then( book => {59 Book.deleteOne({60 _id: param61 }).orFail()62 .then( result => {63 sendResponse(res, 200, {}, "Book successfully deleted")64 }).catch( err => {65 sendResponse(res, 500, {}, "Failed to delete book")66 })67 }).catch( err => {68 sendResponse(res, 500, {}, `Failed to delete book: ${err.message}`)69 })70 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.contains('type').click()4 cy.url().should('include', '/commands/actions')5 cy.get('.action-email')6 .type('

Full Screen

Using AI Code Generation

copy

Full Screen

1cy.request({2 body: {3 }4}).then((response) => {5 expect(response.body).to.have.property('name', 'morpheus')6 expect(response.body).to.have.property('job', 'leader')7})8cy.request({9 body: {10 }11}).then((response) => {12 expect(response.body).to.have.property('name', 'morpheus')13 expect(response.body).to.have.property('job', 'leader')14})15cy.request({16 body: {17 }18}).then((response) => {19 expect(response.body).to.have.property('name', 'morpheus')20 expect(response.body).to.have.property('job', 'leader')21})22cy.request({23 body: {24 }25}).then((response) => {26 expect(response.body).to.have.property('name', 'morpheus')27 expect(response.body).to.have.property('job', 'leader')28})29cy.request({30 body: {

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('test', () => {2 it('test', () => {3 }).then((response) => {4 expect(response.body).to.have.property('test');5 });6 });7});8const express = require('express');9const app = express();10const port = 3000;11app.use(express.json());12app.post('/test', (req, res) => {13 res.send({ test: 'test' });14});15app.listen(port, () => {16});17> CypressError: cy.request() failed trying to load:18> Headers: {“Content-Type”:“application/json”}19> Body: {“test”:“test”}

Full Screen

Using AI Code Generation

copy

Full Screen

1cy.sendResponse({2 body: {3 }4})5Cypress.Commands.add('sendResponse', (options) => {6 cy.window().then((win) => {7 win.postMessage({8 }, '*')9 })10})11module.exports = (on, config) => {12 on('task', {13 'sendResponse': (options) => {14 return new Promise((resolve, reject) => {15 cy.window().then((win) => {16 win.postMessage({17 }, '*')18 resolve()19 })20 })21 }22 })23}24Cypress.on('window:before:load', (win) => {25 win.addEventListener('message', (event) => {26 if (event.data.type === 'CYPRESS_SEND_RESPONSE') {27 event.source.close()28 cy.task('sendResponse', event.data.options)29 }30 })31})32Cypress.on('window:before:load', (win) => {33 win.addEventListener('message', (event) => {34 if (event.data.type === 'CYPRESS_SEND_RESPONSE') {35 cy.task('sendResponse', event.data.options)36 }37 })38})39Cypress.on('window:before:load', (win) => {40 win.addEventListener('message', (event) => {41 if (event.data.type === 'CYPRESS_SEND_RESPONSE') {42 cy.task('sendResponse', event.data.options)43 }44 })45})46Cypress.on('window:before:load', (win) => {47 win.addEventListener('message', (event) => {48 if (event.data.type === 'CYPRESS_SEND_RESPONSE') {49 cy.task('sendResponse', event.data.options)50 }51 })52})53Cypress.on('window:before:load', (win) => {54 win.addEventListener('message', (event) => {55 if (event.data.type === 'CYPRESS_SEND_RESPONSE') {56 cy.task('sendResponse', event.data.options

Full Screen

Using AI Code Generation

copy

Full Screen

1cy.server();2cy.route({3 onRequest: (xhr) => {4 xhr.sendResponse({5 body: {6 }7 });8 }9});10cy.server();11cy.route({12 onRequest: (xhr) => {13 xhr.sendResponse({14 body: {15 }16 });17 }18});19cy.server();20cy.route({21 onRequest: (xhr) => {22 xhr.sendResponse({23 body: {24 }25 });26 }27});28cy.server();29cy.route({30 onRequest: (xhr) => {31 xhr.sendResponse({32 body: {33 }34 });35 }36});37cy.server();38cy.route({39 onRequest: (xhr) => {40 xhr.sendResponse({41 body: {42 }43 });44 }45});46cy.server();47cy.route({48 onRequest: (xhr) => {49 xhr.sendResponse({50 body: {51 }52 });53 }54});55cy.server();56cy.route({57 onRequest: (xhr) => {58 xhr.sendResponse({59 body: {60 }61 });62 }63});64cy.server();65cy.route({

Full Screen

Using AI Code Generation

copy

Full Screen

1cy.get('button').click()2cy.on('window:confirm', (str) => {3 return true;4});5const { sendResponse } = require('@cypress/browserify-preprocessor')6module.exports = (on, config) => {7 on('file:preprocessor', sendResponse)8}9const { sendResponse } = require('@cypress/browserify-preprocessor')10module.exports = (on, config) => {11 on('file:preprocessor', sendResponse)12}13const { sendResponse } = require('@cypress/browserify-preprocessor')14module.exports = (on, config) => {15 on('file:preprocessor', sendResponse)16}17const { sendResponse } = require('@cypress/browserify-preprocessor')18module.exports = (on, config) => {19 on('file:preprocessor', sendResponse)20}21const { sendResponse } = require('@cypress/browserify-preprocessor')22module.exports = (on, config) => {23 on('file:preprocessor', sendResponse)24}25const { sendResponse } = require('@cypress/browserify-preprocessor')26module.exports = (on, config) => {27 on('file:preprocessor', sendResponse)28}29const { sendResponse } = require('@cypress/browserify-preprocessor')30module.exports = (on, config) => {31 on('file:preprocessor', sendResponse)32}33const { sendResponse } = require('@cypress/browserify-preprocessor')34module.exports = (on, config) => {35 on('file:preprocessor', sendResponse)36}37const { sendResponse } = require('@

Full Screen

Cypress Tutorial

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.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

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.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress 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