Best JavaScript code snippet using mountebank
requestFiles.controller.js
Source:requestFiles.controller.js
1"use strict";2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {3 return new (P || (P = Promise))(function (resolve, reject) {4 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }5 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }6 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }7 step((generator = generator.apply(thisArg, _arguments || [])).next());8 });9};10Object.defineProperty(exports, "__esModule", { value: true });11Promise = require("bluebird");12var fs = require("fs");13var deep = require('deep-diff').diff;14var mongoose = require("mongoose");15var ObjectId = require('mongodb').ObjectID;16mongoose.Promise = require("bluebird");17var helperService = require('../../services/helper.service');18// import { HelperService } from '../../services/helper.service';19var DBConnect = require('../../services/dbConnect.service');20var ConstantsBase = require('../../config/base/constants.base');21var response = require('../../services/response.service');22var fileService = require('../../services/files.service');23var RequestFileSchema = require('./requestFile.schema');24var RequestFileHistorySchema = require('./requestFile.history.schema');25var notificationsController = require('../../modules/notification/notifications.controller');26var requestHistoriesController = require('../requestHistories/requestHistories.controller');27var RequestFilesController = {28 getModel: (req, res) => __awaiter(this, void 0, void 0, function* () {29 return DBConnect.connectSystemDB(req, res, 'RequestFile', RequestFileSchema);30 }),31 getHistoryModel: (req, res) => __awaiter(this, void 0, void 0, function* () {32 return DBConnect.connectSystemDB(req, res, 'RequestFileHistory', RequestFileHistorySchema);33 }),34 findFilesByRequestId: (req, res) => __awaiter(this, void 0, void 0, function* () {35 try {36 if (!req.params._id) {37 const result = {38 message: `${req.params._id} is required!`,39 };40 return response.fail_badRequest(res, result);41 }42 else {43 let RequestFiles = yield RequestFilesController.getModel(req, res);44 let requestFiles = yield RequestFiles.find({ docId: req.params._id });45 // console.log(requestFiles);46 if (!requestFiles) {47 return response.fail_notFound(res);48 }49 else {50 const result = {51 message: '',52 data: requestFiles,53 total: requestFiles.length54 };55 return response.ok(res, result);56 }57 }58 }59 catch (err) {60 response.fail_serverError(res, err);61 }62 }),63 findFileById: (req, res) => __awaiter(this, void 0, void 0, function* () {64 }),65 uploadRequestFile: (req, res) => __awaiter(this, void 0, void 0, function* () {66 try {67 if (!mongoose.Types.ObjectId.isValid(req.params._id)) {68 const result = {69 message: `${req.params._id} is invalid Id!`,70 };71 return response.fail_badRequest(res, result);72 }73 else {74 // console.log(req.params._id);75 // console.log('body:', req.body);76 // console.log('files:', req['files']);77 let uploadStatus = yield fileService.uploadRequestDocument(req, res);78 let data = uploadStatus.data;79 // Store information into DB80 let RequestFiles = yield RequestFilesController.getModel(req, res);81 let requestFiles = new RequestFiles(data);82 // let requestFiles = new RequestFiles({83 // docId: req.params._id,84 // originalname: data.originalname,85 // path: data.path,86 // desc: data.originalname,87 // size: data.size,88 // mimetype: data.mimetype,89 // username: req['mySession'].username,90 // status: 'Unmarked'91 // });92 // console.log(requestFiles);93 let createdFile = yield requestFiles.save();94 // console.log(createdFile);95 // TODO: Save the first history96 const historyObject = {97 "type": "comment",98 "docId": req.params._id,99 "header": "<a href='#'>" + req['mySession'].username + "</a> upload a file!",100 "body": "Filename: " + data.originalname,101 "footer": "",102 };103 let createdHistory = yield requestHistoriesController.module11(req, res, historyObject);104 helperService.log(createdHistory);105 const result = {106 message: 'Creation completed!',107 data: createdFile108 };109 return response.ok_created(res, result);110 }111 }112 catch (err) {113 response.fail_serverError(res, err);114 }115 }),116 uploadRequestFiles: (req, res) => __awaiter(this, void 0, void 0, function* () {117 }),118 downloadRequestFile: (req, res) => __awaiter(this, void 0, void 0, function* () {119 try {120 if (!mongoose.Types.ObjectId.isValid(req.params._id)) {121 const result = {122 message: `${req.params._id} is invalid Id!`,123 };124 return response.fail_badRequest(res, result);125 }126 else {127 let RequestFiles = yield RequestFilesController.getModel(req, res);128 let requestFiles = yield RequestFiles.findById(req.params._id);129 if (!requestFiles) {130 return response.fail_notFound(res);131 }132 else {133 // console.log('Generate temporary file for download');134 let originalname = yield fileService.downloadRequestDocument(req, res, requestFiles);135 // helperService.log(req.body);136 // specify tcode of download137 // dl = download138 // in other case tcode is store in (req.body.tcode)139 const notification = {140 tcode: 'dl',141 id: '',142 icon: 'file_download',143 desc: originalname + ' is ready for download!',144 url: originalname,145 data: {146 icon: 'file_download',147 desc: originalname + ' is ready for download!',148 url: originalname149 },150 username: req['mySession']['username'],151 creator: 'system',152 isMark: true153 };154 // helperService.log(notification);155 let notificationResult = yield notificationsController.module11(req, res, notification);156 const result = {157 message: '',158 data: notificationResult159 };160 setTimeout(() => { response.ok(res, result); }, 5000);161 }162 }163 }164 catch (err) {165 response.fail_serverError(res, err);166 }167 }),168 renameRequestFile: (req, res) => __awaiter(this, void 0, void 0, function* () {169 try {170 if (!mongoose.Types.ObjectId.isValid(req.params._id)) {171 const result = {172 message: `${req.params._id} is invalid Id!`,173 };174 return response.fail_badRequest(res, result);175 }176 else {177 let RequestFiles = yield RequestFilesController.getModel(req, res);178 let requestFile = yield RequestFiles.findById(req.params._id);179 if (!requestFile) {180 return response.fail_notFound(res);181 }182 else {183 // console.log(req.body);184 const originalName = requestFile.desc;185 requestFile.desc = req.body.desc;186 let updatedFile = yield requestFile.save();187 // TODO: Save the first history188 const historyObject = {189 "type": "comment",190 "docId": requestFile.docId,191 "header": "<a href='#'>" + req['mySession'].username + "</a> rename a file!",192 "body": "Original name: " + originalName + ". New name: " + req.body.desc,193 "footer": "",194 };195 let createdHistory = yield requestHistoriesController.module11(req, res, historyObject);196 helperService.log(createdHistory);197 if (updatedFile) {198 const result = {199 data: updatedFile,200 };201 return response.ok(res, result);202 }203 else {204 throw new Error('Patch failed!');205 }206 }207 }208 }209 catch (err) {210 response.fail_serverError(res, err);211 }212 }),213 patchRequestFile: (req, res, patchType) => __awaiter(this, void 0, void 0, function* () {214 try {215 if (!mongoose.Types.ObjectId.isValid(req.params._id)) {216 const result = {217 message: `${req.params._id} is invalid Id!`,218 };219 return response.fail_badRequest(res, result);220 }221 else {222 let RequestFiles = yield RequestFilesController.getModel(req, res);223 let requestFile = yield RequestFiles.findById(req.params._id);224 if (!requestFile) {225 return response.fail_notFound(res);226 }227 else {228 const status = requestFile.status;229 switch (patchType) {230 case 'mark':231 if (status === 'Unmarked') {232 requestFile.status = 'Marked';233 }234 break;235 case 'unmark':236 if (status === 'Marked') {237 requestFile.status = 'Unmarked';238 }239 break;240 default:241 break;242 }243 let updatedFile = yield requestFile.save();244 // TODO: Save the first history245 const historyObject = {246 "type": "comment",247 "docId": requestFile.docId,248 "header": "<a href='#'>" + req['mySession'].username + "</a> patch a file!",249 "body": "Patch action: " + patchType,250 "footer": "",251 };252 let createdHistory = yield requestHistoriesController.module11(req, res, historyObject);253 helperService.log(createdHistory);254 if (updatedFile) {255 const result = {256 data: updatedFile,257 };258 return response.ok(res, result);259 }260 else {261 throw new Error('Patch failed!');262 }263 }264 }265 }266 catch (err) {267 response.fail_serverError(res, err);268 }269 }),270 markRequestFile: (req, res) => __awaiter(this, void 0, void 0, function* () {271 RequestFilesController.patchRequestFile(req, res, 'mark');272 }),273 unmarkRequestFile: (req, res) => __awaiter(this, void 0, void 0, function* () {274 RequestFilesController.patchRequestFile(req, res, 'unmark');275 }),276 deleteRequestFile: (req, res) => __awaiter(this, void 0, void 0, function* () {277 try {278 const tcode = 'gkcln18';279 if (!mongoose.Types.ObjectId.isValid(req.params._id)) {280 const result = {281 message: `${req.params._id} is invalid Id!`,282 };283 return response.fail_badRequest(res, result);284 }285 else {286 let RequestFiles = yield RequestFilesController.getModel(req, res);287 let requestFiles = yield RequestFiles.findById(req.params._id);288 if (!requestFiles) {289 return response.fail_notFound(res);290 }291 else {292 if (requestFiles.status == 'Marked') {293 let removedFile = yield requestFiles.remove();294 if (removedFile) {295 // console.log(removedClient);296 // const trackParams = {297 // multi: false,298 // tcode: tcode,299 // oldData: removedClient.toObject(),300 // newData: {_id:''}301 // }302 // let trackHistory = GkClientsController.trackHistory(req, res, trackParams);303 // TODO: Save the first history304 const historyObject = {305 "type": "comment",306 "docId": removedFile.docId,307 "header": "<a href='#'>" + req['mySession'].username + "</a> remove a file!",308 "body": "File info: " + JSON.stringify(removedFile),309 "footer": "",310 };311 let createdHistory = yield requestHistoriesController.module11(req, res, historyObject);312 helperService.log(createdHistory);313 const result = {314 data: removedFile,315 };316 return response.ok(res, result);317 }318 else {319 throw new Error('Remove failed!');320 }321 }322 else {323 const result = {324 message: 'Only marked document could be deleted!',325 data: {},326 };327 return response.fail_preCondition(res, result);328 }329 }330 }331 }332 catch (err) {333 response.fail_serverError(res, err);334 }335 })336};...
requestFiles.controller.ts
Source:requestFiles.controller.ts
1import express = require("express");2Promise = require("bluebird");3var fs = require("fs");4var deep = require('deep-diff').diff;5var mongoose = require("mongoose");6var ObjectId = require('mongodb').ObjectID;7mongoose.Promise = require("bluebird");8var helperService = require('../../services/helper.service');9// import { HelperService } from '../../services/helper.service';10var DBConnect = require('../../services/dbConnect.service');11var ConstantsBase = require('../../config/base/constants.base');12var response = require('../../services/response.service');13var fileService = require('../../services/files.service');14var RequestFileSchema = require('./requestFile.schema');15var RequestFileHistorySchema = require('./requestFile.history.schema');16var notificationsController = require('../../modules/notification/notifications.controller');17var requestHistoriesController = require('../requestHistories/requestHistories.controller');18var RequestFilesController = {19 getModel: async (req: express.Request, res: express.Response) => {20 return DBConnect.connectSystemDB(req, res, 'RequestFile', RequestFileSchema);21 },22 getHistoryModel: async (req: express.Request, res: express.Response) => {23 return DBConnect.connectSystemDB(req, res, 'RequestFileHistory', RequestFileHistorySchema);24 },25 findFilesByRequestId: async (req: express.Request, res: express.Response) => {26 try {27 if (!req.params._id) {28 const result = {29 message: `${req.params._id} is required!`,30 }31 return response.fail_badRequest(res, result);32 } else {33 let RequestFiles = await RequestFilesController.getModel(req, res);34 let requestFiles = await RequestFiles.find({docId: req.params._id});35 // console.log(requestFiles);36 if (!requestFiles) {37 return response.fail_notFound(res);38 } else {39 const result = {40 message: '',41 data: requestFiles,42 total: requestFiles.length43 }44 return response.ok(res, result);45 }46 }47 }48 catch (err) {49 response.fail_serverError(res, err);50 }51 },52 findFileById: async (req: express.Request, res: express.Response) => {53 },54 uploadRequestFile: async (req: express.Request, res: express.Response) => {55 try {56 if (!mongoose.Types.ObjectId.isValid(req.params._id)) {57 const result = {58 message: `${req.params._id} is invalid Id!`,59 }60 return response.fail_badRequest(res, result);61 } else {62 // console.log(req.params._id);63 // console.log('body:', req.body);64 // console.log('files:', req['files']);65 let uploadStatus = await fileService.uploadRequestDocument(req, res);66 let data = uploadStatus.data;67 // Store information into DB68 let RequestFiles = await RequestFilesController.getModel(req, res);69 let requestFiles = new RequestFiles(data);70 // let requestFiles = new RequestFiles({71 // docId: req.params._id,72 // originalname: data.originalname,73 // path: data.path,74 // desc: data.originalname,75 // size: data.size,76 // mimetype: data.mimetype,77 // username: req['mySession'].username,78 // status: 'Unmarked'79 // });80 // console.log(requestFiles);81 let createdFile = await requestFiles.save();82 // console.log(createdFile);83 // TODO: Save the first history84 const historyObject = {85 "type" : "comment",86 "docId" : req.params._id,87 "header" : "<a href='#'>" + req['mySession'].username + "</a> upload a file!",88 "body" : "Filename: " + data.originalname,89 "footer" : "",90 }91 let createdHistory = await requestHistoriesController.module11(req, res, historyObject);92 helperService.log(createdHistory);93 const result = {94 message: 'Creation completed!',95 data: createdFile96 }97 return response.ok_created(res, result);98 }99 }100 catch (err) {101 response.fail_serverError(res, err);102 }103 },104 uploadRequestFiles: async (req: express.Request, res: express.Response) => {105 },106 downloadRequestFile: async (req: express.Request, res: express.Response) => {107 try {108 if (!mongoose.Types.ObjectId.isValid(req.params._id)) {109 const result = {110 message: `${req.params._id} is invalid Id!`,111 }112 return response.fail_badRequest(res, result);113 } else {114 let RequestFiles = await RequestFilesController.getModel(req, res);115 let requestFiles = await RequestFiles.findById(req.params._id);116 if (!requestFiles) {117 return response.fail_notFound(res);118 } else {119 // console.log('Generate temporary file for download');120 let originalname = await fileService.downloadRequestDocument(req, res, requestFiles);121 // helperService.log(req.body);122 // specify tcode of download123 // dl = download124 // in other case tcode is store in (req.body.tcode)125 const notification = {126 tcode: 'dl',127 id: '',128 icon: 'file_download',129 desc: originalname + ' is ready for download!',130 url: originalname,131 data: {132 icon: 'file_download',133 desc: originalname + ' is ready for download!',134 url: originalname135 },136 username: req['mySession']['username'],137 creator: 'system',138 isMark: true139 }140 // helperService.log(notification);141 let notificationResult = await notificationsController.module11(req, res, notification);142 const result = {143 message: '',144 data: notificationResult145 }146 setTimeout(()=>{response.ok(res, result);}, 5000);147 }148 }149 }150 catch (err) {151 response.fail_serverError(res, err);152 }153 },154 renameRequestFile: async (req: express.Request, res: express.Response) => {155 try {156 if (!mongoose.Types.ObjectId.isValid(req.params._id)) {157 const result = {158 message: `${req.params._id} is invalid Id!`,159 }160 return response.fail_badRequest(res, result);161 } else {162 let RequestFiles = await RequestFilesController.getModel(req, res);163 let requestFile = await RequestFiles.findById(req.params._id);164 if (!requestFile) {165 return response.fail_notFound(res);166 } else {167 // console.log(req.body);168 const originalName = requestFile.desc;169 requestFile.desc = req.body.desc;170 let updatedFile = await requestFile.save();171 // TODO: Save the first history172 const historyObject = {173 "type" : "comment",174 "docId" : requestFile.docId,175 "header" : "<a href='#'>" + req['mySession'].username + "</a> rename a file!",176 "body" : "Original name: " + originalName + ". New name: " + req.body.desc,177 "footer" : "",178 }179 let createdHistory = await requestHistoriesController.module11(req, res, historyObject);180 helperService.log(createdHistory);181 if (updatedFile) {182 const result = {183 data: updatedFile,184 }185 return response.ok(res, result);186 } else {187 throw new Error('Patch failed!');188 }189 }190 }191 }192 catch (err) {193 response.fail_serverError(res, err);194 }195 },196 patchRequestFile: async (req: express.Request, res: express.Response, patchType) => {197 try {198 if (!mongoose.Types.ObjectId.isValid(req.params._id)) {199 const result = {200 message: `${req.params._id} is invalid Id!`,201 }202 return response.fail_badRequest(res, result);203 } else {204 let RequestFiles = await RequestFilesController.getModel(req, res);205 let requestFile = await RequestFiles.findById(req.params._id);206 if (!requestFile) {207 return response.fail_notFound(res);208 } else {209 const status = requestFile.status;210 switch (patchType) {211 case 'mark':212 if (status==='Unmarked'){213 requestFile.status = 'Marked';214 }215 break;216 case 'unmark':217 if (status==='Marked'){218 requestFile.status = 'Unmarked';219 }220 break;221 default:222 break;223 }224 let updatedFile = await requestFile.save();225 // TODO: Save the first history226 const historyObject = {227 "type" : "comment",228 "docId" : requestFile.docId,229 "header" : "<a href='#'>" + req['mySession'].username + "</a> patch a file!",230 "body" : "Patch action: " + patchType,231 "footer" : "",232 }233 let createdHistory = await requestHistoriesController.module11(req, res, historyObject);234 helperService.log(createdHistory);235 if (updatedFile) {236 const result = {237 data: updatedFile,238 }239 return response.ok(res, result);240 } else {241 throw new Error('Patch failed!');242 }243 }244 }245 }246 catch (err) {247 response.fail_serverError(res, err);248 }249 },250 markRequestFile: async (req: express.Request, res: express.Response) => {251 RequestFilesController.patchRequestFile(req, res, 'mark');252 },253 unmarkRequestFile: async (req: express.Request, res: express.Response) => {254 RequestFilesController.patchRequestFile(req, res, 'unmark');255 },256 deleteRequestFile: async (req: express.Request, res: express.Response) => {257 try {258 const tcode = 'gkcln18';259 if (!mongoose.Types.ObjectId.isValid(req.params._id)) {260 const result = {261 message: `${req.params._id} is invalid Id!`,262 }263 return response.fail_badRequest(res, result);264 } else {265 let RequestFiles = await RequestFilesController.getModel(req, res);266 let requestFiles = await RequestFiles.findById(req.params._id);267 if (!requestFiles) {268 return response.fail_notFound(res);269 } else {270 if (requestFiles.status == 'Marked') {271 let removedFile = await requestFiles.remove();272 if (removedFile) {273 // console.log(removedClient);274 // const trackParams = {275 // multi: false,276 // tcode: tcode,277 // oldData: removedClient.toObject(),278 // newData: {_id:''}279 // }280 // let trackHistory = GkClientsController.trackHistory(req, res, trackParams);281 // TODO: Save the first history282 const historyObject = {283 "type" : "comment",284 "docId" : removedFile.docId,285 "header" : "<a href='#'>" + req['mySession'].username + "</a> remove a file!",286 "body" : "File info: " + JSON.stringify(removedFile),287 "footer" : "",288 }289 let createdHistory = await requestHistoriesController.module11(req, res, historyObject);290 helperService.log(createdHistory);291 292 const result = {293 data: removedFile,294 }295 return response.ok(res, result);296 } else {297 throw new Error('Remove failed!');298 }299 } else {300 const result = {301 message: 'Only marked document could be deleted!',302 data: {},303 }304 return response.fail_preCondition(res, result);305 }306 }307 }308 }309 catch (err) {310 response.fail_serverError(res, err);311 }312 }313}...
formReducer.js
Source:formReducer.js
1import { ADD_FILE, ADD_IMAGE, ADD_LOCATION, ADD_RECORD, ADD_TITLE, ADD_VIDEO, DATE, INIT, PICK_FILE, QRCODE, } from "../constants/actionsTypes";2 3 const formState = {4 designation: null,5 date: null,6 equipmentCode: null,7 geolocation: null,8 requestFiles: {9 photo: [],10 video: [],11 record: [],12 pickPhoto: [],13 pickFile: [],14 },15 };16 const formReducer = (state = formState, action) => {17 const { type, payload } = action;18 19 switch (type) {20 case ADD_FILE:21 if (state.requestFiles.pickPhoto?.indexOf(payload) == -1) {22 return {23 ...state,24 requestFiles: {25 ...state.requestFiles,26 pickPhoto: [...state.requestFiles.pickPhoto, payload],27 },28 };29 } else return state;30 case PICK_FILE:31 if (state.requestFiles.pickFile?.indexOf(payload) == -1) {32 return {33 ...state,34 requestFiles: {35 ...state.requestFiles,36 pickFile: [...state.requestFiles.pickFile, payload],37 },38 };39 } else return state;40 case ADD_IMAGE:41 if (state.requestFiles.photo?.indexOf(payload) == -1) {42 return {43 ...state,44 requestFiles: {45 ...state.requestFiles,46 photo: [...state.requestFiles.photo, payload],47 },48 };49 } else return state;50 case ADD_VIDEO:51 if (state.requestFiles.video?.indexOf(payload) == -1) {52 return {53 ...state,54 requestFiles: {55 ...state.requestFiles,56 video: [...state.requestFiles.video, payload],57 },58 };59 } else return state;60 case ADD_RECORD:61 if (state.requestFiles.record?.indexOf(payload) == -1) {62 return {63 ...state,64 requestFiles: {65 ...state.requestFiles,66 record: [...state.requestFiles.record, payload],67 },68 };69 } else return state;70 case ADD_LOCATION:71 return {72 ...state,73 geolocation: payload,74 };75 76 case ADD_TITLE:77 return {78 ...state,79 designation: payload,80 };81 case DATE:82 return {83 ...state,84 date: payload,85 };86 case QRCODE:87 return {88 ...state,89 equipmentCode: payload,90 };91 case INIT:92 return {93 ...state,94 ...payload,95 };96 default:97 return state;98 }99 };100 export default formReducer;...
Using AI Code Generation
1const request = require('request');2const options = {3 json: {4 {5 { equals: { method: 'GET', path: '/test' } }6 {7 is: {8 headers: { 'Content-Type': 'application/json' },9 }10 }11 }12 }13};14request(options, (error, response, body) => {15 console.log('response', response);16 console.log('body', body);17 console.log('error', error);18});19const request = require('request');20const options = {21 json: {22 {23 { equals: { method: 'GET', path: '/test' } }24 {25 is: {26 headers: { 'Content-Type': 'application/json' },27 }28 }29 }30 }31};32request(options, (error, response, body) => {33 console.log('response', response);34 console.log('body', body);35 console.log('error', error);36});37const request = require('request');38const options = {39 json: {40 {41 { equals: { method: 'GET', path: '/test' } }42 {43 is: {44 headers: { 'Content-Type': 'application/json' },
Using AI Code Generation
1const request = require('request');2const options = {3 json: {4 {5 {6 "is": {7 "headers": {8 },9 "body": {10 }11 }12 }13 }14 }15};16request(options, function (error, response, body) {17 if (!error && response.statusCode == 200) {18 console.log(body)19 }20})
Using AI Code Generation
1var request = require('request');2var fs = require('fs');3var options = {4 json: {5 "stubs": [{6 "responses": [{7 "is": {8 "headers": {9 },10 "body": fs.readFileSync("response.json")11 }12 }]13 }]14 }15};16request(options, function(error, response, body) {17 if (!error && response.statusCode == 201) {18 console.log(body);19 }20});21{22}23{24}
Using AI Code Generation
1const request = require('request');2const fs = require('fs');3const options = {4 body: {5 stubs: [{6 responses: [{7 is: {8 headers: {9 },10 body: fs.readFileSync('test.json', 'utf8')11 }12 }]13 }]14 }15}16request(options, (error, response, body) => {17 console.log(body);18});19{20}21const request = require('request');22const fs = require('fs');23const options = {24 body: {25 stubs: [{26 responses: [{27 is: {28 headers: {29 },30 body: fs.readFileSync('test.json', 'utf8')31 }32 }]33 }]34 }35}36request(options, (error, response, body) => {37 console.log(body);38});39{40}41const request = require('request');42const fs = require('fs');43const options = {44 body: {45 stubs: [{46 responses: [{47 is: {48 headers: {49 },50 body: fs.readFileSync('test.json', 'utf8')51 }52 }]53 }]54 }55}56request(options, (error, response, body) => {57 console.log(body);58});59{60}
Using AI Code Generation
1var request = require('request');2var fs = require('fs');3var options = {4 json: {5 {6 {7 is: {8 }9 }10 }11 }12};13request(options, function (error, response, body) {14 if (!error && response.statusCode == 201) {15 console.log("Imposter created successfully");16 var imposterId = body.imposter.port;17 console.log("Imposter id is " + imposterId);18 var options = {19 json: {}20 };21 request(options, function (error, response, body) {22 if (!error && response.statusCode == 200) {23 console.log("requestFiles are fetched successfully");24 console.log(body);25 fs.writeFile("requestFiles.json", JSON.stringify(body), function (err) {26 if (err) {27 console.log(err);28 }29 });30 }31 });32 }33});
Using AI Code Generation
1var request = require('request');2var fs = require('fs');3var path = require('path');4var file = fs.readFileSync(path.join(__dirname, 'files', 'test.txt'));5var options = {6 json: {7 {8 {9 is: {10 headers: {11 },12 body: file.toString()13 }14 }15 }16 }17};18request(options, function (error, response, body) {19 if (error) {20 console.log(error);21 } else {22 console.log(body);23 }24});
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!!