Best JavaScript code snippet using devicefarmer-stf
DynamoDBManager.ts
Source:DynamoDBManager.ts
...5export class DynamoDBManager implements IDBManager {6 _db = new DynamoDBAsync();7 async create(tableName: string, payload: any): Promise<any> {8 let k = getFields(tableName)[0];9 let v = tryFind(payload, k, undefined);10 if (!v) throw `${k || 'Key'} does not exist in request.`;11 let key = {};12 key[k] = v;13 let r = await this._db.get({14 TableName: tableName,15 Key: key16 });17 if (r && r.Item) throw `${v || 'Item'} already exists.`;18 let item = {};19 for (let e of getFields(tableName)) {20 let p = tryFind(payload, e, undefined);21 if (p) {22 item[e] = p;23 } else {24 throw `${e} does not exist in request.`;25 }26 }27 return this._db.create({28 TableName: tableName,29 Item: item30 });31 }32 async get(tableName: string, payload: any): Promise<any> {33 let key = tryFind(payload, 'key', undefined);34 if (!key) throw `Key does not exist in request.`;35 let r = await this._db.get({36 TableName: tableName,37 Key: key38 });39 if (!r || !r.Item) throw `${key[Object.keys(key)[0]] || 'Item'} does not exists.`;40 return r.Item;41 }42 async update(tableName: string, payload: any): Promise<any> {43 let r = await this.get(tableName, payload);44 let attributes = {};45 for (let e of getFields(tableName)) {46 let v = tryFind(payload, e, undefined);47 if (v && r[e] !== v) {48 attributes[e] = {49 Action: "PUT",50 Value: v51 };52 }53 }54 return this._db.update({55 TableName: tableName,56 Key: tryFind(payload, 'key', undefined),57 AttributeUpdates: attributes58 });59 }60 async delete(tableName: string, payload: any): Promise<any> {61 await this.get(tableName, payload);62 return this._db.delete({63 TableName: tableName,64 Key: tryFind(payload, 'key', undefined)65 });66 }67 find(tableName: string, payload: any): Promise<any> {68 return this._db.find({69 TableName: tableName,70 FilterExpression: tryFind(payload, 'expression', undefined),71 ExpressionAttributeValues: tryFind(payload, 'values', undefined)72 });73 }...
queue.ts
Source:queue.ts
1import IQueueDTO from "../dtos/IQueueDTO"2import { jsonXlxs, getCompany } from "../utils/index"3import fs from "fs"4import { path } from "app-root-path"5export default async function({ id, json }: IQueueDTO): Promise<void> {6 const findedData = []7 const notFinded = []8 9 let queueData = JSON.parse(fs.readFileSync(path + "/src/queue.json", { encoding: "utf-8" }))10 queueData.push({ id, loaded: json.length, finded: 0, checked: 0, last: "" })11 fs.writeFileSync(path + "/src/queue.json", JSON.stringify(queueData, null, 4), { encoding: "utf-8" })12 13 let columnIndex = 014 15 for (let i = 0; i < json.length; i++) {16 queueData = JSON.parse(fs.readFileSync(path + "/src/queue.json", { encoding: "utf-8" }))17 let queueStats = queueData.find(x => x.id == id)18 let forFind = json[i][Object.keys(json[i])[columnIndex]]19 let telefone = json[i][Object.keys(json[i])[1]]20 console.log(json[i])21 queueStats.last = forFind22 let tryFind = await getCompany({ search: forFind })23 if (tryFind) {24 console.log(telefone)25 for (let i = 0; i < tryFind.length; i++)26 tryFind[i]['telefone'] = telefone27 queueStats.finded++28 findedData.push(...tryFind)29 } else {30 notFinded.push({ name: forFind })31 }32 33 queueStats.checked++34 queueData[queueData.findIndex(x => x.id == id)] = queueStats35 fs.writeFileSync(path + "/src/queue.json", JSON.stringify(queueData, null, 4), { encoding: "utf-8" })36 }37 await jsonXlxs(id, findedData)...
userAuth.js
Source:userAuth.js
...7 getUserPhoneNumbers,8 getUserAddresses,9} = require('../sql/userQueries');10const { getPool } = require('../database');11async function tryFind(pool, query, token, req) {12 const user = (await pool.query(query, [token])).rows[0];13 if (user) {14 req.user = user;15 req.user.phoneNumbers = (await pool.query(getUserPhoneNumbers, [user.username])).rows;16 req.user.addresses = (await pool.query(getUserAddresses, [user.username])).rows;17 return true;18 }19 return false;20}21async function userAuth(req, res, next) {22 const token = req.header('Authorization').substring(7);23 if (!token) {24 return res.status(401).send('Auth token missing');25 }26 const pool = await getPool();27 try {28 if (await tryFind(pool, getNormalUserByAuth, token, req)) return next();29 if (await tryFind(pool, getStudentUserByAuth, token, req)) return next();30 if (await tryFind(pool, getProfessorUserByAuth, token, req)) return next();31 if (await tryFind(pool, getLibrarianUserByAuth, token, req)) return next();32 if (await tryFind(pool, getManagerUserByAuth, token, req)) return next();33 return res.sendStatus(401);34 } catch (err) {35 return res.status(500).send(`User auth check failed: ${err.message}`);36 }37}...
Using AI Code Generation
1var devicefarmer = require('devicefarmer-stf');2stf.tryFind('device1').then(function(device) {3 console.log(device);4});5var devicefarmer = require('devicefarmer-stf');6stf.tryFind('device1').then(function(device) {7 console.log(device);8});9var devicefarmer = require('devicefarmer-stf');10stf.tryFind('device1').then(function(device) {11 console.log(device);12});13var devicefarmer = require('devicefarmer-stf');14stf.tryFind('device1').then(function(device) {15 console.log(device);16});17var devicefarmer = require('devicefarmer-stf');18stf.tryFind('device1').then(function(device) {19 console.log(device);20});21var devicefarmer = require('devicefarmer-stf');22stf.tryFind('device1').then(function(device) {23 console.log(device);24});25var devicefarmer = require('devicefarmer-stf');26stf.tryFind('device1').then(function(device) {27 console.log(device);28});
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!!