Best JavaScript code snippet using devicefarmer-stf
user-test.js
Source:user-test.js
1const userAPI = require('../functions/users'),2 owner = require('../../settings/ganache-accounts'),3 web3 = require('../../settings/bcConn').web3,4 multiTransaction = require('./multiTransactionController'),5 contract = owner.contract.methods;6const siloamHospitalCode = web3.utils.stringToHex('3171789S'),7 husadaHospitalCode = web3.utils.stringToHex('3173040'),8 pluitHospitalCode = web3.utils.stringToHex('3175341'),9 gadingPluitHospitalCode = web3.utils.stringToHex('3175407'),10 manuelaHospitalCode = web3.utils.stringToHex('3174405'),11 pertaminaHospitalCode = web3.utils.stringToHex('3173474'),12 tarakanHospitalCode = web3.utils.stringToHex('3173521'),13 pikHospitalCode = web3.utils.stringToHex('3175352'),14 sumberWarasHospitalCode = web3.utils.stringToHex('3174015'),15 jakartaHospitalCode = web3.utils.stringToHex('3171045');16async function insertTestData() {17 await setHospitals();18 await insertUsers();19 /*Update User*/20 // await userAPI.updateUser(2, 2, 'Dr.Ian', 1234567890123456).then(r => console.log(r))21}22async function getTestData() {23 await userAPI.getHospital(owner.accountAddresses[0]).then(r => console.log(r));24 await userAPI.getHospital(owner.accountAddresses[1]).then(r => console.log(r));25 await userAPI.getHospital(owner.accountAddresses[2]).then(r => console.log(r));26 await userAPI.getHospital(owner.accountAddresses[3]).then(r => console.log(r));27 await userAPI.getHospital(owner.accountAddresses[4]).then(r => console.log(r));28 await userAPI.getHospital(owner.accountAddresses[5]).then(r => console.log(r));29 await userAPI.getHospital(owner.accountAddresses[6]).then(r => console.log(r));30 await userAPI.getHospital(owner.accountAddresses[7]).then(r => console.log(r));31 await userAPI.getHospital(owner.accountAddresses[8]).then(r => console.log(r));32 await userAPI.getHospital(owner.accountAddresses[9]).then(r => console.log(r));33 await userAPI.getUser(owner.accountAddresses[11]).then(r => console.log(r));34 await userAPI.getUser(owner.accountAddresses[12]).then(r => console.log(r));35}36async function setHospitals() {37 await userAPI.setHospital(owner.accountAddresses[14], owner.accountAddresses[0], 'SILOAM HOSPITALS', siloamHospitalCode);38 await userAPI.setHospital(owner.accountAddresses[14], owner.accountAddresses[1], 'RS Husada', husadaHospitalCode);39 await userAPI.setHospital(owner.accountAddresses[14], owner.accountAddresses[2], 'RS Pluit', pluitHospitalCode);40 await userAPI.setHospital(owner.accountAddresses[14], owner.accountAddresses[3], 'RS Gading Pluit', gadingPluitHospitalCode);41 await userAPI.setHospital(owner.accountAddresses[14], owner.accountAddresses[4], 'RS Manuela', manuelaHospitalCode);42 await userAPI.setHospital(owner.accountAddresses[14], owner.accountAddresses[5], 'RS Pertamina Jaya', pertaminaHospitalCode);43 await userAPI.setHospital(owner.accountAddresses[14], owner.accountAddresses[6], 'RSU Tarakan', tarakanHospitalCode);44 await userAPI.setHospital(owner.accountAddresses[14], owner.accountAddresses[7], 'RS Pantai Indah Kapuk', pikHospitalCode);45 await userAPI.setHospital(owner.accountAddresses[14], owner.accountAddresses[8], 'RS Sumber Waras', sumberWarasHospitalCode);46 await userAPI.setHospital(owner.accountAddresses[14], owner.accountAddresses[9], 'RS Jakarta', jakartaHospitalCode);47}48async function insertUsers() {49 // Insert Doctor50 await userAPI.storeUser(owner.accountAddresses[0], owner.accountAddresses[11], 2, 'Chandra', 1234567890123456);51 // Insert Patient52 await userAPI.storeUser(owner.accountAddresses[0], owner.accountAddresses[12], 1, 'Ian Joseph', 1234567890123455);53}54async function runTest() {55 // await insertTestData();56 await getTestData();57 // await insertUsers();58}...
ProfileController.ts
Source:ProfileController.ts
1import { Utils } from '../utils/Utils';2import { UserAPI } from '../api/user-api';3import { AuthAPI } from '../api/auth-api';4import { Store } from '../modules/Store';5const authAPI = new AuthAPI();6const userAPI = new UserAPI();7const store = new Store();8export class ProfileController {9 static getProfile(options?): void {10 if (store.get('profileProps.info')) {11 store.eventBus.emit('profileDataReceived');12 return;13 }14 authAPI15 .request(options)16 .then((xhr: XMLHttpRequest) => {17 if (xhr.status === 204) return;18 if (xhr.status !== 200) {19 alert(xhr.responseText);20 }21 if (xhr.status === 200) {22 store.set('profileProps.info', JSON.parse(xhr.response));23 store.eventBus.emit('profileDataReceived');24 }25 })26 .catch(userAPI.handleErrors);27 }28 static updateProfile(options): void {29 Utils.preventDOS(30 store,31 userAPI.updateProfile.bind(userAPI, {32 headers: {33 'Content-Type': 'application/json',34 },35 data: Utils.collectFormData(),36 }),37 )38 .then((xhr: XMLHttpRequest) => {39 if (xhr.status === 204) return;40 if (xhr.status !== 200) {41 alert(xhr.responseText);42 }43 if (xhr.status === 200) {44 store.set('profileProps.info', JSON.parse(xhr.response));45 store.eventBus.emit('profileDataReceived');46 options.success();47 }48 })49 .catch(userAPI.handleErrors);50 }51 static updatePassword(options): void {52 Utils.preventDOS(53 store,54 userAPI.updatePassword.bind(userAPI, {55 headers: {56 'Content-Type': 'application/json',57 },58 data: Utils.collectFormData(),59 }),60 )61 .then((xhr: XMLHttpRequest) => {62 if (xhr.status === 204) return;63 alert(xhr.responseText);64 if (xhr.status === 200) {65 options.success();66 }67 })68 .catch(userAPI.handleErrors);69 }70 static uploadAvatar(options): void {71 Utils.preventDOS(72 store,73 userAPI.updateAvatar.bind(userAPI, {74 data: Utils.collectFormData({ returnFormData: true }),75 }),76 )77 .then((xhr: XMLHttpRequest) => {78 if (xhr.status === 204) return;79 if (xhr.status !== 200) {80 alert(xhr.responseText);81 }82 if (xhr.status === 200) {83 store.set('profileProps.info', JSON.parse(xhr.response));84 store.eventBus.emit('profileDataReceived');85 options.success();86 }87 })88 .catch(userAPI.handleErrors);89 }90 static logout(options): void {91 authAPI92 .logout()93 .then((xhr: XMLHttpRequest) => {94 if (xhr.status === 204) return;95 alert(xhr.responseText);96 if (xhr.status === 200) {97 options.success();98 }99 })100 .catch(authAPI.handleErrors);101 }...
routes.js
Source:routes.js
1const express = require('express');2const router = express.Router();3const userApi = require('./api/userApi');4router.post('/user', userApi.createUser)5router.post('/user/verification', userApi.verifyUser)6router.post('/user/resendVerification', userApi.resendVerification)7router.post('/user/forgotPassword', userApi.forgotPassword)8router.post('/user/confirmForgotPassword', userApi.confirmForgotPassword)9router.post('/user/login', userApi.loginUser)10router.post('/user/logout', userApi.validateToken, userApi.signOutUser)11router.get('/user',userApi.validateToken, userApi.getUser)12router.post('/token', userApi.refreshToken)13router.post('/user',userApi.validateToken, userApi.updateUser)14router.delete('/user',userApi.validateToken, userApi.deleteUser)...
Using AI Code Generation
1var userapi = require('devicefarmer-stf').userapi;2userapi.getDevices(function(err, devices) {3 console.log(devices);4});5var userapi = require('devicefarmer-stf').userapi;6userapi.getDevices(function(err, devices) {7 console.log(devices);8});9var userapi = require('devicefarmer-stf').userapi;10userapi.getDevices(function(err, devices) {11 console.log(devices);12});13var userapi = require('devicefarmer-stf').userapi;14userapi.getDevices(function(err, devices) {15 console.log(devices);16});17var userapi = require('devicefarmer-stf').userapi;18userapi.getDevices(function(err, devices) {19 console.log(devices);20});21var userapi = require('devicefarmer-stf').userapi;22userapi.getDevices(function(err, devices) {23 console.log(devices);24});25var userapi = require('devicefarmer-stf').userapi;26userapi.getDevices(function(err, devices) {27 console.log(devices);28});29var userapi = require('devicefarmer-stf').userapi;30userapi.getDevices(function(err, devices) {31 console.log(devices);32});33var userapi = require('devicefarmer-stf').userapi;34userapi.getDevices(function(err, devices) {35 console.log(devices);36});37var userapi = require('devicefarmer-stf').userapi;38userapi.getDevices(function(err, devices) {39 console.log(devices
Using AI Code Generation
1var userapi = require('devicefarmer-stf').userapi;2user.list(function(err, data) {3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var deviceapi = require('devicefarmer-stf').deviceapi;10device.list(function(err, data) {11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var deviceapi = require('devicefarmer-stf').deviceapi;18device.list(function(err, data) {19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var deviceapi = require('devicefarmer-stf').deviceapi;26device.list(function(err, data) {27 if (err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var deviceapi = require('devicefarmer-stf').deviceapi;34device.list(function(err, data) {35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var deviceapi = require('devicefarmer-stf').deviceapi;42device.list(function(err, data) {43 if (err) {44 console.log(err);45 } else {46 console.log(data);47 }48});49var deviceapi = require('devicefarmer-stf').deviceapi;
Using AI Code Generation
1var userapi = require('devicefarmer-stf').userapi;2stfapi.getDevices(function(err, devices) {3 if (err) {4 console.log(err);5 } else {6 console.log(devices);7 }8});9var deviceapi = require('devicefarmer-stf').deviceapi;10stfapi.getDevice('serial', function(err, device) {11 if (err) {12 console.log(err);13 } else {14 console.log(device);15 }16});17var deviceapi = require('devicefarmer-stf').deviceapi;18stfapi.getDevice('serial', function(err, device) {19 if (err) {20 console.log(err);21 } else {22 console.log(device);23 }24});25var deviceapi = require('devicefarmer-stf').deviceapi;26stfapi.getDevice('serial', function(err, device) {27 if (err) {28 console.log(err);29 } else {30 console.log(device);31 }32});33var deviceapi = require('devicefarmer-stf').deviceapi;34stfapi.getDevice('serial', function(err, device) {35 if (err) {36 console.log(err);37 } else {38 console.log(device);39 }40});41var deviceapi = require('devicefarmer-stf').deviceapi;42stfapi.getDevice('serial', function(err, device) {43 if (err) {44 console.log(err);45 } else {46 console.log(device);47 }48});49var deviceapi = require('devicefar
Using AI Code Generation
1var stf = require('devicefarmer-stf');2stf.userapi(function (err, data) {3 console.log(data);4});5var stf = require('devicefarmer-stf');6stf.deviceapi(function (err, data) {7 console.log(data);8});9var stf = require('devicefarmer-stf');10stf.deviceapi(function (err, data) {11 console.log(data);12});13var stf = require('devicefarmer-stf');14stf.deviceapi(function (err, data) {15 console.log(data);16});17var stf = require('devicefarmer-stf');18stf.deviceapi(function (err, data) {19 console.log(data);20});21var stf = require('devicefarmer-stf');22stf.deviceapi(function (err, data) {23 console.log(data);24});25var stf = require('devicefarmer-stf');26stf.deviceapi(function (err, data) {27 console.log(data);28});29var stf = require('devicefarmer-stf');30stf.deviceapi(function (err, data) {31 console.log(data);32});
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!!