Best JavaScript code snippet using devicefarmer-stf
triggersDAO.js
Source:triggersDAO.js
1let dbConfig = require("../Utilities/mysqlConfig");2//Models/triggers.js3let updatetokensOnUserNameUpdate = (callback) => {4 console.log(`CREATE TRIGGER IF EXISTS updatetokensOnUserNameUpdate`);5 dbConfig.getDB().query(`DROP TRIGGER IF EXISTS updatetokensOnUserNameUpdate`);6 dbConfig.getDB().query(`CREATE TRIGGER updatetokensOnUserNameUpdate7 AFTER UPDATE 8 ON users FOR EACH ROW 9 BEGIN 10 IF NEW.name != OLD.name THEN11 UPDATE tokens SET userName = NEW.name WHERE userId = NEW.id; 12 END IF;13 END`, callback); 14}15//Models/triggers.js16let updatetokensOnShopNameUpdate = (callback) => {17 console.log(`CREATE TRIGGER IF EXISTS updatetokensOnShopNameUpdate`);18 dbConfig.getDB().query(`DROP TRIGGER IF EXISTS updatetokensOnShopNameUpdate`);19 dbConfig.getDB().query(`CREATE TRIGGER updatetokensOnShopNameUpdate20 AFTER UPDATE 21 ON shops FOR EACH ROW 22 BEGIN 23 IF NEW.shopName != OLD.shopName THEN24 UPDATE tokens SET shopName = NEW.shopName WHERE shopId = NEW.id; 25 END IF;26 END`, callback); 27}28//Models/triggers.js29let updateRequestsOnShopUpdate = (callback) => {30 console.log(`CREATE TRIGGER IF EXISTS updateRequestsOnShopUpdate`);31 dbConfig.getDB().query(`DROP TRIGGER IF EXISTS updateRequestsOnShopUpdate`);32 dbConfig.getDB().query(`CREATE TRIGGER updateRequestsOnShopUpdate33 AFTER UPDATE 34 ON shops FOR EACH ROW 35 BEGIN 36 IF NEW.shopName != OLD.shopName OR NEW.address != OLD.address THEN37 UPDATE request SET shopName = NEW.shopName, address = NEW.address WHERE shopId = OLD.id; 38 END IF;39 END`, callback); 40}41//Models/triggers.js42let updateRequestsOnAuthUpdate = (callback) => {43 console.log(`CREATE TRIGGER IF EXISTS updateRequestsOnAuthUpdate`);44 dbConfig.getDB().query(`DROP TRIGGER IF EXISTS updateRequestsOnAuthUpdate`);45 dbConfig.getDB().query(`CREATE TRIGGER updateRequestsOnAuthUpdate46 AFTER UPDATE 47 ON localAuths FOR EACH ROW 48 BEGIN 49 IF NEW.mobileNumber != OLD.mobileNumber THEN50 UPDATE request SET authMobile = NEW.mobileNumber WHERE authId = NEW.id; 51 END IF;52 END`, callback); 53}54//Models/triggers.js55let updateShopBookingOnInsertInToken = (callback) => {56 console.log(`CREATE TRIGGER IF EXISTS updateShopBookingOnInsertInToken`);57 dbConfig.getDB().query(`DROP TRIGGER IF EXISTS updateShopBookingOnInsertInToken`);58 dbConfig.getDB().query(`CREATE TRIGGER updateShopBookingOnInsertInToken59 AFTER INSERT 60 ON tokens FOR EACH ROW 61 BEGIN 62 IF NEW.status = 1 THEN63 UPDATE shopBookings SET capacityLeft = capacityLeft - 1 WHERE shopId = NEW.shopId AND date = NEW.date AND slotNumber = NEW.slotNumber; 64 END IF;65 IF NEW.verified = 1 THEN66 UPDATE shopBookings SET tokensVerified = tokensVerified + 1 WHERE shopId = NEW.shopId AND date = NEW.date AND slotNumber = NEW.slotNumber;67 END IF;68 END`, callback); 69}70//Models/triggers.js71let updateShopBookingOnUpdateInToken = (callback) => {72 console.log(`CREATE TRIGGER IF EXISTS updateShopBookingOnUpdateInToken`);73 dbConfig.getDB().query(`DROP TRIGGER IF EXISTS updateShopBookingOnUpdateInToken`);74 dbConfig.getDB().query(`CREATE TRIGGER updateShopBookingOnUpdateInToken75 AFTER UPDATE76 ON tokens FOR EACH ROW77 BEGIN78 IF NEW.status = 0 AND OLD.status = 1 THEN 79 UPDATE shopBookings SET capacityLeft = capacityLeft + 1 WHERE shopId = OLD.shopId AND date = OLD.date AND slotNumber = OLD.slotNumber;80 END IF;81 IF NEW.status = 1 AND OLD.status = 2 THEN 82 UPDATE shopBookings SET capacityLeft = GREATEST(capacityLeft - 1, 0) WHERE shopId = NEW.shopId AND date = NEW.date AND slotNumber = NEW.slotNumber;83 END IF;84 IF NEW.verified = 1 AND OLD.verified = 0 THEN85 UPDATE shopBookings SET tokensVerified = tokensVerified + 1 WHERE shopId = NEW.shopId AND date = NEW.date AND slotNumber = NEW.slotNumber;86 END IF;87 END `, callback); 88}89//Models/triggers.js90let updateShopOnResolveRequest = (callback) => {91 console.log(`CREATE TRIGGER IF EXISTS updateShopOnResolveRequest`);92 dbConfig.getDB().query(`DROP TRIGGER IF EXISTS updateShopOnResolveRequest`);93 dbConfig.getDB().query(`CREATE TRIGGER updateShopOnResolveRequest94 AFTER UPDATE95 ON request FOR EACH ROW96 BEGIN97 IF NEW.status = 1 AND OLD.status = 2 THEN 98 IF NEW.capacity = 0 THEN99 UPDATE shops SET authVerification = 1, openingTimeApp = LEAST(openingTimeApp, NEW.openingTime), closingTimeApp = GREATEST(closingTimeApp, NEW.closingTime) WHERE id = NEW.shopId;100 ELSE101 UPDATE shops SET authVerification = 1, capacityApp = NEW.capacity WHERE id = NEW.shopId;102 END IF;103 END IF;104 END `, callback); 105}106module.exports = {107 updatetokensOnUserNameUpdate : updatetokensOnUserNameUpdate,108 updatetokensOnShopNameUpdate : updatetokensOnShopNameUpdate,109 updateShopBookingOnInsertInToken : updateShopBookingOnInsertInToken,110 updateShopBookingOnUpdateInToken : updateShopBookingOnUpdateInToken,111 updateRequestsOnShopUpdate : updateRequestsOnShopUpdate,112 updateRequestsOnAuthUpdate : updateRequestsOnAuthUpdate,113 updateShopOnResolveRequest : updateShopOnResolveRequest...
nec-compress.js
Source:nec-compress.js
...40 postUpdateTokens(t,l);41 return t;42 }43 if(t[9] == l[9]){ t = t.slice(0,9); }44 updateTokens(t,l,1,2);45 if(t[3]==l[3] && t[4]==l[4] && t[5]==l[5] )46 {47 t[0]=compress_map["g1"];48 updateTokens(t,l,6,3);49 postUpdateTokens(t,l,6,3,3);50 t.splice(3,3);51 return t;52 }53 if(t[3]==l[6] && t[4]==l[7] && t[5]==l[8] )54 {55 t[0]=compress_map["g3"];56 updateTokens(t,l,6,3);57 postUpdateTokens(t,l,6,3,3);58 t.splice(3,3);59 return t;60 }61 if(t[6]==l[3] && t[7]==l[4] && t[8]==l[5] )62 {63 t[0]=compress_map["g2"];64 updateTokens(t,l,3,3);65 t.splice(6,3);66 return t;67 }68 if(t[6]==l[6] && t[7]==l[7] && t[8]==l[8] )69 {70 t[0]=compress_map["g4"];71 updateTokens(t,l,3,3);72 t.splice(6,3);73 return t;74 }75 if(t[6]==t[3] && t[7]==t[4])76 {77 t[0]=compress_map["g5"];78 updateTokens(t,l,3,3);79 updateTokens(t,l,8,1);80 t.splice(6,2);81 return t;82 }83 if(t[7]==t[4] && t[8]==t[5])84 {85 t[0]=compress_map["g6"];86 updateTokens(t,l,3,4);87 t.splice(7,2);88 return t;89 }90 if(t[6]==t[3] && t[8]==t[5])91 {92 t[0]=compress_map["g7"];93 updateTokens(t,l,3,2);94 updateTokens(t,l,7,2);95 t.splice(5,2);96 return t;97 }98 updateTokens(t,l,3,6);99 postUpdateTokens(t,l,6,3,3);100 return t;101 },102 general: function(t){103 for (var i=1; i!=t.length; ++i)104 {105 if(t[i]=="0")106 {107 t[i] = "";108 }109 }110 t[0] = compress_map[t[0]];111 return t;112 },
...
WallPage.cy.ts
Source:WallPage.cy.ts
1import { validTokens } from '../utils/tokens'2import { dataReturned } from '../utils/dataReturned'3import {4 BUTTON_LOGOUT,5 BUTTON_POST_CREATION,6 BUTTON_SIGN_IN_NAVIGATE,7 HOME_ROUTE,8 INPUT_POST_CREATION,9 POST,10 POSTS_ENDPOINT,11 TOKEN_ENDPOINT,12 WALL_ROUTE13} from '../utils/constants'14describe('Test Home page', () => {15 it('is possible to create a post if logged', () => {16 window.localStorage.setItem('authTokens', JSON.stringify(validTokens))17 cy.intercept(TOKEN_ENDPOINT, dataReturned(200, 'successTokens')).as(18 'updateTokens'19 )20 cy.intercept(POSTS_ENDPOINT, dataReturned(200, 'posts')).as('getPosts')21 cy.visit(WALL_ROUTE)22 cy.wait(['@updateTokens', '@getPosts'])23 cy.get(INPUT_POST_CREATION).should('exist')24 cy.get(BUTTON_POST_CREATION).should('exist')25 cy.get(BUTTON_SIGN_IN_NAVIGATE).should('not.exist')26 cy.location('pathname').should('eq', WALL_ROUTE)27 })28 it('unable to create a post if not logged', () => {29 cy.intercept(POSTS_ENDPOINT, dataReturned(200, 'posts')).as('getPosts')30 cy.visit(WALL_ROUTE)31 cy.wait('@getPosts')32 cy.get(INPUT_POST_CREATION).should('not.exist')33 cy.get(BUTTON_POST_CREATION).should('not.exist')34 cy.get(BUTTON_SIGN_IN_NAVIGATE).should('exist')35 cy.location('pathname').should('eq', WALL_ROUTE)36 })37 it('navigate from Wall page to Home on Sign In click', () => {38 cy.intercept(POSTS_ENDPOINT, dataReturned(200, 'posts')).as('getPosts')39 cy.visit(WALL_ROUTE)40 cy.wait('@getPosts')41 cy.get(BUTTON_SIGN_IN_NAVIGATE).click()42 cy.location('pathname').should('eq', HOME_ROUTE)43 })44 it('is possible to logout', () => {45 window.localStorage.setItem('authTokens', JSON.stringify(validTokens))46 cy.intercept(TOKEN_ENDPOINT, dataReturned(200, 'successTokens')).as(47 'updateTokens'48 )49 cy.intercept(POSTS_ENDPOINT, dataReturned(200, 'posts')).as('getPosts')50 cy.visit(WALL_ROUTE)51 cy.wait(['@updateTokens', '@getPosts'])52 cy.get(BUTTON_LOGOUT).click()53 cy.location('pathname').should('eq', HOME_ROUTE)54 })55 it('has username on Wall Post Header', () => {56 window.localStorage.setItem('authTokens', JSON.stringify(validTokens))57 cy.intercept(TOKEN_ENDPOINT, dataReturned(200, 'successTokens')).as(58 'updateTokens'59 )60 cy.intercept(POSTS_ENDPOINT, dataReturned(200, 'posts')).as('getPosts')61 cy.visit(WALL_ROUTE)62 cy.wait(['@updateTokens', '@getPosts'])63 cy.get('p:contains("userTest")').should('exist')64 })65 it('has username on Wall Post Header', () => {66 cy.intercept(POSTS_ENDPOINT, dataReturned(200, 'posts')).as('getPosts')67 cy.visit(WALL_ROUTE)68 cy.wait('@getPosts')69 cy.get(POST).its('length').should('eq', 10)70 })...
Using AI Code Generation
1var client = require('devicefarmer-stf-client');2var util = require('util');3var fs = require('fs');4var path = require('path');5var file = path.join(__dirname, 'stf.json');6var stf = require(file);7var stfClient = new client(stf);8stfClient.updateTokens(function(err, result) {9 if (err) {10 console.log(err);11 } else {12 console.log(result);13 }14});15{ updated: 0, skipped: 1, errors: 0 }16Share this: Click to print (Opens in new window)
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!