How to use FormatError method in wpt

Best JavaScript code snippet using wpt

json_schema_test.js

Source:json_schema_test.js Github

copy

Full Screen

...55}56function formatError(key, replacements) {57 return JSONSchemaValidator.formatError(key, replacements);58}59function testFormatError() {60 AssertTrue(formatError("propertyRequired") == "Property is required.");61 AssertTrue(formatError("invalidEnum", ["foo, bar"]) ==62 "Value must be one of: [foo, bar].");63 AssertTrue(formatError("invalidType", ["foo", "bar"]) ==64 "Expected 'foo' but got 'bar'.");65}66function testComplex() {67 var schema = {68 type: "array",69 items: [70 {71 type: "object",72 properties: {73 id: {...

Full Screen

Full Screen

reporter.spec.js

Source:reporter.spec.js Github

copy

Full Screen

1'use strict'2const EventEmitter = require('events').EventEmitter3const loadFile = require('mocks').loadFile4const path = require('path')5const _ = require('lodash')6const sinon = require('sinon')7const File = require('../../lib/file')8describe('reporter', () => {9 let m10 beforeEach(() => {11 m = loadFile(path.join(__dirname, '/../../lib/reporter.js'))12 })13 describe('formatError', () => {14 let emitter15 let formatError = emitter = null16 let sandbox17 beforeEach(() => {18 emitter = new EventEmitter()19 formatError = m.createErrorFormatter({ basePath: '', hostname: 'localhost', port: 8080 }, emitter)20 sandbox = sinon.createSandbox()21 })22 it('should call config.formatError if defined', () => {23 const spy = sandbox.spy()24 formatError = m.createErrorFormatter({ basePath: '', formatError: spy }, emitter)25 formatError()26 expect(spy).to.have.been.calledOnce27 })28 it('should not call config.formatError if not defined', () => {29 const spy = sandbox.spy()30 formatError()31 expect(spy).not.to.have.been.calledOnce32 })33 it('should pass the error message as the first config.formatError argument', () => {34 const ERROR = 'foo bar'35 const spy = sandbox.spy()36 formatError = m.createErrorFormatter({ basePath: '', formatError: spy }, emitter)37 formatError(ERROR)38 expect(spy.firstCall.args[0]).to.equal(ERROR)39 })40 it('should display the exact error returned by config.formatError', () => {41 const formattedError = 'A new error'42 formatError = m.createErrorFormatter({ basePath: '', formatError: () => formattedError }, emitter)43 expect(formatError('Something', '\t')).to.equal(formattedError)44 })45 it('should indent', () => {46 expect(formatError('Something', '\t')).to.equal('\tSomething\n')47 })48 it('should handle empty message', () => {49 expect(formatError(null)).to.equal('\n')50 })51 it('should handle arbitrary error objects', () => {52 expect(53 formatError({ hello: 'world' })54 ).to.equal(55 JSON.stringify({ hello: 'world' }) + '\n'56 )57 })58 it('should handle error objects', () => {59 expect(60 formatError(new Error('fail'))61 ).to.equal(62 'fail\n'63 )64 })65 it('should remove specified hostname from files', () => {66 expect(formatError('file http://localhost:8080/base/usr/a.js and http://127.0.0.1:8080/absolute/home/b.js')).to.be.equal('file usr/a.js and http://127.0.0.1:8080/home/b.js\n')67 })68 it('should remove shas', () => {69 const ERROR = 'file http://localhost:8080/base/usr/file.js?6e31cb249ee5b32d91f37ea516ca0f84bddc5aa9 and http://127.0.0.1:8080/absolute/home/file.js?6e31cb249ee5b32d91f37ea516ca0f84bddc5aa9'70 expect(formatError(ERROR)).to.be.equal('file usr/file.js and http://127.0.0.1:8080/home/file.js\n')71 })72 it('should indent all lines', () => {73 expect(formatError('first\nsecond\nthird', '\t')).to.equal('\tfirst\n\tsecond\n\tthird\n')74 })75 it('should restore base paths', () => {76 formatError = m.createErrorFormatter({ basePath: '/some/base', hostname: 'localhost', port: 123 }, emitter)77 expect(formatError('at http://localhost:123/base/a.js?123')).to.equal('at a.js\n')78 })79 it('should restore urlRoot paths', () => {80 formatError = m.createErrorFormatter({ urlRoot: '/__karma__', basePath: '/some/base', hostname: 'localhost', port: 123 }, emitter)81 expect(formatError('at http://localhost:123/__karma__/base/sub/a.js?123')).to.equal('at sub/a.js\n')82 })83 it('should restore absolute paths', () => {84 const ERROR = 'at http://localhost:8080/absolute/usr/path.js?6e31cb249ee5b32d91f37ea516ca0f84bddc5aa9'85 expect(formatError(ERROR)).to.equal('at /usr/path.js\n')86 })87 it('should preserve line numbers', () => {88 const ERROR = 'at http://localhost:8080/absolute/usr/path.js?6e31cb249ee5b32d91f37ea516ca0f84bddc5aa9:2'89 expect(formatError(ERROR)).to.equal('at /usr/path.js:2\n')90 })91 it('should preserve absolute word', () => {92 const ERROR = 'contains absolute'93 expect(formatError(ERROR)).to.equal('contains absolute\n')94 })95 it('should preserve base word', () => {96 const ERROR = 'contains base'97 expect(formatError(ERROR)).to.equal('contains base\n')98 })99 describe('source maps', () => {100 let originalPositionForCallCount = 0101 let sourceMappingPath = null102 class MockSourceMapConsumer {103 constructor (sourceMap) {104 this.source = sourceMap.content.replace('SOURCE MAP ', sourceMappingPath)105 }106 originalPositionFor (position) {107 originalPositionForCallCount++108 if (position.line === 0) {109 throw new TypeError('Line must be greater than or equal to 1, got 0')110 }111 return {112 source: this.source,113 line: position.line + 2,114 column: position.column + 2115 }116 }117 }118 beforeEach(() => {119 originalPositionForCallCount = 0120 sourceMappingPath = '/original/'121 })122 MockSourceMapConsumer.GREATEST_LOWER_BOUND = 1123 MockSourceMapConsumer.LEAST_UPPER_BOUND = 2124 it('should rewrite stack traces', (done) => {125 formatError = m.createErrorFormatter({ basePath: '/some/base', hostname: 'localhost', port: 123 }, emitter, MockSourceMapConsumer)126 const servedFiles = [new File('/some/base/a.js'), new File('/some/base/b.js')]127 servedFiles[0].sourceMap = { content: 'SOURCE MAP a.js' }128 servedFiles[1].sourceMap = { content: 'SOURCE MAP b.js' }129 emitter.emit('file_list_modified', { served: servedFiles })130 _.defer(() => {131 const ERROR = 'at http://localhost:123/base/b.js:2:6'132 expect(formatError(ERROR)).to.equal('at /original/b.js:4:8 <- b.js:2:6\n')133 done()134 })135 })136 it('should rewrite stack traces (when basePath is empty)', (done) => {137 formatError = m.createErrorFormatter({ basePath: '', hostname: 'localhost', port: 123 }, emitter, MockSourceMapConsumer)138 const servedFiles = [new File('/a.js'), new File('/b.js')]139 servedFiles[0].sourceMap = { content: 'SOURCE MAP a.js' }140 servedFiles[1].sourceMap = { content: 'SOURCE MAP b.js' }141 emitter.emit('file_list_modified', { served: servedFiles })142 _.defer(() => {143 const ERROR = 'at http://localhost:123/base/b.js:2:6'144 expect(formatError(ERROR)).to.equal('at /original/b.js:4:8 <- b.js:2:6\n')145 done()146 })147 })148 it('should rewrite stack traces to the first column when no column is given', (done) => {149 formatError = m.createErrorFormatter({ basePath: '/some/base', hostname: 'localhost', port: 123 }, emitter, MockSourceMapConsumer)150 const servedFiles = [new File('/some/base/a.js'), new File('/some/base/b.js')]151 servedFiles[0].sourceMap = { content: 'SOURCE MAP a.js' }152 servedFiles[1].sourceMap = { content: 'SOURCE MAP b.js' }153 emitter.emit('file_list_modified', { served: servedFiles })154 _.defer(() => {155 const ERROR = 'at http://localhost:123/base/b.js:2'156 expect(formatError(ERROR)).to.equal('at /original/b.js:4:3 <- b.js:2\n')157 done()158 })159 })160 it('should rewrite relative url stack traces', (done) => {161 formatError = m.createErrorFormatter({ basePath: '/some/base', hostname: 'localhost', port: 123 }, emitter, MockSourceMapConsumer)162 const servedFiles = [new File('/some/base/a.js'), new File('/some/base/b.js')]163 servedFiles[0].sourceMap = { content: 'SOURCE MAP a.js' }164 servedFiles[1].sourceMap = { content: 'SOURCE MAP b.js' }165 emitter.emit('file_list_modified', { served: servedFiles })166 _.defer(() => {167 const ERROR = 'at /base/b.js:2:6'168 expect(formatError(ERROR)).to.equal('at /original/b.js:4:8 <- b.js:2:6\n')169 done()170 })171 })172 it('should resolve relative urls from source maps', (done) => {173 sourceMappingPath = 'original/' // Note: relative path.174 formatError = m.createErrorFormatter({ basePath: '/some/base' }, emitter, MockSourceMapConsumer)175 const servedFiles = [new File('/some/base/path/a.js')]176 servedFiles[0].sourceMap = { content: 'SOURCE MAP a.fancyjs' }177 emitter.emit('file_list_modified', { served: servedFiles })178 _.defer(() => {179 const ERROR = 'at /base/path/a.js:2:6'180 expect(formatError(ERROR)).to.equal('at path/original/a.fancyjs:4:8 <- path/a.js:2:6\n')181 done()182 })183 })184 it('should fall back to non-source-map format if originalPositionFor throws', (done) => {185 formatError = m.createErrorFormatter({ basePath: '/some/base', hostname: 'localhost', port: 123 }, emitter, MockSourceMapConsumer)186 const servedFiles = [new File('/some/base/a.js'), new File('/some/base/b.js')]187 servedFiles[0].sourceMap = { content: 'SOURCE MAP a.js' }188 servedFiles[1].sourceMap = { content: 'SOURCE MAP b.js' }189 emitter.emit('file_list_modified', { served: servedFiles })190 _.defer(() => {191 const ERROR = 'at http://localhost:123/base/b.js:0:0'192 expect(formatError(ERROR)).to.equal('at b.js\n')193 done()194 })195 })196 it('should not try to use source maps when no line is given', (done) => {197 formatError = m.createErrorFormatter({ basePath: '/some/base', hostname: 'localhost', port: 123 }, emitter, MockSourceMapConsumer)198 const servedFiles = [new File('/some/base/a.js'), new File('/some/base/b.js')]199 servedFiles[0].sourceMap = { content: 'SOURCE MAP a.js' }200 servedFiles[1].sourceMap = { content: 'SOURCE MAP b.js' }201 emitter.emit('file_list_modified', { served: servedFiles })202 _.defer(() => {203 const ERROR = 'at http://localhost:123/base/b.js'204 expect(formatError(ERROR)).to.equal('at b.js\n')205 expect(originalPositionForCallCount).to.equal(0)206 done()207 })208 })209 it('should not try to match domains with spaces', (done) => {210 formatError = m.createErrorFormatter({ basePath: '/some/base', hostname: 'localhost', port: 9876 }, emitter, MockSourceMapConsumer)211 const servedFiles = [new File('/some/base/a.js'), new File('/some/base/b.js')]212 servedFiles[0].sourceMap = { content: 'SOURCE MAP a.js' }213 servedFiles[1].sourceMap = { content: 'SOURCE MAP b.js' }214 emitter.emit('file_list_modified', { served: servedFiles })215 _.defer(() => {216 const ERROR = '"http://localhost:9876"\n at /base/b.js:2:6'217 expect(formatError(ERROR)).to.equal('"http://localhost:9876"\n at /original/b.js:4:8 <- b.js:2:6\n')218 done()219 })220 })221 describe('Windows', () => {222 formatError = null223 let servedFiles = null224 beforeEach(() => {225 formatError = m.createErrorFormatter({ basePath: '/some/base', hostname: 'localhost', port: 123 }, emitter, MockSourceMapConsumer)226 servedFiles = [new File('C:/a/b/c.js')]227 servedFiles[0].sourceMap = { content: 'SOURCE MAP b.js' }228 })229 it('should correct rewrite stack traces without sha', (done) => {230 emitter.emit('file_list_modified', { served: servedFiles })231 _.defer(() => {232 const ERROR = 'at http://localhost:123/absoluteC:/a/b/c.js:2:6'233 expect(formatError(ERROR)).to.equal('at c:/original/b.js:4:8 <- C:/a/b/c.js:2:6\n')234 done()235 })236 })237 it('should correct rewrite stack traces with sha', (done) => {238 emitter.emit('file_list_modified', { served: servedFiles })239 _.defer(() => {240 const ERROR = 'at http://localhost:123/absoluteC:/a/b/c.js?da39a3ee5e6:2:6'241 expect(formatError(ERROR)).to.equal('at c:/original/b.js:4:8 <- C:/a/b/c.js:2:6\n')242 done()243 })244 })245 })246 })247 })...

Full Screen

Full Screen

productionApp.js

Source:productionApp.js Github

copy

Full Screen

1const express = require("express");2const Web3 = require("web3");3const app = express();4app.use(express.json());5const ethNetwork = process.env.ETH_NETWORK;6const BankId = process.env.BANK_ID;7const GAS = process.env.GAS_VALUE;8const web3 = new Web3(new Web3.providers.HttpProvider(ethNetwork));9const Accounts = require("web3-eth-accounts");10const port = process.env.PORT || 3000;11app.listen(port, () => console.log("Server is running on port " + port));12/*****************************************************PRODUCTION ROUTES**************************************************************/13// Production Route - to get all details from bank14app.get("/getBankDetails", (req, res) => {15 // res.json({"Name":"Api is running on cypher server"})16 let TOKENNAME, TOKENSYMBOL, DECIMALUNITS, TOTALSUPPLY;17 contract.methods18 .name()19 .call()20 .then((result) => {21 //res.send(result);22 TOKENNAME = result;23 console.log("name= " + result);24 })25 .catch((err) => {26 TOKENNAME = err;27 console.log("ERROR :" + err);28 let formaterror = `{"errorcode" :"GBD1","message" : "${err}"}`;29 console.log(JSON.parse(formaterror));30 res.json(JSON.parse(formaterror));31 });32 contract.methods33 .symbol()34 .call()35 .then((result) => {36 //res.send(result);37 TOKENSYMBOL = result;38 console.log("Symbol= " + result);39 })40 .catch((err) => {41 TOKENSYMBOL = err;42 console.log("ERROR :" + err);43 let formaterror = `{"errorcode" :"GBD2","message" : "${err}"}`;44 console.log(JSON.parse(formaterror));45 res.json(JSON.parse(formaterror));46 });47 contract.methods48 .decimals()49 .call()50 .then((result) => {51 //res.send(result);52 DECIMALUNITS = result;53 console.log("decimals= " + result);54 })55 .catch((err) => {56 DECIMALUNITS = err;57 console.log("ERROR :" + err);58 let formaterror = `{"errorcode" :"GBD3","message" : "${err}"}`;59 console.log(JSON.parse(formaterror));60 res.json(JSON.parse(formaterror));61 });62 contract.methods63 .totalSupply()64 .call()65 .then((result) => {66 //res.send(result);67 TOTALSUPPLY = result;68 console.log("totalSupply= " + result);69 })70 .catch((err) => {71 TOTALSUPPLY = err;72 console.log("ERROR :" + err);73 let formaterror = `{"errorcode" :"GBD4","message" : "${err}"}`;74 console.log(JSON.parse(formaterror));75 res.json(JSON.parse(formaterror));76 });77 function formatjson() {78 let jsonResult = `{"TokenName" : "${TOKENNAME}","TokenSymbol" : "${TOKENSYMBOL}","DecimalUnits" : "${DECIMALUNITS}","BankID" :"${BankId}","TotalSupply" :"${TOTALSUPPLY}"}`;79 console.log(JSON.parse(jsonResult));80 res.json(JSON.parse(jsonResult));81 }82 setTimeout(formatjson, 5000);83});84// Production Route - to get user details85app.get("/getUserDetails/:USERID", (req, res) => {86 let USERID = req.params.USERID,87 BALANCEOF;88 console.log(USERID);89 contract.methods90 .balanceOf(USERID)91 .call()92 .then((result) => {93 BALANCEOF = result;94 console.log("result= " + result);95 })96 .catch((err) => {97 BALANCEOF = err;98 console.log("ERROR :" + err);99 let formaterror = `{"errorcode" :"GUD","message" : "${err}"}`;100 console.log(JSON.parse(formaterror));101 res.json(JSON.parse(formaterror));102 });103 function formatjson() {104 let jsonResult = `{"UserId" : "${USERID}","UserBalance" : "${BALANCEOF}"}`;105 console.log(JSON.parse(jsonResult));106 res.json(JSON.parse(jsonResult));107 }108 setTimeout(formatjson, 3000);109});110// Production Route - to get user Account111app.get("/createUser", (req, res) => {112 const accounts = new Accounts(ethNetwork);113 const userAccount = web3.eth.accounts.create();114 console.log(115 "user = " + userAccount.address + " private key =" + userAccount.privateKey116 );117 function formatjson() {118 let jsonResult = `{"Address" : "${userAccount.address}","PrivateKey" : "${userAccount.privateKey}"}`;119 console.log(JSON.parse(jsonResult));120 res.json(JSON.parse(jsonResult));121 }122 setTimeout(formatjson, 2000);123});124// Production Route - to post money from bank to user account125/*126Request127{128 "UserId" :"0x01B7Ca9BFf093C69A1F8dA64735A1DBf01B27207",129 "TransferAmmount":10130}131Response132{133 "status": "true",134 "UserId": "0x01B7Ca9BFf093C69A1F8dA64735A1DBf01B27207",135 "TransferAmmount": "10"136}137*/138app.post("/transferFromBank", (req, res) => {139 console.log(req.body.UserId, req.body.TransferAmmount);140 let STAT1, STAT2, UID, UTA;141 UTA = req.body.TransferAmmount;142 UID = req.body.UserId;143 contract.methods144 .transfer(UID, UTA)145 .send({ from: account, gas: GAS })146 .then((result) => {147 console.log(result.status);148 STAT1 = result.status;149 contract.methods150 .burn(UTA.toString())151 .send({ from: account, gas: GAS })152 .then((result) => {153 STAT2 = result.status;154 console.log("STATUS= " + STAT2);155 let jsonResult = `{"status1" : "${STAT1}","status2" : "${STAT2}","UserId":"${UID}","TransferAmmount":"${UTA}"}`;156 res.json(JSON.parse(jsonResult));157 console.log(JSON.parse(jsonResult));158 })159 .catch((err) => {160 console.log("burn :" + err);161 let formaterror = `{"errorcode" :"TFB2","message" : "${err}"}`;162 console.log(JSON.parse(formaterror));163 res.json(JSON.parse(formaterror));164 });165 })166 .catch((err) => {167 console.log("Bank Transfer Error:" + err);168 let formaterror = `{"errorcode" :"TFB1","message" : "${err}"}`;169 console.log(JSON.parse(formaterror));170 res.json(JSON.parse(formaterror));171 return;172 });173});174// Production Route - to post money from one User to Other account175/*176Request177{178 "FromUserId" :"0x01B7Ca9BFf093C69A1F8dA64735A1DBf01B27207",179 "ToUserId" :"0x01B7Ca9BFf093C69A1F8dA64735A1DBf01B27207",180 "TransferAmmount":10181}182Response183{184 "status": "true",185 "FromUserId": "0x01B7Ca9BFf093C69A1F8dA64735A1DBf01B27207",186 "ToUserId": "0x40E767878739529D5D244B3cbd4bC6a2e9438365",187 "TransferAmmount": "10"188}189*/190app.post("/transferBtwUsers", (req, res) => {191 contract.methods192 .transferFrom(193 req.body.FromUserId,194 req.body.ToUserId,195 req.body.TransferAmmount.toString()196 )197 .send({ from: account, gas: GAS })198 .then((result) => {199 console.log(result.status);200 let jsonResult = `{"status" : "${result.status}","FromUserId":"${201 req.body.FromUserId202 }","ToUserId":"${203 req.body.ToUserId204 }","TransferAmmount":"${req.body.TransferAmmount.toString()}"}`;205 res.json(JSON.parse(jsonResult));206 })207 .catch((err) => {208 console.log(" User Transfer Error:" + err);209 let formaterror = `{"errorcode" :"TBWUS","message" : "${err}"}`;210 console.log(JSON.parse(formaterror));211 res.json(JSON.parse(formaterror));212 });213});214// Production Route - to get all user money to bank and delete account215app.get("/DeleteUser/:USERID", (req, res) => {216 let USERID = req.params.USERID,217 BALANCEOF,218 STATUS;219 console.log(USERID);220 contract.methods221 .balanceOf(USERID)222 .call()223 .then((result) => {224 BALANCEOF = result;225 console.log("result= " + result);226 })227 .catch((err) => {228 BALANCEOF = err;229 console.log("ERROR :" + err);230 let formaterror = `{"errorcode" :"DELUSER1","message" : "${err}"}`;231 console.log(JSON.parse(formaterror));232 res.json(JSON.parse(formaterror));233 });234 function formatjson() {235 contract.methods236 .burnFrom(USERID, BALANCEOF)237 .send({ from: account, gas: GAS })238 .then((result) => {239 STATUS = result.status;240 console.log("STATUS= " + STATUS);241 let jsonResult = `{"UserId" : "${USERID}","Status" : "${STATUS}"}`;242 console.log(JSON.parse(jsonResult));243 res.json(JSON.parse(jsonResult));244 })245 .catch((err) => {246 console.log("burn from :" + err);247 let formaterror = `{"errorcode" :"DELUSER2","message" : "${err}"}`;248 console.log(JSON.parse(formaterror));249 res.json(JSON.parse(formaterror));250 });251 }252 setTimeout(formatjson, 3000);253});254//Production Route - to handle default requests255app.get("*", (req, res) => {256 let jsonResult = `{"errorcode" :"GETNOTFOUND","message" : "API IS NOT DEFINED FOR THIS GET ROUTE."}`;257 console.log(JSON.parse(jsonResult));258 res.json(JSON.parse(jsonResult));259});260app.post("*", (req, res) => {261 let jsonResult = `{"errorcode" :"POSTNOTFOUND","message" : "API IS NOT DEFINED FOR THIS POST ROUTE."}`;262 console.log(JSON.parse(jsonResult));263 res.json(JSON.parse(jsonResult));...

Full Screen

Full Screen

validators.js

Source:validators.js Github

copy

Full Screen

1const { FormatError, ConflictError } = require('crowdaids-errors')23function validateId(id) {4 if (typeof id !== 'string') throw new TypeError('id is not a string')5 if (!id.trim().length) throw new FormatError('id is empty or blank')6 if (/\r?\n|\r|\t| /g.test(id)) throw new FormatError('blank spaces around id')7 if (id.length < 24) throw new FormatError('id has less than 24 characters')8}910function validateToken(token) {11 if (typeof token !== 'string') throw new TypeError('token is not a string')12 if (!/[a-zA-Z0-9\-_]+?\.[a-zA-Z0-9\-_]+?\.([a-zA-Z0-9\-_]+)$/.test(token)) throw new Error('invalid token')13}1415function validateUsername(username) {16 if (typeof username !== 'string') throw new TypeError('username is not a string')17 if (!username.trim().length) throw new FormatError('username is empty or blank')18 if (/\r?\n|\r|\t| /g.test(username)) throw new FormatError('username has blank spaces')19 if (username.length < 4) throw new FormatError('username has less than 4 characters')2021}2223function validatePassword(password) {24 if (typeof password !== 'string') throw new TypeError('password is not a string')25 if (!password.trim().length) throw new FormatError('password is empty or blank')26 if (/\r?\n|\r|\t| /g.test(password)) throw new FormatError('password has blank spaces')27 if (password.length < 8) throw new FormatError('password has less than 8 characters')28}2930function validateOldPassword(oldPassword) {31 if (typeof oldPassword !== 'string') throw new TypeError('old password is not a string')32 if (!oldPassword.trim().length) throw new FormatError('old password is empty or blank')33 if (/\r?\n|\r|\t| /g.test(oldPassword)) throw new FormatError('old password has blank spaces')34 if (oldPassword.length < 8) throw new FormatError('old password has less than 8 characters')35}3637function validateName(name) {38 if (typeof name !== 'string') throw new TypeError('name is not a string')39 if (!name.trim().length) throw new FormatError('name is empty or blank')40 if (name.trim() !== name) throw new FormatError('blank spaces around name')41}4243function validateEmail(email) {44 if (typeof email !== "string") throw new TypeError("email is not a string")45 if (!email.trim().length) throw new FormatError("email is empty or blank")46 if (!/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(email)) throw new FormatError("is not an e-mail")47}4849function validateData(data) {50 if (typeof data !== 'object' || data.constructor.name !== 'Object') throw new TypeError('data is not an object')5152 const { name, username, email, password, oldPassword } = data5354 if (typeof name !== 'undefined') {55 validateName(name)56 }5758 if (typeof username !== 'undefined') {59 validateUsername(username)60 }6162 if (typeof email !== 'undefined') {63 validateEmail(email)64 }6566 if (typeof oldPassword === 'undefined' && typeof password !== 'undefined') throw new ConflictError('old password is not defined')67 if (typeof password === 'undefined' && typeof oldPassword !== 'undefined') throw new ConflictError('password is not defined')6869 if (typeof password !== 'undefined') {70 validatePassword(password)71 }7273 if (typeof oldPassword !== 'undefined') {74 validateOldPassword(oldPassword)75 }76}7778function validateCallback(callback) {79 if (typeof callback !== 'function') throw new TypeError('callback is not a function')80}8182function validateCreditCardNumber(number) {83 if (typeof number !== 'string') throw new TypeError('credit card number is not a string')84 if (!number.trim().length) throw new FormatError('credit card number is empty or blank')85 if (/\r?\n|\r|\t| /g.test(number)) throw new FormatError('credit card number has blank spaces')86 if (number.length !== 16) throw new FormatError('credit card number doesn\'t have 16 digits')87 if (isNaN(number)) throw new FormatError('credit card number is not numeric')88}8990function validateDate(date) {91 if (!(date instanceof Date)) throw new TypeError('date is not a date')92}9394function validateCreditCardCVV(cvv) {95 if (typeof cvv !== 'string') throw new TypeError('cvv is not a string')96 if (!cvv.trim().length) throw new FormatError('cvv is empty or blank')97 if (/\r?\n|\r|\t| /g.test(cvv)) throw new FormatError('cvv has blank spaces')98 if (cvv.length > 4 || cvv.length < 3) throw new FormatError('cvv doesn\'t have 3 or 4 digits')99 if (isNaN(cvv)) throw new FormatError('cvv is not numeric')100}101102module.exports = {103 validateId,104 validateToken,105 validateUsername,106 validatePassword,107 validateOldPassword,108 validateData,109 validateName,110 validateCallback,111 validateCreditCardNumber,112 validateDate,113 validateCreditCardCVV, ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptools = require('wptools');2const wiki = wptools.page('Barack Obama');3wiki.get((err, resp) => {4 if(err) {5 console.log(wiki.formatError(err));6 }7});8const wptools = require('wptools');9const wiki = wptools.page('Barack Obama');10wiki.get((err, resp) => {11 if(err) {12 console.log(wiki.formatError(err));13 }14 else {15 console.log(resp.infobox);16 }17});18const wptools = require('wptools');19const wiki = wptools.page('Barack Obama');20wiki.get((err, resp) => {21 if(err) {22 console.log(wiki.formatError(err));23 }24 else {25 console.log(resp.pageid);26 }27});28const wptools = require('wptools');29const wiki = wptools.page('Barack Obama');30wiki.get((err, resp) => {31 if(err) {32 console.log(wiki.formatError(err));33 }34 else {35 console.log(resp.title);36 }37});38const wptools = require('wptools');39const wiki = wptools.page('Barack Obama');40wiki.get((err, resp) => {41 if(err) {42 console.log(wiki.formatError(err));43 }44 else {45 console.log(resp.summary);46 }47});48const wptools = require('wptools');49const wiki = wptools.page('Barack Obama');50wiki.get((err, resp) => {51 if(err) {52 console.log(wiki.formatError(err));53 }54 else {

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('wpt');2const wptOptions = {3};4const wptTest = new wpt('YOUR_API_KEY');5wptTest.runTest(wptOptions, (err, data) => {6 if (err) {7 console.log(wptTest.formatError(err));8 }9 else {10 console.log(data);11 }12});13const wpt = require('wpt');14const wptTest = new wpt('YOUR_API_KEY');15 if (err) {16 console.log(err);17 }18 else {19 console.log(data);20 }21});22const wpt = require('wpt');23const wptTest = new wpt('YOUR_API_KEY');24wptTest.runTest(wptOptions, (err, data) => {25 if (err) {26 console.log(err);27 }28 else {29 console.log(data);30 }31});

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptools = require('wptools');2wptools.page('Barack Obama').get().then((page) => {3 console.log(page.infobox());4});5const wptools = require('wptools');6wptools.page('Barack Obama').get().then((page) => {7 console.log(page.infobox());8});9const wptools = require('wptools');10wptools.page('Barack Obama').get().then((page) => {11 console.log(page.infobox());12});13const wptools = require('wptools');14wptools.page('Barack Obama').get().then((page) => {15 console.log(page.infobox());16});17const wptools = require('wptools');18wptools.page('Barack Obama').get().then((page) => {19 console.log(page.infobox());20});21const wptools = require('wptools');22wptools.page('Barack Obama').get().then((page) => {23 console.log(page.infobox());24});25const wptools = require('wptools');26wptools.page('Barack Obama').get().then((page) => {27 console.log(page.infobox());28});29const wptools = require('wptools');30wptools.page('Barack Obama').get().then((page) => {31 console.log(page.infobox());32});33const wptools = require('wptools');34wptools.page('Barack Obama').get().then((page) => {35 console.log(page.infobox());36});37const wptools = require('wptools');38wptools.page('Barack Obama').get().then((page) => {39 console.log(page.infobox());40});41const wptools = require('wptools');42wptools.page('Bar

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptoolkit = require('wptoolkit');2const error = new wptoolkit.FormatError('Error message', 'Error code', 'Error name');3console.log(error);4{5}6const wptoolkit = require('wptoolkit');7const response = new wptoolkit.FormatResponse('Response data', 'Response code', 'Response name');8console.log(response);9{10}11const wptoolkit = require('wptoolkit');12const success = new wptoolkit.FormatSuccess('Success message', 'Success code', 'Success name');13console.log(success);14{15}16const wptoolkit = require('wptoolkit');17wp.addPost('Test post', 'Test post content', 'test-post', ['post', 'page'], 'publish').then((response) => {18 console.log(response);19});20{21 data: {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt-api');2var wptKey = 'A.4f0e2b2f7e4e1d9c7b9b4e0c7f4f8e0c';3var wptOptions = {4};5wpt.runTest(wptOptions, function(err, data) {6 if (err) {7 console.log('Error: ' + wpt.formatError(err));8 } else {9 console.log('Test ID: ' + data.data.testId);10 }11});

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

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