How to use payload_message method in wpt

Best JavaScript code snippet using wpt

app.js

Source:app.js Github

copy

Full Screen

1var events = require('events');2var mqtt = require('mqtt');3var util = require('util');4var fs = require('fs');5var jsonpath = require('jsonpath');6const express = require('express');7const app = express();8var sensor_ids = [];9var mobius = require('./MobiusConnector').mobius;1011const SENSOR_LIST_FILE = 'sensor_list.txt';12global.conf = require('./conf.js');13var event = new events.EventEmitter();14var keti_mobius = new mobius();15keti_mobius.set_mobius_info(conf.cse.host, conf.cse.port);16var latest_data = [];17var latest_data_count = 0;18function payload_decode(dev_eui,message){19 opcode = message.substring(8,10);20 device_type = message.substring(10,12);21 parking_data = message.substring(12,14);22 battery = message.substring(14,16);23 device_err = message.substring(16,18);24 rssi = message.substring(18,20);25 snr = message.substring(20,22);26 radar_info = message.substring(22,24);27 check_cycle = message.substring(24,26);2829 var packet_json = {};30 //---------------opcode------------------31 if (opcode == '04'){32 packet_json['opcode'] = 'event';33 }34 else if (opcode == '02'){35 packet_json['opcode'] = 'periodic';36 }3738 //------------device info---------------39// sub_json['device_type'] = device_type;40 if (device_type == '10'){41 packet_json['device_type'] = 'Radar';42 }43 else if (device_type == '20'){44 packet_json['device_type'] = 'Magnetic';45 }4647 //------------parking data---------------48 if (parking_data == '30'){49 packet_json['parking'] = 'free';50 }51 else if (parking_data == '31'){52 packet_json['parking'] = 'occupied';53 }5455 //--------------battery----------------56 packet_json['battery'] = parseInt(battery, 16);5758 //--------------device error----------------59 if (device_err == '30'){60 packet_json['device_info'] = 'normal';61 }62 else if (device_err == '31'){63 packet_json['device_info'] = 'sensor_error';64 }65 else if (device_err == '32'){66 packet_json['device_info'] = 'battery_error';67 }68 else if (device_err == '33'){69 packet_json['device_info'] = 'reset';70 }71 else if (device_err == '34'){72 packet_json['device_info'] = 'radar_error';73 }7475 //---------------rssi-----------------76 packet_json['rssi'] = parseInt(rssi, 16);7778 //---------------snr----------------79 packet_json['snr'] = parseInt(snr, 16);;8081 //------------radarinfo---------------82 if (radar_info === '00'){83 packet_json['radar_info'] = 'parking_event';84 }85 else if (radar_info == '01'){86 packet_json['radar_info'] = 'device_init';87 }88 else if (radar_info == '02'){89 packet_json['radar_info'] = 'reboot_reset';90 }91 else if (radar_info == '03'){92 packet_json['radar_info'] = 'system_reset';93 }94 else if (radar_info == '04'){95 packet_json['radar_info'] = 'report';96 }97 else if (radar_info == '05'){98 packet_json['radar_info'] = 'radar_error';99 }100 else if (radar_info == '06'){101 packet_json['radar_info'] = 'radar_repair';102 }103104 //------------checkcycle---------------105 if (check_cycle == '00'){106 packet_json['check_cycle'] = 15;107 direct30_downlink(dev_eui);108 }109 else if (check_cycle == '01'){110 packet_json['check_cycle'] = 30;111 direct30_downlink(dev_eui);112 }113 else if (check_cycle == '02'){114 packet_json['check_cycle'] = 60;115 direct30_downlink(dev_eui);116 }117 else if (check_cycle == '03'){118 packet_json['check_cycle'] = 120;119 direct30_downlink(dev_eui);120 }121 else if (check_cycle == '04'){122 packet_json['check_cycle'] = 180;123 direct30_downlink(dev_eui);124 }125 else if (check_cycle == '05'){126 packet_json['check_cycle'] = 240;127 direct30_downlink(dev_eui);128 }129 else if (check_cycle == '06'){130 packet_json['check_cycle'] = 300;131 direct30_downlink(dev_eui);132 }133 else if (check_cycle == '07'){134 packet_json['check_cycle'] = 600;135 direct30_downlink(dev_eui);136 }137138 //-------------json print-------------139 console.log(packet_json);140 return packet_json141}142function direct15_downlink(devID){//downlink143 console.log(devID + ' Configuration');144145 var payload_message = {}146 var ls_txtopic = util.format('application/2/device/%s/tx', devID);147148// var downlink_message = '7e060114070101007f'; // 15sec149 var downlink_message = '7e07011407010000157f';150 downlink_message = new Buffer.from(downlink_message, 'hex');151 var encode_message = downlink_message.toString('base64');152 // console.log(hex_payload)153 payload_message.confirmed = true;154 payload_message.fPort = 2;155 payload_message.data = encode_message;156 // payload_message.timing = "IMMEDIATELY";157 console.log(payload_message)158 ls_mqtt_client.publish(ls_txtopic, JSON.stringify(payload_message));159}160161function direct30_downlink(devID){//downlink162 console.log(devID + ' Configuration');163164 var payload_message = {}165 var ls_txtopic = util.format('application/2/device/%s/tx', devID);166167 var downlink_message = '7e07011407010001157f';168169// var downlink_message = '7e060114070101017f'; // 30sec170 downlink_message = new Buffer.from(downlink_message, 'hex');171 var encode_message = downlink_message.toString('base64');172 // console.log(hex_payload)173 payload_message.confirmed = true;174 payload_message.fPort = 2;175 payload_message.data = encode_message;176 // payload_message.timing = "IMMEDIATELY";177 console.log(payload_message)178 ls_mqtt_client.publish(ls_txtopic, JSON.stringify(payload_message));179}180181182function ls_downlink(devID,cinObj){//downlink183 console.log(devID + ' Configuration');184185 var payload_message = {}186 var ls_txtopic = util.format('application/2/device/%s/tx', devID);187188 var downlink_message = new Buffer.from(cinObj[0], 'hex');189 var encode_message = downlink_message.toString('base64');190 // console.log(hex_payload)191 payload_message.confirmed = true;192 payload_message.fPort = 2;193 payload_message.data = encode_message;194 // payload_message.timing = "IMMEDIATELY";195 console.log(payload_message)196 ls_mqtt_client.publish(ls_txtopic, JSON.stringify(payload_message));197}198199function read_sensor_id_list(){200 var str = String(fs.readFileSync(SENSOR_LIST_FILE));201 sensor_ids = str.split(',');202 for (i = 0; i < sensor_ids.length; i++){203 sensor_ids[i] = JSON.parse(sensor_ids[i]);204 sensor_ids[i] = sensor_ids[i]["id"];205 }206 console.log(sensor_ids);207}208209function init_mqtt_client() {210 var mobius_connectOptions = {211 host: conf.cse.host,212 port: conf.cse.mqttport,213 protocol: "mqtt",214 keepalive: 10,215 protocolId: "MQTT",216 protocolVersion: 4,217 clean: true,218 reconnectPeriod: 2000,219 connectTimeout: 2000,220 rejectUnauthorized: false221 };222 var ls_connectOptions = {223 host: conf.lora.host,224 port: conf.lora.mqttport,225 protocol: "mqtt",226 keepalive: 10,227 protocolId: "MQTT",228 protocolVersion: 4,229 clean: true,230 reconnectPeriod: 2000,231 connectTimeout: 2000,232 rejectUnauthorized: false233 };234 mqtt_client = mqtt.connect(mobius_connectOptions);235 mqtt_client.on('connect', on_mqtt_connect);236 mqtt_client.on('message', on_mqtt_message_recv);237 ls_mqtt_client = mqtt.connect(ls_connectOptions);238 ls_mqtt_client.on('connect', ls_on_mqtt_connect);239 ls_mqtt_client.on('message', ls_on_mqtt_message_recv);240 console.log("init_mqtt_client!!!");241}242243function on_mqtt_connect() { //mobius mqtt connet244 var noti_topic = util.format('/oneM2M/req/+/%s/#', conf.ae.id);245 mqtt_client.unsubscribe(noti_topic);246 mqtt_client.subscribe(noti_topic);247 console.log('[mqtt_connect] noti_topic : ' + noti_topic);248}249250function ls_on_mqtt_connect() { //lora_app_server mqtt connet251 for (var i = 0; i < sensor_ids.length; i++){252 var ls_rxtopic = util.format('application/2/device/%s/rx', sensor_ids[i].toLowerCase());253 ls_mqtt_client.unsubscribe(ls_rxtopic);254 ls_mqtt_client.subscribe(ls_rxtopic);255 console.log('[ls_mqtt_connect] ls_noti_topic : ' + ls_rxtopic);256 }257}258259function on_mqtt_message_recv(topic, message) {260 console.log('receive message from topic: <- ' + topic);261 console.log('receive message: ' + message.toString());262 var topic_arr = topic.split("/");263 if (topic_arr[1] == 'oneM2M' && topic_arr[2] == 'req' && topic_arr[4] == conf.ae.id) {264 var jsonObj = JSON.parse(JSON.stringify(message.toString()));265 mqtt_noti_action(jsonObj, function (path_arr, cinObj, rqi, sur) {266 if (cinObj) {267 var rsp_topic = '/oneM2M/resp/' + topic_arr[3] + '/' + topic_arr[4] + '/' + topic_arr[5];268269 event.emit('upload', sur, cinObj);270271 response_mqtt(rsp_topic, '2000', '', conf.ae.id, rqi, '');272 }273 });274 }275 else {276 console.log('topic is not supported');277 }278}279280function response_mqtt (rsp_topic, rsc, to, fr, rqi, inpcs) {281282 var rsp_message = {};283 rsp_message['m2m:rsp'] = {};284 rsp_message['m2m:rsp'].rsc = rsc;285 rsp_message['m2m:rsp'].to = to;286 rsp_message['m2m:rsp'].fr = fr;287 rsp_message['m2m:rsp'].rqi = rqi;288 rsp_message['m2m:rsp'].pc = inpcs;289290 mqtt_client.publish(rsp_topic, JSON.stringify(rsp_message));291292 console.log('noti publish -> ' + JSON.stringify(rsp_message));293294}295296function ls_on_mqtt_message_recv(topic, message) {297298 console.log('receive message from topic: <- ' + topic);299 console.log('receive message: ' + message.toString());300 var message_parse= JSON.parse(message);301 var dev_eui = message_parse['devEUI'];302 message_parse = message_parse['data'];303 if (message_parse != null) {304 console.log("payload_message is " + message_parse);305 var new_message = new Buffer.from(message_parse, 'base64');306 var decode_message = new_message.toString('hex');307 var packet_decode = payload_decode(dev_eui,decode_message);308 var cin_path = conf.ae.parent + '/' +conf.ae.name + '/' + dev_eui + '/' + 'up';309 var cin_obj = {310 'm2m:cin':{311 'con': JSON.stringify(packet_decode)312 }313 }314 var hartbeatdata = status_payload(cin_path, packet_decode);315 latest_data[latest_data_count] = hartbeatdata;316 latest_data_count++;317 if(latest_data_count == 3){318 latest_data_count = 0;319 }320 console.log(latest_data);321 var resp = keti_mobius.create_cin(cin_path, cin_obj);322 console.log(resp);323324 }325}326327function init_resource(){328 read_sensor_id_list();329 var ae_obj = {330 'm2m:ae':{331 'api': conf.ae.id,332 'rr': true,333 'rn': conf.ae.name334 }335 };336 var ae_resp = keti_mobius.create_ae(conf.ae.parent, ae_obj);337 console.log(ae_resp);338 if(ae_resp.code == 201 || ae_resp.code == 409){339 var cnt_parent_path = conf.ae.parent + '/' + conf.ae.name;340 for (var i = 0; i < sensor_ids.length; i++) {341 var cnt_sensor_obj = {342 'm2m:cnt':{343 'rn' : sensor_ids[i].toLowerCase()344 }345 };346 var cnt_resp = keti_mobius.create_cnt(cnt_parent_path, cnt_sensor_obj);347 if (cnt_resp.code == 201 || cnt_resp.code == 409){348 var cnt2_parent_path = cnt_parent_path +'/'+ sensor_ids[i].toLowerCase();349 var cnt_upobj = {350 'm2m:cnt':{351 'rn' : "up"352 }353 };354 var cnt_downobj = {355 'm2m:cnt':{356 'rn' : "down"357 }358 };359 cnt_resp = keti_mobius.create_cnt(cnt2_parent_path, cnt_upobj);360 if(cnt_resp.code == 201 || cnt_resp.code == 409){361 cnt_resp = keti_mobius.create_cnt(cnt2_parent_path, cnt_downobj);362 if(cnt_resp.code == 201 || cnt_resp.code == 409 ){363 console.log(sensor_ids[i] + " CNT_Complete!!");364 }365 }366 }367 }368 var sub_ae_parent_path = conf.ae.parent + '/' + conf.ae.name;369 var sub_body = {nu:['mqtt://' + conf.cse.host +'/'+ conf.ae.id + '?ct=json']};370 var sub_obj = {371 'm2m:sub':372 {373 'rn' : "sub_container_check",374 'enc': {'net': [4]},375 'nu' : sub_body.nu,376 'nct': 2377 }378 };379 var sub_checker_path = sub_ae_parent_path+'/'+'sub_container_check';380 var resp_sub = keti_mobius.retrieve_sub(sub_checker_path);381 if (resp_sub.code == 200) {382 resp_sub = keti_mobius.delete_res(sub_checker_path);383 if (resp_sub.code == 200) {384 resp_sub = keti_mobius.create_sub(sub_ae_parent_path, sub_obj);385 }386 } 387 else if (resp_sub.code == 404) {388 keti_mobius.create_sub(sub_ae_parent_path, sub_obj);389 }390 else{391392 }393 for (var i = 0; i < sensor_ids.length; i++) {394 var sub_downlink = sub_ae_parent_path + '/'+ sensor_ids[i].toLowerCase() +'/'+"down";395 var sub_body = {nu:['mqtt://' + conf.cse.host +'/'+ conf.ae.id + '?ct=json']};396 var sub_obj = {397 'm2m:sub':398 {399 'rn' : "sub_downlink",400 'enc': {'net': [3]},401 'nu' : sub_body.nu,402 'nct': 2403 }404 };405 var sub_path = sub_downlink +'/'+"sub_downlink";406 var resp_sub = keti_mobius.retrieve_sub(sub_path);407408 if (resp_sub.code == 200) {409 resp_sub = keti_mobius.delete_res(sub_path);410411 if (resp_sub.code == 200) {412 resp_sub = keti_mobius.create_sub(sub_downlink, sub_obj);413 414 }415 } 416 else if (resp_sub.code == 404) {417 keti_mobius.create_sub(sub_downlink, sub_obj);418 }419 else{420421 }422 if(resp_sub.code == 201 || resp_sub.code == 409){423 console.log("SUB_Complete!!");424 }425 }426 init_mqtt_client();427 status_Check();428 }429}430431function mqtt_noti_action(jsonObj, callback) {432 if (jsonObj != null) {433 var net = JSON.stringify(jsonpath.query(JSON.parse(jsonObj), '$..net'));434 net=net.replace("\"", "").replace("]", "").replace("[", "").replace("\"", "");435 var path_arr= JSON.stringify(jsonpath.query(JSON.parse(jsonObj),'$..sur'));436 var cinObj= jsonpath.query(JSON.parse(jsonObj),'$..con');437 var sur = path_arr.split('/');438439 if(net == '3'){440 var devID = sur[2].toLowerCase();441 ls_downlink(devID,cinObj);//sensingserver or442 }443 else if (net == '4'){444 var cnt_parent_path = conf.ae.parent + '/' + conf.ae.name;445 var rn = JSON.stringify(jsonpath.query(JSON.parse(jsonObj), '$..rn'));446 rn=rn.replace("\"", "").replace("]", "").replace("[", "").replace("\"", "");447 console.log(rn);448 var retry_cnt_sensor_obj = {449 'm2m:cnt':{450 'rn' : rn451 }452 };1453 var cnt_resp = keti_mobius.create_cnt(cnt_parent_path, retry_cnt_sensor_obj);454 if (cnt_resp.code == 201 || cnt_resp.code == 409){455 var cnt2_parent_path = cnt_parent_path +'/'+ rn;456 var cnt_upobj = {457 'm2m:cnt':{458 'rn' : "up"459 }460 };461 var cnt_downobj = {462 'm2m:cnt':{463 'rn' : "down"464 }465 };466 var cnt_resp2 = keti_mobius.create_cnt(cnt2_parent_path, cnt_upobj);467 if(cnt_resp2.code == 201 || cnt_resp2.code == 409){468 var cnt_resp3 = keti_mobius.create_cnt(cnt2_parent_path, cnt_downobj);469 }470 if(cnt_resp3.code == 201 || cnt_resp3.code == 409 ){471 console.log("Container Recreate!");472 var sub_parent_path = cnt2_parent_path +'/'+"down";473 var sub_body = {nu:['mqtt://' + conf.cse.host +'/'+ conf.ae.id + '?ct=json']};474 var sub_obj = {475 'm2m:sub':476 {477 'rn' : "sub_lora_sensor",478 'enc': {'net': [3]},479 'nu' : sub_body.nu,480 'nct': 2481 }482 };483 var sub_path = sub_parent_path +'/'+"sub_lora_sensor";484 var resp_sub = keti_mobius.retrieve_sub(sub_path);485486 if (resp_sub.code == 200) {487 resp_sub = keti_mobius.create_sub(sub_parent_path, sub_obj);488489 }490 else if (resp_sub.code == 404) {491 keti_mobius.create_sub(sub_parent_path, sub_obj);492 }493 }494 }495 }496 }497 else {498 console.log('[mqtt_noti_action] message is not noti');499 }500}501502setTimeout(init_resource,100)503504var keti_mobius_hartbeat = new mobius();505keti_mobius_hartbeat.set_mobius_info('203.253.128.164', conf.cse.port);506507function status_payload(path,packet_decode){508 var times = new Date();509 var timestamp = times.toISOString().replace(/-/, '').replace(/-/, '').replace(/:/, '').replace(/:/, '').replace(/\..+/, '');510 var hartbeatcheck = {511 timestamp: timestamp,512 targetResID: path,513 data: packet_decode514 };515 return hartbeatcheck516}517function status_Check(){518519 var cin_path = '/Mobius/sync_parking/heartbeat/LoRa_IPE';520 setInterval(function(){521 var cin_obj = {522 'm2m:cin':{523 'con': JSON.stringify(latest_data)524 }525 };526 var resp = keti_mobius_hartbeat.create_cin(cin_path, cin_obj);527 console.log(resp);528//},10000);529},1800000);530 /*app.get('/status', (req, res) => {531 const healthcheck = {532 uptime: process.uptime(),533 status: "UP",534 timestamp: Date.now()535 };536 res.send(healthcheck);537 });538 // app.get('/errlog', (req, res) => {539 // if(fs.existsSync(err_log)){540 // var log = fs.readFileSync(err_log);541 // res.send(log);542 // // fs.unlinkSync(err_log);543 // }544 // else{545 // res.send({status:""});546 // }547 // });548 app.listen(conf.health.port, () => {549 console.log('Health Checker Start');550 });551 */552} ...

Full Screen

Full Screen

reducers.test.js

Source:reducers.test.js Github

copy

Full Screen

1import gameReducer from "../reducers/game";2import * as types from "../constants/ActionTypes";3import { POINTS, SIZE } from "../constants/BoardKeys";4import {5 BOARD,6 CONNECTED,7 MESSAGE,8 REJOIN_NEEDED,9 KEYS as KEYS_STATE,10 YOUR_COLOR as YOUR_COLOR_STATE,11 PAST_GAMES,12 OPPONENT_CONNECTED,13 CHAT_MESSAGES,14} from "../constants/StateKeys";15import {16 EXPLANATION,17 KEYS as KEYS_MSG,18 SUCCESS,19 YOUR_COLOR as YOUR_COLOR_MSG,20} from "../constants/IncomingMessageDataKeys";21import { clearMessage, clearRejoinNeeded } from "../actions";22import {23 DATA,24 MESSAGE_TYPE,25 MESSAGE as PAYLOAD_MESSAGE,26} from "../constants/IncomingMessagePayloadKeys";27import {28 GAME_ACTION_RESPONSE,29 GAME_STATUS,30 JOIN_GAME_RESPONSE,31 NEW_GAME_RESPONSE,32} from "../constants/IncomingMessageTypes";33import { BLACK, WHITE } from "../constants/Colors";34describe("game reducer", () => {35 const initialState = {36 [BOARD]: {37 [SIZE]: 19,38 [POINTS]: Array.from({ length: 19 }, () =>39 Array.from({ length: 19 }, () => ["", false, false, ""])40 ),41 },42 [CONNECTED]: false,43 [PAST_GAMES]: {},44 };45 it("should return the initial state", () => {46 expect(gameReducer(undefined, {})).toEqual(initialState);47 });48 it("should clear a message", () => {49 expect(50 gameReducer(51 { [MESSAGE]: "blah blah good boy blah what a good boy blah" },52 clearMessage()53 )54 ).toEqual({ [MESSAGE]: "" });55 });56 it("should clear rejoin needed", () => {57 expect(gameReducer({ [REJOIN_NEEDED]: true }, clearRejoinNeeded())).toEqual(58 { [REJOIN_NEEDED]: false }59 );60 });61 it("should set connected and unset rejoined needed", () => {62 expect(63 gameReducer({ [CONNECTED]: false }, { type: types.WS_OPEN })64 ).toEqual({ [CONNECTED]: true, [REJOIN_NEEDED]: false });65 });66 it("should set connected and rejoined needed", () => {67 expect(68 gameReducer(69 { [CONNECTED]: false, [KEYS_STATE]: {} },70 { type: types.WS_OPEN }71 )72 ).toMatchObject({ [CONNECTED]: true, [REJOIN_NEEDED]: true });73 });74 it("should unset connected", () => {75 expect(76 gameReducer({ [CONNECTED]: true }, { type: types.WS_CLOSED })77 ).toMatchObject({ [CONNECTED]: false });78 });79});80describe("game reducer incoming message", () => {81 const keysState = { [WHITE]: "9876543210", [BLACK]: "0123456789" };82 const keysResponse = { [WHITE]: "0123456789", [BLACK]: "9876543210" };83 const msgSuccess = "Success";84 const msgFailure = "Failure";85 const newGameResponseSuccess = {86 type: types.WS_MESSAGE,87 payload: {88 [PAYLOAD_MESSAGE]: {89 [MESSAGE_TYPE]: NEW_GAME_RESPONSE,90 [DATA]: {91 [SUCCESS]: true,92 [KEYS_MSG]: keysResponse,93 [YOUR_COLOR_MSG]: WHITE,94 [EXPLANATION]: msgSuccess,95 },96 },97 },98 };99 it("should write keys, color, and message (new game)", () => {100 expect(gameReducer({}, newGameResponseSuccess)).toEqual({101 [KEYS_STATE]: keysResponse,102 [YOUR_COLOR_STATE]: WHITE,103 [MESSAGE]: msgSuccess,104 });105 });106 const newGameResponseFailure = {107 type: types.WS_MESSAGE,108 payload: {109 [PAYLOAD_MESSAGE]: {110 [MESSAGE_TYPE]: NEW_GAME_RESPONSE,111 [DATA]: {112 [SUCCESS]: false,113 [EXPLANATION]: msgFailure,114 },115 },116 },117 };118 it("should retain old keys and color and write message (new game)", () => {119 expect(120 gameReducer(121 {122 [KEYS_STATE]: keysState,123 [YOUR_COLOR_STATE]: BLACK,124 },125 newGameResponseFailure126 )127 ).toEqual({128 [KEYS_STATE]: keysState,129 [YOUR_COLOR_STATE]: BLACK,130 [MESSAGE]: msgFailure,131 });132 });133 const joinGameResponseSuccess = JSON.parse(134 JSON.stringify(newGameResponseSuccess)135 );136 joinGameResponseSuccess.payload[PAYLOAD_MESSAGE][MESSAGE_TYPE] =137 JOIN_GAME_RESPONSE;138 it("should write keys, color, and message (join game)", () => {139 expect(gameReducer({}, joinGameResponseSuccess)).toEqual({140 [KEYS_STATE]: keysResponse,141 [YOUR_COLOR_STATE]: WHITE,142 [MESSAGE]: msgSuccess,143 });144 });145 const joinGameResponseFailure = JSON.parse(146 JSON.stringify(newGameResponseFailure)147 );148 joinGameResponseFailure.payload[PAYLOAD_MESSAGE][MESSAGE_TYPE] =149 JOIN_GAME_RESPONSE;150 it("should retain old keys and color and write message (join game)", () => {151 expect(152 gameReducer(153 {154 [KEYS_STATE]: keysState,155 [YOUR_COLOR_STATE]: BLACK,156 },157 joinGameResponseFailure158 )159 ).toEqual({160 [KEYS_STATE]: keysState,161 [YOUR_COLOR_STATE]: BLACK,162 [MESSAGE]: msgFailure,163 });164 });165 const gameActionSuccess = {166 type: types.WS_MESSAGE,167 payload: {168 [PAYLOAD_MESSAGE]: {169 [MESSAGE_TYPE]: GAME_ACTION_RESPONSE,170 [DATA]: {171 [SUCCESS]: true,172 [EXPLANATION]: msgSuccess,173 },174 },175 },176 };177 it("should not write a message", () => {178 expect(gameReducer({}, gameActionSuccess)).toEqual({});179 });180 const gameActionFailure = {181 type: types.WS_MESSAGE,182 payload: {183 [PAYLOAD_MESSAGE]: {184 [MESSAGE_TYPE]: GAME_ACTION_RESPONSE,185 [DATA]: {186 [SUCCESS]: false,187 [EXPLANATION]: msgFailure,188 },189 },190 },191 };192 it("should write a message", () => {193 expect(gameReducer({}, gameActionFailure)).toEqual({194 [MESSAGE]: msgFailure,195 });196 });197 const updatedBoard = {198 [BOARD]: {199 [SIZE]: 19,200 [POINTS]: Array.from({ length: 19 }, () =>201 Array.from({ length: 19 }, () => ["w", false, false, ""])202 ),203 },204 };205 const gameStatus = {206 type: types.WS_MESSAGE,207 payload: {208 [PAYLOAD_MESSAGE]: {209 [MESSAGE_TYPE]: GAME_STATUS,210 [DATA]: updatedBoard,211 },212 },213 };214 const myKey = keysState[WHITE];215 const theirKey = keysState[BLACK];216 const initStateWithKeys = {217 [KEYS_STATE]: keysState,218 [YOUR_COLOR_STATE]: WHITE,219 [PAST_GAMES]: { [myKey]: 0, [theirKey]: 0 },220 };221 it("should update the board", () => {222 expect(gameReducer(initStateWithKeys, gameStatus)).toEqual(223 expect.objectContaining(updatedBoard)224 );225 });226 it("should update past games", () => {227 const newState = gameReducer(initStateWithKeys, gameStatus);228 expect(newState[PAST_GAMES][myKey]).toBeGreaterThan(0);229 });230 it("should not blow away unrelated past games state", () => {231 const newState = gameReducer(initStateWithKeys, gameStatus);232 expect(newState[PAST_GAMES][theirKey]).toBe(0);233 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('webpagetest');2const wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.error(err);4 console.log('Test status:', data.statusText);5 wpt.getTestResults(data.data.testId, function(err, data) {6 if (err) return console.error(err);7 console.log('SpeedIndex:', data.data.average.firstView.SpeedIndex);8 });9});10const wpt = require('webpagetest');11const wpt = new WebPageTest('www.webpagetest.org');12 if (err) return console.error(err);13 console.log('Test status:', data.statusText);14 wpt.getTestResults(data.data.testId, function(err, data) {15 if (err) return console.error(err);16 console.log('SpeedIndex:', data.data.average.firstView.SpeedIndex);17 });18});19const wpt = require('webpagetest');20const wpt = new WebPageTest('www.webpagetest.org');21 if (err) return console.error(err);22 console.log('Test status:', data.statusText);23 wpt.getTestResults(data.data.testId, function(err, data) {24 if (err) return console.error(err);25 console.log('SpeedIndex:', data.data.average.firstView.SpeedIndex);26 });27});28const wpt = require('webpagetest');29const wpt = new WebPageTest('www.webpagetest.org');30 if (err) return console.error(err);31 console.log('Test status:', data.statusText);32 wpt.getTestResults(data.data.testId, function(err, data) {33 if (err) return console.error(err);34 console.log('SpeedIndex:', data.data.average.firstView.SpeedIndex);35 });36});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wiki = wptools.page('Albert Einstein');3wiki.get(function(err, resp) {4 if (!err) {5 console.log(resp.payload.message);6 }7});8var wptools = require('wptools');9var wiki = wptools.page('Albert Einstein');10wiki.get(function(err, resp) {11 if (!err) {12 console.log(resp.payload.links);13 }14});

