How to use bodyParser method in pact-foundation-pact

Best JavaScript code snippet using pact-foundation-pact

body-parser.test.ts

Source:body-parser.test.ts Github

copy

Full Screen

...45 bodyParser = createBodyParser('raw');46 expect(typeof bodyParser).toBe('function');47 expect(bodyParser.name).toBe('bodyParser');48 });49 describe('bodyParser()', () => {50 describe('when passed a stream with NO data', () => {51 const context = createMockContext();52 test('does not add a `body` property to the request object', async () => {53 const promise = bodyParser(context);54 context[requestSymbol].end();55 await expect(promise).resolves.toBeUndefined();56 expect(context.request).not.toHaveProperty('body');57 });58 });59 describe('when passed a stream with data', () => {60 const context = createMockContext();61 const expectedBody = Buffer.concat(textChunks);62 context.request.headers[HTTP_HEADER_CONTENT_TYPE] = 'application/octet-stream';63 context.request.headers[HTTP_HEADER_CONTENT_LENGTH] = expectedBody.length.toString();64 test('adds a `body` property set to the expected value to the request object', async () => {65 const promise = bodyParser(context);66 textChunks.forEach(chunk => context[requestSymbol].write(chunk));67 context[requestSymbol].end();68 await expect(promise).resolves.toBeUndefined();69 expect(context.request).toHaveProperty('body', expectedBody);70 });71 });72 describe('when passed a stream without a `content-length` header', () => {73 const context = createMockContext();74 context.request.headers[HTTP_HEADER_CONTENT_TYPE] = 'application/octet-stream';75 test('resolves with an HTTP error response object', async () => {76 const promise = bodyParser(context);77 context[requestSymbol].end();78 await expect(promise).resolves.toEqual({ error: 'LENGTH_REQUIRED' });79 expect(context.request).not.toHaveProperty('body');80 });81 });82 describe('when passed a stream without a valid `content-length` header', () => {83 const context = createMockContext();84 context.request.headers[HTTP_HEADER_CONTENT_TYPE] = 'application/octet-stream';85 context.request.headers[HTTP_HEADER_CONTENT_LENGTH] = 'this is not a number';86 test('resolves with an HTTP error response object', async () => {87 const promise = bodyParser(context);88 context[requestSymbol].end();89 await expect(promise).resolves.toEqual({ error: 'BAD_REQUEST' });90 expect(context.request).not.toHaveProperty('body');91 });92 });93 describe('when passed a stream with data of size greater than `content-length`', () => {94 const context = createMockContext();95 context.request.headers[HTTP_HEADER_CONTENT_TYPE] = 'application/octet-stream';96 context.request.headers[HTTP_HEADER_CONTENT_LENGTH] = '1';97 test('resolves with an HTTP error response object', async () => {98 const promise = bodyParser(context);99 textChunks.forEach(chunk => context[requestSymbol].write(chunk));100 context[requestSymbol].end();101 await expect(promise).resolves.toEqual({ error: 'PAYLOAD_TOO_LARGE' });102 expect(context.request).not.toHaveProperty('body');103 });104 });105 describe('when passed a stream with data of size less than `content-length`', () => {106 const context = createMockContext();107 context.request.headers[HTTP_HEADER_CONTENT_TYPE] = 'application/octet-stream';108 context.request.headers[HTTP_HEADER_CONTENT_LENGTH] = '10';109 test('resolves with an HTTP error response object', async () => {110 const promise = bodyParser(context);111 textChunks.forEach(chunk => context[requestSymbol].write(chunk));112 context[requestSymbol].end();113 await expect(promise).resolves.toEqual({ error: 'BAD_REQUEST' });114 expect(context.request).not.toHaveProperty('body');115 });116 });117 });118});119/**120 * createBodyParser('raw') with second argument set to 0121 */122describe('createBodyParser(`raw`) with second argument set to 0', () => {123 let bodyParser: (t: MockTuftContext) => Promise<void>;124 test('returns a function named `bodyParser`', () => {125 //@ts-expect-error126 bodyParser = createBodyParser('raw', 0);127 expect(typeof bodyParser).toBe('function');128 expect(bodyParser.name).toBe('bodyParser');129 });130 describe('bodyParser()', () => {131 describe('when passed a stream with NO data', () => {132 const context = createMockContext();133 test('does not add a `body` property to the request object', async () => {134 const promise = bodyParser(context);135 context[requestSymbol].end();136 await expect(promise).resolves.toBeUndefined();137 expect(context.request).not.toHaveProperty('body');138 });139 });140 });141});142/**143 * createBodyParser('raw') with second argument set to 1144 */145describe('createBodyParser(`raw`) with second argument set to 1', () => {146 let bodyParser: (t: MockTuftContext) => Promise<void>;147 test('returns a function named `bodyParser`', () => {148 //@ts-expect-error149 bodyParser = createBodyParser('raw', 1);150 expect(typeof bodyParser).toBe('function');151 expect(bodyParser.name).toBe('bodyParser');152 });153 describe('bodyParser()', () => {154 describe('when passed a stream with NO data', () => {155 const context = createMockContext();156 test('does not add a `body` property to the request object', async () => {157 const promise = bodyParser(context);158 context[requestSymbol].end();159 await expect(promise).resolves.toBeUndefined();160 expect(context.request).not.toHaveProperty('body');161 });162 });163 describe('when passed a stream with data that exceeds the set body size limit', () => {164 const context = createMockContext();165 const expectedBody = Buffer.concat(textChunks);166 context.request.headers[HTTP_HEADER_CONTENT_TYPE] = 'application/octet-stream';167 context.request.headers[HTTP_HEADER_CONTENT_LENGTH] = expectedBody.length.toString();168 test('resolves with an HTTP error response object', async () => {169 const promise = bodyParser(context);170 textChunks.forEach(chunk => context[requestSymbol].write(chunk));171 context[requestSymbol].end();172 await expect(promise).resolves.toEqual({ error: 'PAYLOAD_TOO_LARGE' });173 expect(context.request).not.toHaveProperty('body');174 });175 });176 });177});178/**179 * createBodyParser('text')180 */181describe('createBodyParser(`text`)', () => {182 let bodyParser: (t: MockTuftContext) => Promise<void>;183 test('returns a function named `bodyParser`', () => {184 //@ts-expect-error185 bodyParser = createBodyParser('text');186 expect(typeof bodyParser).toBe('function');187 expect(bodyParser.name).toBe('bodyParser');188 });189 describe('bodyParser()', () => {190 describe('when passed a stream with NO data', () => {191 const context = createMockContext();192 test('does not add a `body` property to the request object', async () => {193 const promise = bodyParser(context);194 context[requestSymbol].end();195 await expect(promise).resolves.toBeUndefined();196 expect(context.request).not.toHaveProperty('body');197 });198 });199 describe('when passed a stream with data', () => {200 const context = createMockContext();201 const expectedBody = Buffer.concat(textChunks);202 context.request.headers[HTTP_HEADER_CONTENT_TYPE] = 'text/plain';203 context.request.headers[HTTP_HEADER_CONTENT_LENGTH] = expectedBody.length.toString();204 test('adds a `body` property set to the expected value to the request object', async () => {205 const promise = bodyParser(context);206 textChunks.forEach(chunk => context[requestSymbol].write(chunk));207 context[requestSymbol].end();208 await expect(promise).resolves.toBeUndefined();209 expect(context.request).toHaveProperty('body', expectedBody.toString());210 });211 });212 });213});214/**215 * createBodyParser('text') with second argument set to 0216 */217describe('createBodyParser(`text`) with second argument set to 0', () => {218 let bodyParser: (t: MockTuftContext) => Promise<void>;219 test('returns a function named `bodyParser`', () => {220 //@ts-expect-error221 bodyParser = createBodyParser('text', 0);222 expect(typeof bodyParser).toBe('function');223 expect(bodyParser.name).toBe('bodyParser');224 });225 describe('bodyParser()', () => {226 describe('when passed a stream with NO data', () => {227 const context = createMockContext();228 test('does not add a `body` property to the request object', async () => {229 const promise = bodyParser(context);230 context[requestSymbol].end();231 await expect(promise).resolves.toBeUndefined();232 expect(context.request).not.toHaveProperty('body');233 });234 });235 });236});237/**238 * createBodyParser('text') with second argument set to 1239 */240describe('createBodyParser(`text`) with second argument set to 1', () => {241 let bodyParser: (t: MockTuftContext) => Promise<void>;242 test('returns a function named `bodyParser`', () => {243 //@ts-expect-error244 bodyParser = createBodyParser('text', 1);245 expect(typeof bodyParser).toBe('function');246 expect(bodyParser.name).toBe('bodyParser');247 });248 describe('bodyParser()', () => {249 describe('when passed a stream with NO data', () => {250 const context = createMockContext();251 test('does not add a `body` property to the request object', async () => {252 const promise = bodyParser(context);253 context[requestSymbol].end();254 await expect(promise).resolves.toBeUndefined();255 expect(context.request).not.toHaveProperty('body');256 });257 });258 describe('when passed a stream with data that exceeds the set body size limit', () => {259 const context = createMockContext();260 const expectedBody = Buffer.concat(textChunks);261 context.request.headers[HTTP_HEADER_CONTENT_TYPE] = 'text/plain';262 context.request.headers[HTTP_HEADER_CONTENT_LENGTH] = expectedBody.length.toString();263 test('resolves with an HTTP error response object', async () => {264 const promise = bodyParser(context);265 textChunks.forEach(chunk => context[requestSymbol].write(chunk));266 context[requestSymbol].end();267 await expect(promise).resolves.toEqual({ error: 'PAYLOAD_TOO_LARGE' });268 expect(context.request).not.toHaveProperty('body');269 });270 });271 });272});273/**274 * createBodyParser('json')275 */276describe('createBodyParser(`json`)', () => {277 let bodyParser: (t: MockTuftContext) => Promise<void>;278 test('returns a function named `bodyParser`', () => {279 //@ts-expect-error280 bodyParser = createBodyParser('json');281 expect(typeof bodyParser).toBe('function');282 expect(bodyParser.name).toBe('bodyParser');283 });284 describe('bodyParser()', () => {285 describe('when passed a stream with NO data', () => {286 const context = createMockContext();287 test('does not add a `body` property to the request object', async () => {288 const promise = bodyParser(context);289 context[requestSymbol].end();290 await expect(promise).resolves.toBeUndefined();291 expect(context.request).not.toHaveProperty('body');292 });293 });294 describe('when passed a stream with data', () => {295 const context = createMockContext();296 const expectedBody = Buffer.concat(jsonChunks);297 context.request.headers[HTTP_HEADER_CONTENT_TYPE] = 'application/json';298 context.request.headers[HTTP_HEADER_CONTENT_LENGTH] = expectedBody.length.toString();299 test('adds a `body` property set to the expected value to the request object', async () => {300 const promise = bodyParser(context);301 jsonChunks.forEach(chunk => context[requestSymbol].write(chunk));302 context[requestSymbol].end();303 await expect(promise).resolves.toBeUndefined();304 expect(context.request).toHaveProperty('body', { abc: 123 });305 });306 });307 });308});309/**310 * createBodyParser('json') with second argument set to 0311 */312describe('createBodyParser(`json`) with second argument set to 0', () => {313 let bodyParser: (t: MockTuftContext) => Promise<void>;314 test('returns a function named `bodyParser`', () => {315 //@ts-expect-error316 bodyParser = createBodyParser('json', 0);317 expect(typeof bodyParser).toBe('function');318 expect(bodyParser.name).toBe('bodyParser');319 });320 describe('bodyParser()', () => {321 describe('when passed a stream with NO data', () => {322 const context = createMockContext();323 test('does not add a `body` property to the request object', async () => {324 const promise = bodyParser(context);325 context[requestSymbol].end();326 await expect(promise).resolves.toBeUndefined();327 expect(context.request).not.toHaveProperty('body');328 });329 });330 });331});332/**333 * createBodyParser('json') with second argument set to 1334 */335describe('createBodyParser(`json`) with second argument set to 1', () => {336 let bodyParser: (t: MockTuftContext) => Promise<void>;337 test('returns a function named `bodyParser`', () => {338 //@ts-expect-error339 bodyParser = createBodyParser('json', 1);340 expect(typeof bodyParser).toBe('function');341 expect(bodyParser.name).toBe('bodyParser');342 });343 describe('bodyParser()', () => {344 describe('when passed a stream with NO data', () => {345 const context = createMockContext();346 test('does not add a `body` property to the request object', async () => {347 const promise = bodyParser(context);348 context[requestSymbol].end();349 await expect(promise).resolves.toBeUndefined();350 expect(context.request).not.toHaveProperty('body');351 });352 });353 describe('when passed a stream with data that exceeds the set body size limit', () => {354 const context = createMockContext();355 const expectedBody = Buffer.concat(jsonChunks);356 context.request.headers[HTTP_HEADER_CONTENT_TYPE] = 'application/json';357 context.request.headers[HTTP_HEADER_CONTENT_LENGTH] = expectedBody.length.toString();358 test('rejects with an error', async () => {359 const promise = bodyParser(context);360 jsonChunks.forEach(chunk => context[requestSymbol].write(chunk));361 context[requestSymbol].end();362 await expect(promise).resolves.toEqual({ error: 'PAYLOAD_TOO_LARGE' });363 expect(context.request).not.toHaveProperty('body');364 });365 });366 });367});368/**369 * createBodyParser('urlEncoded')370 */371describe('createBodyParser(`urlEncoded`)', () => {372 let bodyParser: (t: MockTuftContext) => Promise<void>;373 test('returns a function named `bodyParser`', () => {374 //@ts-expect-error375 bodyParser = createBodyParser('urlEncoded');376 expect(typeof bodyParser).toBe('function');377 expect(bodyParser.name).toBe('bodyParser');378 });379 describe('bodyParser()', () => {380 describe('when passed a stream with NO data', () => {381 const context = createMockContext();382 test('does not add a `body` property to the request object', async () => {383 const promise = bodyParser(context);384 context[requestSymbol].end();385 await expect(promise).resolves.toBeUndefined();386 expect(context.request).not.toHaveProperty('body');387 });388 });389 describe('when passed a stream with data', () => {390 const context = createMockContext();391 const chunks = urlEncodedChunks.slice(0, 2);392 const expectedBody = Buffer.concat(chunks);393 context.request.headers[HTTP_HEADER_CONTENT_TYPE] = 'application/x-www-form-urlencoded';394 context.request.headers[HTTP_HEADER_CONTENT_LENGTH] = expectedBody.length.toString();395 test('adds a `body` property set to the expected value to the request object', async () => {396 const promise = bodyParser(context);397 chunks.forEach(chunk => context[requestSymbol].write(chunk));398 context[requestSymbol].end();399 await expect(promise).resolves.toBeUndefined();400 expect(context.request).toHaveProperty('body', { abc: '123' });401 });402 });403 });404 describe('when passed a stream with data that includes two key/value pairs', () => {405 const context = createMockContext();406 const expectedBody = Buffer.concat(urlEncodedChunks);407 context.request.headers[HTTP_HEADER_CONTENT_TYPE] = 'application/x-www-form-urlencoded';408 context.request.headers[HTTP_HEADER_CONTENT_LENGTH] = expectedBody.length.toString();409 test('adds a `body` property set to the expected value to the request object', async () => {410 const promise = bodyParser(context);411 urlEncodedChunks.forEach(chunk => context[requestSymbol].write(chunk));412 context[requestSymbol].end();413 await expect(promise).resolves.toBeUndefined();414 expect(context.request).toHaveProperty('body', { abc: '123', def: '456' });415 });416 });417});418/**419 * createBodyParser('urlEncoded') with second argument set to 0420 */421describe('createBodyParser(`urlEncoded`) with second argument set to 0', () => {422 let bodyParser: (t: MockTuftContext) => Promise<void>;423 test('returns a function named `bodyParser`', () => {424 //@ts-expect-error425 bodyParser = createBodyParser('urlEncoded', 0);426 expect(typeof bodyParser).toBe('function');427 expect(bodyParser.name).toBe('bodyParser');428 });429 describe('bodyParser()', () => {430 describe('when passed a stream with NO data', () => {431 const context = createMockContext();432 test('does not add a `body` property to the request object', async () => {433 const promise = bodyParser(context);434 context[requestSymbol].end();435 await expect(promise).resolves.toBeUndefined();436 expect(context.request).not.toHaveProperty('body');437 });438 });439 });440});441/**442 * createBodyParser('urlEncoded') with second argument set to 1443 */444describe('createBodyParser(`urlEncoded`) with second argument set to 1', () => {445 let bodyParser: (t: MockTuftContext) => Promise<void>;446 test('returns a function named `bodyParser`', () => {447 //@ts-expect-error448 bodyParser = createBodyParser('urlEncoded', 1);449 expect(typeof bodyParser).toBe('function');450 expect(bodyParser.name).toBe('bodyParser');451 });452 describe('bodyParser()', () => {453 describe('when passed a stream with NO data', () => {454 const context = createMockContext();455 test('does not add a `body` property to the request object', async () => {456 const promise = bodyParser(context);457 context[requestSymbol].end();458 await expect(promise).resolves.toBeUndefined();459 expect(context.request).not.toHaveProperty('body');460 });461 });462 describe('when passed a stream with data that exceeds the set body size limit', () => {463 const context = createMockContext();464 const chunks = urlEncodedChunks.slice(0, 2);465 context.request.headers[HTTP_HEADER_CONTENT_TYPE] = 'application/x-www-form-urlencoded';466 context.request.headers[HTTP_HEADER_CONTENT_LENGTH] = chunks.length.toString();467 test('rejects with an error', async () => {468 const promise = bodyParser(context);469 chunks.forEach(chunk => context[requestSymbol].write(chunk));470 context[requestSymbol].end();471 await expect(promise).resolves.toEqual({ error: 'PAYLOAD_TOO_LARGE' });472 expect(context.request).not.toHaveProperty('body');473 });474 });475 });...

Full Screen

Full Screen

router.js

Source:router.js Github

copy

Full Screen

1const Public = require('./controllers/public');2const Account = require('./controllers/account');3const User = require('./controllers/user');4const Advertiser = require('./controllers/advertiser');5const Campaign = require('./controllers/campaign');6const Publisher = require('./controllers/publisher');7const Integration = require('./controllers/integration');8const Placement = require('./controllers/placement');9const Flight = require('./controllers/flight');10const Lists = require('./controllers/domain.list');11const passportService = require('./services/passport');12const passport = require('passport');13const bodyParser = require('body-parser').json();14const multiplart = require('connect-multiparty');15const multipartMiddleware = multiplart({ uploadDir: '/tmp/' });16let db = require("./models");17const requireSignin = passport.authenticate('local', { session: false });18const requireAuth = passport.authenticate('jwt', { session: false });19module.exports = function (app) {20 // Public Routes21 app.post('/public/login', bodyParser, requireSignin, Public.login);22 app.post('/public/register', bodyParser, Public.register);23 app.post('/public/recover', bodyParser, Public.recover);24 // Account Routes25 app.post('/account/master_list', requireAuth, bodyParser, Account.master_list);26 app.post('/account/list', requireAuth, bodyParser, Account.list);27 app.post('/account/list_pending', requireAuth, bodyParser, Account.listPending);28 app.post('/account/list_disabled', requireAuth, bodyParser, Account.listDisabled);29 app.post('/account/scope_list', requireAuth, bodyParser, Account.scopeList);30 app.post('/account/read', requireAuth, bodyParser, Account.read);31 app.post('/account/create', requireAuth, bodyParser, Account.create);32 app.post('/account/delete', requireAuth, bodyParser, Account.delete);33 app.post('/account/update', requireAuth, bodyParser, Account.update);34 app.post('/account/activate', requireAuth, bodyParser, Account.activate);35 app.post('/account/deactivate', requireAuth, bodyParser, Account.deactivate);36 // User Routes37 app.post('/user/scope', requireAuth, bodyParser, User.scope);38 app.get('/user/read', requireAuth, User.readActive);39 app.post('/user/read', requireAuth, bodyParser, User.read);40 app.post('/user/list', requireAuth, bodyParser, User.list);41 app.post('/user/create', requireAuth, bodyParser, User.create);42 app.post('/user/update', requireAuth, bodyParser, User.update);43 app.post('/user/delete', requireAuth, bodyParser, User.delete);44 app.post('/user/timezone', requireAuth, bodyParser, User.timezone);45 app.post('/user/list_disabled', requireAuth, bodyParser, User.listDisabled);46 app.post('/user/activate', requireAuth, bodyParser, User.activate);47 app.post('/user/deactivate', requireAuth, bodyParser, User.deactivate);48 // Advertiser Routes49 app.post('/advertiser/create', requireAuth, bodyParser, Advertiser.create);50 app.post('/advertiser/list', requireAuth, bodyParser, Advertiser.list);51 app.post('/advertiser/list_disabled', requireAuth, bodyParser, Advertiser.listDisabled);52 app.post('/advertiser/read', requireAuth, bodyParser, Advertiser.read);53 app.post('/advertiser/update', requireAuth, bodyParser, Advertiser.update);54 app.post('/advertiser/delete', requireAuth, bodyParser, Advertiser.delete);55 app.get('/advertiser/list', requireAuth, Advertiser.listAll);56 // Campaign Routes57 app.post('/campaign/create', requireAuth, bodyParser, Campaign.create);58 app.post('/campaign/delete', requireAuth, bodyParser, Campaign.delete);59 app.post('/campaign/tag', requireAuth, bodyParser, Campaign.tag);60 app.post('/campaign/list', requireAuth, bodyParser, Campaign.list);61 app.post('/campaign/list_active', requireAuth, bodyParser, Campaign.listActive);62 app.post('/campaign/list_inactive', requireAuth, bodyParser, Campaign.listInactive);63 app.post('/campaign/list_disabled', requireAuth, bodyParser, Campaign.listDisabled);64 app.post('/campaign/read', requireAuth, bodyParser, Campaign.read);65 //find campaign dates66 app.get('/api/dates/:id', requireAuth, Campaign.date);67 app.post('/campaign/update', requireAuth, bodyParser, Campaign.update);68 app.post('/campaign/activate', requireAuth, bodyParser, Campaign.activate);69 app.post('/campaign/deactivate', requireAuth, bodyParser, Campaign.deactivate);70 app.post('/campaign/list_advertiser_campaigns', requireAuth, bodyParser, Campaign.listAdvertiserCampaigns);71 app.get('/campaign/list_advertisers/:master', requireAuth, Campaign.listAdvertisers);72 // Publisher Routes73 app.post('/publisher/create', requireAuth, bodyParser, Publisher.create);74 app.post('/publisher/list', requireAuth, bodyParser, Publisher.list);75 app.post('/publisher/list_disabled', requireAuth, bodyParser, Publisher.listDisabled);76 app.post('/publisher/read', requireAuth, bodyParser, Publisher.read);77 app.post('/publisher/delete', requireAuth, bodyParser, Publisher.delete);78 app.post('/publisher/update', requireAuth, bodyParser, Publisher.update);79 app.get('/publisher/list/:master', requireAuth, Publisher.listAll);80 // integrations81 app.post('/integration/create', requireAuth, bodyParser, Integration.create);82 app.post('/integration/list', requireAuth, bodyParser, Integration.list);83 app.post('/integration/list_disabled', requireAuth, bodyParser, Integration.listDisabled);84 app.post('/integration/read', requireAuth, bodyParser, Integration.read);85 app.post('/integration/delete', requireAuth, bodyParser, Integration.delete);86 app.post('/integration/update', requireAuth, bodyParser, Integration.update);87 app.get('/integration/list/', requireAuth, Integration.listAll);88 // Placement Routes89 app.post('/placement/create', requireAuth, bodyParser, Placement.create);90 app.post('/placement/delete', requireAuth, bodyParser, Placement.delete);91 app.post('/placement/list', requireAuth, bodyParser, Placement.list);92 app.post('/placement/list_active', requireAuth, bodyParser, Placement.listActive);93 app.post('/placement/list_inactive', requireAuth, bodyParser, Placement.listInactive);94 app.post('/placement/list_disabled', requireAuth, bodyParser, Placement.listDisabled);95 app.post('/placement/read', requireAuth, bodyParser, Placement.read);96 app.post('/placement/read_opportunity_count', requireAuth, bodyParser, Placement.readOpportunityCount);97 98 app.post('/placement/update', requireAuth, bodyParser, Placement.update);99 app.post('/placement/activate', requireAuth, bodyParser, Placement.activate);100 app.post('/placement/deactivate', requireAuth, bodyParser, Placement.deactivate);101 app.post('/placement/tag', requireAuth, bodyParser, Placement.tag);102 app.post('/placement/video_tag', requireAuth, bodyParser, Placement.playerTag);103 app.post('/placement/list_demand', requireAuth, bodyParser, Placement.listDemand);104 app.post('/placement/demand_list', requireAuth, bodyParser, Placement.demandList);105 app.post('/placement/update_demand', requireAuth, bodyParser, Placement.updateDemand);106 // Flight Routes107 app.post('/flight/create', requireAuth, bodyParser, Flight.create);108 app.post('/flight/delete', requireAuth, bodyParser, Flight.delete);109 app.post('/flight/tag', requireAuth, bodyParser, Flight.tag);110 app.post('/flight/list', requireAuth, bodyParser, Flight.list);111 app.post('/flight/list_active', requireAuth, bodyParser, Flight.listActive);112 app.post('/flight/list_inactive', requireAuth, bodyParser, Flight.listInactive);113 app.post('/flight/list_paused', requireAuth, bodyParser, Flight.listPaused);114 app.post('/flight/list_disabled', requireAuth, bodyParser, Flight.listDisabled);115 app.post('/flight/read', requireAuth, bodyParser, Flight.read);116 app.post('/flight/update', requireAuth, bodyParser, Flight.update);117 app.post('/flight/clone', requireAuth, bodyParser, Flight.clone);118 app.post('/flight/display_upload', requireAuth, multipartMiddleware, Flight.displayUpload);119 app.post('/flight/video_upload', requireAuth, multipartMiddleware, Flight.videoUpload);120 app.post('/flight/activate', requireAuth, bodyParser, Flight.activate);121 app.post('/flight/deactivate', requireAuth, bodyParser, Flight.deactivate);122 app.post('/flight/pause', requireAuth, bodyParser, Flight.pause);123 app.post('/flight/disable', requireAuth, bodyParser, Flight.disable);124 app.post('/flight/list_campaigns', requireAuth, bodyParser, Flight.listCampaigns);125 app.post('/flight/list_options', requireAuth, bodyParser, Flight.listOptions);126 app.post('/flight/update_supply', requireAuth, bodyParser, Flight.updateSupply);127 app.post('/flight/list_supply', requireAuth, bodyParser, Flight.listSupply);128 app.post('/flight/supply_list', requireAuth, bodyParser, Flight.supplyList);129 // Lists Routes130 app.post('/lists/list', requireAuth, bodyParser, Lists.list);131 app.post('/lists/type', requireAuth, bodyParser, Lists.type);132 app.post('/lists/upload', requireAuth, multipartMiddleware, Lists.upload);133 app.post('/lists/uploadbundle', requireAuth, multipartMiddleware, Lists.uploadBundle);134 app.post('/lists/uploadapp', requireAuth, multipartMiddleware, Lists.uploadApp);135 136 app.post('/lists/uploadip', requireAuth, multipartMiddleware, Lists.uploadIp);137 app.post('/lists/create', requireAuth, bodyParser, Lists.create);138 app.post('/lists/read', requireAuth, bodyParser, Lists.read);139 app.post('/lists/update', requireAuth, bodyParser, Lists.update);140 app.post('/lists/delete', requireAuth, bodyParser, Lists.delete);141 app.post('/lists/clone', requireAuth, bodyParser, Lists.clone);142 app.get('/lists/list/:id', requireAuth, Lists.listAll);...

Full Screen

Full Screen

server.js

Source:server.js Github

copy

Full Screen

1var express = require("express");2var db = require('./DBlibrary');3var session = require('express-session');4var bodyParser = require("body-parser");5var router = require("./router");6var flash = require('connect-flash');7var md5 = require('crypto-md5');8var multer = require('multer');9var cookieParser = require('cookie-parser');10var passport = require('passport');11var LocalStrategy = require('passport-local').Strategy;12var configure = require('./configure');13var app = express();14db.connect(function(afterConnect) {15 db.createDBIfNotExists();16});17var storage = multer.diskStorage({18 destination: function(req, file, callback) {19 callback(null, './uploads');20 },21 filename: function(req, file, callback) {22 console.log(file);23 callback(null, file.fieldname + '-' + Date.now() + file.originalname);24 }25});26var upload = multer({ storage: storage }).array('userPhoto', 2);27app.get('/', function(req, res) {28 res.sendFile(__dirname + "/index.html");29});30app.post('/api/photo', function(req, res) {31 upload(req, res, function(err) {32 if (err) {33 return res.end("Error uploading file.");34 }35 res.end("File is uploaded");36 });37});38app.use(bodyParser.json());39//app.use(bodyParser.urlencoded({ extended: false }));40app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));41app.use(cookieParser());42app.use(flash());43app.use(session({44 secret: 'secret cat',45 resave: true,46 saveUninitialized: true47}));48app.use(passport.initialize());49app.use(passport.session());50passport.use(new LocalStrategy({51 /* Define custom fields for passport */52 usernameField: 'email',53 passwordField: 'password'54 },55 function(email2, password2, done) {56 /* validate email and password */57 db.login({ email: email2, password: password2 }, done);58 }59));60passport.serializeUser(function(user, done) {61 /* Attach to the session as req.session.passport.user = { email: 'test@test.com' } */62 /* The email key will be later used in our passport.deserializeUser function */63 done(null, user.email);64});65passport.deserializeUser(function(email, done) {66 db.findOne({ email: email }, done);67});68app.use(function(req, res, next) {69 req.db = db;70 res.locals.user = req.user;71 next();72});73// app.use(fileUpload());74app.set("view engine", "ejs");75app.use(express.static("public"));76bodyParser = bodyParser.urlencoded({ extended: false })77app.get("/login.html", router.controler.loginView);78app.get("/register.html", router.controler.registerView);79app.post('/login.html',80 passport.authenticate('local', {81 successRedirect: '/home.html',82 failureRedirect: '/login.html',83 failureFlash: true84 }));85passport.authenticate('local', { failureFlash: 'Invalid username or password.' });86app.get('/logout.html', function(req, res) {87 req.logout();88 res.redirect('/home.html');89});90app.post("/register.html", bodyParser, router.controler.register);91app.post("/product.html", bodyParser, router.controler.product);92app.post("/cart.html/add", bodyParser, router.controler.addToCart);93app.post("/cart.html/update", bodyParser, router.controler.EditCart);94app.post("/cart.html/delete", bodyParser, router.controler.deleteFromCart);95app.post("/edit.html", bodyParser, router.controler.editPost);96app.post("/manageusers.html/checkUpdate", bodyParser, router.controler.checkUpdate)97app.post("/account.html", bodyParser, router.controler.accountPost);98app.post("/edit_product.html", bodyParser, router.controler.addProductEdit);99app.post("/edit_product.html/update", bodyParser, router.controler.editProductUpdate);100app.post("/addproduct.html/delete", bodyParser, router.controler.addProductDelete);101app.post("/checkOut.html", bodyParser, router.controler.checkOutOrder)102app.post("/manageorders.html", bodyParser, router.controler.approve)103app.post("/register.html/image", bodyParser, router.controler.registerImg)104app.get("/home.html", router.controler.home);105app.get("/shop.html", router.controler.shop);106app.get("/edit.html", router.controler.edit);107app.get("/addproduct.html", router.controler.add_product);108app.get("/account.html", router.controler.account);109app.get("/cart.html", router.controler.cart);110app.get("/checkout.html", router.controler.checkout);111app.get("/orders.html", router.controler.orders);112app.get("/manageorders.html", router.controler.manage_orders);113app.get("/manageusers.html", router.controler.manage_users);...

Full Screen

Full Screen

bodyparser-options.ts

Source:bodyparser-options.ts Github

copy

Full Screen

1'use strict'2import Set from '@supercharge/set'3import { BodyparserJsonOptions } from './bodyparser-json-options'4import { BodyparserBaseOptions } from './bodyparser-base-options'5import { BodyparserMultipartOptions } from './bodyparser-multipart-options'6import { BodyparserOptions as BodyparserOptionsContract } from '@supercharge/contracts'7export class BodyparserOptions {8 /**9 * The bodyparser object object.10 */11 protected readonly options: BodyparserOptionsContract12 /**13 * Create a new instance.14 *15 * @param {BodyparserOptionsContract} options16 */17 constructor (options: BodyparserOptionsContract) {18 this.options = options ?? {}19 }20 /**21 * Returns the configured encoding.22 *23 * @returns {BodyparserJsonOptions}24 */25 encoding (): BufferEncoding {26 return this.options.encoding ?? 'utf8'27 }28 /**29 * Returns an array of allowed methods, transformed to lowercase.30 *31 * @example32 * ```js33 * new BodyparserOptions({ methods: ['post', 'PUT'] }).methods()34 * // ['post', 'put']35 * ```36 *37 * @returns {BodyparserJsonOptions}38 */39 methods (): string[] {40 return Set41 .from(this.options.methods)42 .map(method => method.toLowerCase())43 .toArray()44 }45 /**46 * Returns a JSON options instance.47 *48 * @returns {BodyparserJsonOptions}49 */50 json (): BodyparserJsonOptions {51 return new BodyparserJsonOptions(this.options.json)52 }53 /**54 * Returns a form (form url encoded) options instance.55 *56 * @returns {BodyparserBaseOptions}57 */58 form (): BodyparserBaseOptions {59 return new BodyparserBaseOptions(this.options.form)60 }61 /**62 * Returns a text options instance.63 *64 * @returns {BodyparserBaseOptions}65 */66 text (): BodyparserBaseOptions {67 return new BodyparserBaseOptions(this.options.text)68 }69 /**70 * Returns a multipart options instance.71 *72 * @returns {BodyparserMultipartOptions}73 */74 multipart (): BodyparserMultipartOptions {75 return new BodyparserMultipartOptions(this.options.multipart ?? {})76 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const bodyParser = require('body-parser');2const {Pact} = require('@pact-foundation/pact');3const {PactWeb} = require('@pact-foundation/pact-web');4const {PactWeb} = require('@pact-foundation/pact-web');5const {Pact} = require('@pact-foundation/pact');6const {PactWeb} = require('@pact-foundation/pact-web');7const {Pact} = require('@pact-foundation/pact');8const {PactWeb} = require('@pact-foundation/pact-web');9const {Pact} = require('@pact-foundation/pact');10const {PactWeb} = require('@pact-foundation/pact-web');11const {Pact} = require('@pact-foundation/pact');12const {PactWeb} = require('@pact-foundation/pact-web');13const {Pact} = require('@pact-foundation/pact');14const {PactWeb} = require('@pact-foundation/pact-web');15const {Pact} = require('@pact-foundation/pact');16const {PactWeb} = require('@pact-foundation/pact-web');17const {Pact} = require('@pact-foundation/pact');

Full Screen

Using AI Code Generation

copy

Full Screen

1const bodyParser = require('body-parser');2const pact = require('pact-foundation-pact-js');3const app = require('express');4const path = require('path');5const pact = require('pact-foundation-pact-js');6const opts = {7 log: path.resolve(process.cwd(), 'logs', 'pact.log'),8 dir: path.resolve(process.cwd(), 'pacts'),9};10const provider = pact(opts);11provider.setup().then(() => {12 app.use(bodyParser.json());13 app.post('/test', (req, res) => {14 res.json({success: true});15 });16 app.listen(1234, () => {17 provider.finalize();18 });19});

Full Screen

Using AI Code Generation

copy

Full Screen

1var pact = require('pact-foundation/pact-node');2var fs = require('fs');3var path = require('path');4var pactfile = fs.readFileSync('./pacts/Consumer-Supplier.json');5var pactfile1 = JSON.parse(pactfile);6var interactions = pactfile1.interactions;7var interactions1 = JSON.stringify(interactions);8console.log(interactions1);9var pactfile2 = JSON.parse(interactions1);10console.log(pactfile2);11var pactfile3 = pactfile2[0];12console.log(pactfile3);13var pactfile4 = pactfile3.request;14console.log(pactfile4);15var pactfile5 = pactfile4.path;16console.log(pactfile5);17var pactfile6 = pactfile4.method;18console.log(pactfile6);19var pactfile7 = pactfile4.query;20console.log(pactfile7);21var pactfile8 = pactfile4.headers;22console.log(pactfile8);23var pactfile9 = pactfile4.body;24console.log(pactfile9);25var pactfile10 = pactfile3.response;26console.log(pactfile10);27var pactfile11 = pactfile10.status;28console.log(pactfile11);29var pactfile12 = pactfile10.headers;30console.log(pactfile12);31var pactfile13 = pactfile10.body;32console.log(pactfile13);33var pactfile14 = pactfile13.contents;34console.log(pactfile14);35var pactfile16 = pactfile13.json_class;36console.log(pactfile16);37var pactfile17 = pactfile13.matcher;38console.log(pactfile17);39var pactfile18 = pactfile13.value;40console.log(pactfile18);41var pactfile19 = pactfile13.generators;42console.log(pactfile19);43var pactfile20 = pactfile19[0];44console.log(pactfile20);45var pactfile21 = pactfile20.type;46console.log(pactfile21);47var pactfile22 = pactfile20.regex;48console.log(pactfile22);49var pactfile23 = pactfile20.function;

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 pact-foundation-pact 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