Full Screen

Using AI Code Generation

copy

Full Screen

1var payload_message = require('../lib/wptools').payload_message;2var payload_message = require('../lib/wptools').payload_message;3var payload_message = require('../lib/wptools').payload_message;4var payload_message = require('../lib/wptools').payload_message;5var payload_message = require('../lib/wptools').payload_message;6var payload_message = require('../lib/wptools').payload_message;7var payload_message = require('../lib/wptools').payload_message;8var payload_message = require('../lib/wptools').payload_message;9var payload_message = require('../lib/wptools').payload_message;10var payload_message = require('../lib/wptools').payload_message;11var payload_message = require('../lib/wptools').payload_message;

Full Screen

Using AI Code Generation

copy

Full Screen

1var payload_message = require('wptools').payload_message;2var message = payload_message('Hello World');3console.log(message);4var payload_message = require('wptools').payload_message;5var message = payload_message('Hello World');6console.log(message);7var payload_message = require('wptools').payload_message;8var message = payload_message('Hello World');9console.log(message);10var payload_message = require('wptools').payload_message;11var message = payload_message('Hello World');12console.log(message);13var payload_message = require('wptools').payload_message;14var message = payload_message('Hello World');15console.log(message);16var payload_message = require('wptools').payload_message;17var message = payload_message('Hello World');18console.log(message);19var payload_message = require('wptools').payload_message;20var message = payload_message('Hello World');21console.log(message);22var payload_message = require('wptools').payload_message;23var message = payload_message('Hello World');24console.log(message);25var payload_message = require('wptools').payload_message;26var message = payload_message('Hello World');27console.log(message);28var payload_message = require('wptools').payload_message;29var message = payload_message('Hello World');30console.log(message);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wpt = wptools('Barack Obama');3wpt.payload_message(function(err, resp) {4 console.log(resp);5});6{ status: 'error',7 { code: 'missingtitle',

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('./index.js');2var payload_message = wptools.payload_message;3var message = payload_message('test', 'test', 'test');4console.log(message);5{6}7MIT © [Aman Mittal](

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2wpt.payload_message('test', 'test message');3#### wpt.payload_message(test_id, message)4#### wpt.get_test_info(test_id)5**Returns** - [TestInfo](#testinfo)6#### wpt.get_test_status(test_id)7**Returns** - [TestStatus](#teststatus)8#### wpt.get_test_results(test_id)9**Returns** - [TestResults](#testresults)10#### wpt.get_test_pagespeed_score(test_id)11**Returns** - [PageSpeedScore](#pagespeedscore)12#### wpt.get_test_video(test_id)13**Returns** - [TestVideo](#testvideo)14#### wpt.get_test_requests(test_id)15**Returns** - [TestRequests](#testrequests)16#### wpt.get_test_breakdown(test_id)17**Returns** - [TestBreakdown](#testbreakdown)18#### wpt.get_test_pages(test_id)

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