Best JavaScript code snippet using wpt
MoreResults.js
Source:MoreResults.js
1var assert = require('chai').assert;2var request = require('request-promise');3var config = require('../it.config');4describe('Wishlist MoreResults', function () {5 this.timeout(60000);6 var cookieJar = request.jar();7 // Notice that for users used in this test, their wishlist are empty and private be default (as created by demo data).8 // Therefore any change in this regard have to be reverted/cleanup at the end of test.9 function setRequestUrlAndMethod(inRequest, endPoint, method) {10 var myRequest = inRequest;11 myRequest.url = config.baseUrl + '/' + endPoint;12 myRequest.method = method;13 }14 function setRequestToLogin(inRequest, csrfResponse, loginEmail, loginPassword) {15 var csrfJsonResponse = JSON.parse(csrfResponse.body);16 var csrfToken = csrfJsonResponse.csrf.token;17 var myRequest = inRequest;18 myRequest.url = config.baseUrl + '/Account-Login?' + csrfJsonResponse.csrf.tokenName + '=' + csrfToken;19 myRequest.method = 'POST';20 myRequest.form = {21 loginEmail: loginEmail,22 loginPassword: loginPassword,23 csrf_token: csrfToken24 };25 }26 function setCookieJar(inRequest, myCookieJar) {27 var myRequest = inRequest;28 var cookieString = cookieJar.getCookieString(myRequest.url);29 var cookie = request.cookie(cookieString);30 myCookieJar.setCookie(cookie, myRequest.url);31 }32 function setRequestToAddProduct(inRequest, productId) {33 var myRequest = inRequest;34 myRequest.url = config.baseUrl + '/Wishlist-AddProduct';35 myRequest.method = 'POST';36 myRequest.form = {37 pid: productId,38 optionId: null,39 optionVal: null40 };41 }42 function setRequestToTogglePublic(inRequest, getListResponse) {43 var bodyAsJson = JSON.parse(getListResponse.body);44 var myRequest = inRequest;45 myRequest.form = {46 listID: bodyAsJson.list.UUID,47 itemID: null48 };49 myRequest.url = config.baseUrl + '/ProductList-TogglePublic';50 myRequest.method = 'POST';51 }52 before(function () {53 // ----- login, set user's wishlist to public, logout54 var myRequest1 = {55 url: '',56 method: '',57 rejectUnauthorized: false,58 resolveWithFullResponse: true,59 jar: cookieJar,60 headers: {61 'X-Requested-With': 'XMLHttpRequest'62 }63 };64 // 'wluser1@demandware.com', 'Test123!', '701644329402M'65 setRequestUrlAndMethod(myRequest1, 'CSRF-Generate', 'POST');66 return request(myRequest1)67 .then(function (csrfResponse) {68 assert.equal(csrfResponse.statusCode, 200);69 setRequestToLogin(myRequest1, csrfResponse, 'wluser1@demandware.com', 'Test123!');70 return request(myRequest1);71 })72 .then(function (loginResponse) {73 assert.equal(loginResponse.statusCode, 200);74 setCookieJar(myRequest1, cookieJar);75 setRequestToAddProduct(myRequest1, '701644329402M');76 return request(myRequest1);77 })78 .then(function (addToWishListresponse) {79 assert.equal(addToWishListresponse.statusCode, 200);80 setRequestUrlAndMethod(myRequest1, 'Wishlist-GetListJson', 'get');81 return request(myRequest1);82 })83 .then(function (getListResponse) {84 assert.equal(getListResponse.statusCode, 200);85 setRequestToTogglePublic(myRequest1, getListResponse);86 return request(myRequest1);87 })88 .then(function (toggleResponse) {89 assert.equal(toggleResponse.statusCode, 200);90 setRequestUrlAndMethod(myRequest1, 'Login-Logout', 'get');91 return request(myRequest1);92 })93 .then(function (logOffResponse) {94 assert.equal(logOffResponse.statusCode, 200);95 })96 // ----- 'wluser2@demandware.com', 'Test123!', '701644391737M')97 .then(function () {98 setRequestUrlAndMethod(myRequest1, 'CSRF-Generate', 'POST');99 return request(myRequest1);100 })101 .then(function (csrfResponse) {102 setRequestToLogin(myRequest1, csrfResponse, 'wluser2@demandware.com', 'Test123!');103 return request(myRequest1);104 })105 .then(function (loginResponse) {106 assert.equal(loginResponse.statusCode, 200);107 setCookieJar(myRequest1, cookieJar);108 setRequestToAddProduct(myRequest1, '701644391737M');109 return request(myRequest1);110 })111 .then(function (addToWishListresponse) {112 assert.equal(addToWishListresponse.statusCode, 200);113 setRequestUrlAndMethod(myRequest1, 'Wishlist-GetListJson', 'get');114 return request(myRequest1);115 })116 .then(function (getListResponse) {117 assert.equal(getListResponse.statusCode, 200);118 setRequestToTogglePublic(myRequest1, getListResponse);119 return request(myRequest1);120 })121 .then(function (toggleResponse) {122 assert.equal(toggleResponse.statusCode, 200);123 setRequestUrlAndMethod(myRequest1, 'Login-Logout', 'get');124 return request(myRequest1);125 })126 .then(function (logOffResponse) {127 assert.equal(logOffResponse.statusCode, 200);128 })129 // ----- 'wluser3@demandware.com', 'Test123!', '701643238125M'130 .then(function () {131 setRequestUrlAndMethod(myRequest1, 'CSRF-Generate', 'POST');132 return request(myRequest1);133 })134 .then(function (csrfResponse) {135 setRequestToLogin(myRequest1, csrfResponse, 'wluser3@demandware.com', 'Test123!');136 return request(myRequest1);137 })138 .then(function (loginResponse) {139 assert.equal(loginResponse.statusCode, 200);140 setCookieJar(myRequest1, cookieJar);141 setRequestToAddProduct(myRequest1, '701643238125M');142 return request(myRequest1);143 })144 .then(function (addToWishListresponse) {145 assert.equal(addToWishListresponse.statusCode, 200);146 setRequestUrlAndMethod(myRequest1, 'Wishlist-GetListJson', 'get');147 return request(myRequest1);148 })149 .then(function (getListResponse) {150 assert.equal(getListResponse.statusCode, 200);151 setRequestToTogglePublic(myRequest1, getListResponse);152 return request(myRequest1);153 })154 .then(function (toggleResponse) {155 assert.equal(toggleResponse.statusCode, 200);156 setRequestUrlAndMethod(myRequest1, 'Login-Logout', 'get');157 return request(myRequest1);158 })159 .then(function (logOffResponse) {160 assert.equal(logOffResponse.statusCode, 200);161 })162 // ----- 'wluser4@demandware.com', 'Test123!', '701643238064M'163 .then(function () {164 setRequestUrlAndMethod(myRequest1, 'CSRF-Generate', 'POST');165 return request(myRequest1);166 })167 .then(function (csrfResponse) {168 setRequestToLogin(myRequest1, csrfResponse, 'wluser4@demandware.com', 'Test123!');169 return request(myRequest1);170 })171 .then(function (loginResponse) {172 assert.equal(loginResponse.statusCode, 200);173 setCookieJar(myRequest1, cookieJar);174 setRequestToAddProduct(myRequest1, '701643238064M');175 return request(myRequest1);176 })177 .then(function (addToWishListresponse) {178 assert.equal(addToWishListresponse.statusCode, 200);179 setRequestUrlAndMethod(myRequest1, 'Wishlist-GetListJson', 'get');180 return request(myRequest1);181 })182 .then(function (getListResponse) {183 assert.equal(getListResponse.statusCode, 200);184 setRequestToTogglePublic(myRequest1, getListResponse);185 return request(myRequest1);186 })187 .then(function (toggleResponse) {188 assert.equal(toggleResponse.statusCode, 200);189 setRequestUrlAndMethod(myRequest1, 'Login-Logout', 'get');190 return request(myRequest1);191 })192 .then(function (logOffResponse) {193 assert.equal(logOffResponse.statusCode, 200);194 })195 // ----- 'wluser5@demandware.com', 'Test123!', '701644389413M'196 .then(function () {197 setRequestUrlAndMethod(myRequest1, 'CSRF-Generate', 'POST');198 return request(myRequest1);199 })200 .then(function (csrfResponse) {201 setRequestToLogin(myRequest1, csrfResponse, 'wluser5@demandware.com', 'Test123!');202 return request(myRequest1);203 })204 .then(function (loginResponse) {205 assert.equal(loginResponse.statusCode, 200);206 setCookieJar(myRequest1, cookieJar);207 setRequestToAddProduct(myRequest1, '701644389413M');208 return request(myRequest1);209 })210 .then(function (addToWishListresponse) {211 assert.equal(addToWishListresponse.statusCode, 200);212 setRequestUrlAndMethod(myRequest1, 'Wishlist-GetListJson', 'get');213 return request(myRequest1);214 })215 .then(function (getListResponse) {216 assert.equal(getListResponse.statusCode, 200);217 setRequestToTogglePublic(myRequest1, getListResponse);218 return request(myRequest1);219 })220 .then(function (toggleResponse) {221 assert.equal(toggleResponse.statusCode, 200);222 setRequestUrlAndMethod(myRequest1, 'Login-Logout', 'get');223 return request(myRequest1);224 })225 .then(function (logOffResponse) {226 assert.equal(logOffResponse.statusCode, 200);227 })228 // ----- 'wluser6@demandware.com', 'Test123!', '609717701332M'229 .then(function () {230 setRequestUrlAndMethod(myRequest1, 'CSRF-Generate', 'POST');231 return request(myRequest1);232 })233 .then(function (csrfResponse) {234 setRequestToLogin(myRequest1, csrfResponse, 'wluser6@demandware.com', 'Test123!');235 return request(myRequest1);236 })237 .then(function (loginResponse) {238 assert.equal(loginResponse.statusCode, 200);239 setCookieJar(myRequest1, cookieJar);240 setRequestToAddProduct(myRequest1, '609717701332M');241 return request(myRequest1);242 })243 .then(function (addToWishListresponse) {244 assert.equal(addToWishListresponse.statusCode, 200);245 setRequestUrlAndMethod(myRequest1, 'Wishlist-GetListJson', 'get');246 return request(myRequest1);247 })248 .then(function (getListResponse) {249 assert.equal(getListResponse.statusCode, 200);250 setRequestToTogglePublic(myRequest1, getListResponse);251 return request(myRequest1);252 })253 .then(function (toggleResponse) {254 assert.equal(toggleResponse.statusCode, 200);255 setRequestUrlAndMethod(myRequest1, 'Login-Logout', 'get');256 return request(myRequest1);257 })258 .then(function (logOffResponse) {259 assert.equal(logOffResponse.statusCode, 200);260 })261 // ----- 'wluser7@demandware.com', 'Test123!', '708141677203M'262 .then(function () {263 setRequestUrlAndMethod(myRequest1, 'CSRF-Generate', 'POST');264 return request(myRequest1);265 })266 .then(function (csrfResponse) {267 setRequestToLogin(myRequest1, csrfResponse, 'wluser7@demandware.com', 'Test123!');268 return request(myRequest1);269 })270 .then(function (loginResponse) {271 assert.equal(loginResponse.statusCode, 200);272 setCookieJar(myRequest1, cookieJar);273 setRequestToAddProduct(myRequest1, '708141677203M');274 return request(myRequest1);275 })276 .then(function (addToWishListresponse) {277 assert.equal(addToWishListresponse.statusCode, 200);278 setRequestUrlAndMethod(myRequest1, 'Wishlist-GetListJson', 'get');279 return request(myRequest1);280 })281 .then(function (getListResponse) {282 assert.equal(getListResponse.statusCode, 200);283 setRequestToTogglePublic(myRequest1, getListResponse);284 return request(myRequest1);285 })286 .then(function (toggleResponse) {287 assert.equal(toggleResponse.statusCode, 200);288 setRequestUrlAndMethod(myRequest1, 'Login-Logout', 'get');289 return request(myRequest1);290 })291 .then(function (logOffResponse) {292 assert.equal(logOffResponse.statusCode, 200);293 })294 // ----- 'wluser8@demandware.com', 'Test123!', '883360541808M'295 .then(function () {296 setRequestUrlAndMethod(myRequest1, 'CSRF-Generate', 'POST');297 return request(myRequest1);298 })299 .then(function (csrfResponse) {300 setRequestToLogin(myRequest1, csrfResponse, 'wluser8@demandware.com', 'Test123!');301 return request(myRequest1);302 })303 .then(function (loginResponse) {304 assert.equal(loginResponse.statusCode, 200);305 setCookieJar(myRequest1, cookieJar);306 setRequestToAddProduct(myRequest1, '883360541808M');307 return request(myRequest1);308 })309 .then(function (addToWishListresponse) {310 assert.equal(addToWishListresponse.statusCode, 200);311 setRequestUrlAndMethod(myRequest1, 'Wishlist-GetListJson', 'get');312 return request(myRequest1);313 })314 .then(function (getListResponse) {315 assert.equal(getListResponse.statusCode, 200);316 setRequestToTogglePublic(myRequest1, getListResponse);317 return request(myRequest1);318 })319 .then(function (toggleResponse) {320 assert.equal(toggleResponse.statusCode, 200);321 setRequestUrlAndMethod(myRequest1, 'Login-Logout', 'get');322 return request(myRequest1);323 })324 .then(function (logOffResponse) {325 assert.equal(logOffResponse.statusCode, 200);326 })327 // ----- 'wluser10@demandware.com', 'Test123!', '883360352015M'328 .then(function () {329 setRequestUrlAndMethod(myRequest1, 'CSRF-Generate', 'POST');330 return request(myRequest1);331 })332 .then(function (csrfResponse) {333 setRequestToLogin(myRequest1, csrfResponse, 'wluser10@demandware.com', 'Test123!');334 return request(myRequest1);335 })336 .then(function (loginResponse) {337 assert.equal(loginResponse.statusCode, 200);338 setCookieJar(myRequest1, cookieJar);339 setRequestToAddProduct(myRequest1, '883360352015M');340 return request(myRequest1);341 })342 .then(function (addToWishListresponse) {343 assert.equal(addToWishListresponse.statusCode, 200);344 setRequestUrlAndMethod(myRequest1, 'Wishlist-GetListJson', 'get');345 return request(myRequest1);346 })347 .then(function (getListResponse) {348 assert.equal(getListResponse.statusCode, 200);349 setRequestToTogglePublic(myRequest1, getListResponse);350 return request(myRequest1);351 })352 .then(function (toggleResponse) {353 assert.equal(toggleResponse.statusCode, 200);354 setRequestUrlAndMethod(myRequest1, 'Login-Logout', 'get');355 return request(myRequest1);356 })357 .then(function (logOffResponse) {358 assert.equal(logOffResponse.statusCode, 200);359 });360 });361 after(function () {362 // ----- login, remove wishlist, logout363 var cookieJar2 = request.jar();364 var myRequest2 = {365 url: '',366 method: '',367 rejectUnauthorized: false,368 resolveWithFullResponse: true,369 jar: cookieJar2,370 headers: {371 'X-Requested-With': 'XMLHttpRequest'372 }373 };374 // -- cleanup wluser1@demandware.com375 setRequestUrlAndMethod(myRequest2, 'CSRF-Generate', 'POST');376 return request(myRequest2)377 .then(function (csrfResponse) {378 setRequestToLogin(myRequest2, csrfResponse, 'wluser1@demandware.com', 'Test123!');379 return request(myRequest2);380 })381 .then(function (response) {382 assert.equal(response.statusCode, 200);383 setCookieJar(myRequest2, cookieJar2);384 setRequestUrlAndMethod(myRequest2, 'Wishlist-RemoveList', 'get');385 return request(myRequest2);386 })387 .then(function (removeListResponse) {388 assert.equal(removeListResponse.statusCode, 200);389 setRequestUrlAndMethod(myRequest2, 'Login-Logout', 'get');390 return request(myRequest2);391 })392 .then(function (logOffResponse) {393 assert.equal(logOffResponse.statusCode, 200);394 })395 // -- cleanup wluser2@demandware.com396 .then(function () {397 setRequestUrlAndMethod(myRequest2, 'CSRF-Generate', 'POST');398 return request(myRequest2);399 })400 .then(function (csrfResponse) {401 setRequestToLogin(myRequest2, csrfResponse, 'wluser2@demandware.com', 'Test123!');402 return request(myRequest2);403 })404 .then(function (response) {405 assert.equal(response.statusCode, 200);406 setCookieJar(myRequest2, cookieJar2);407 setRequestUrlAndMethod(myRequest2, 'Wishlist-RemoveList', 'get');408 return request(myRequest2);409 })410 .then(function (removeListResponse) {411 assert.equal(removeListResponse.statusCode, 200);412 setRequestUrlAndMethod(myRequest2, 'Login-Logout', 'get');413 return request(myRequest2);414 })415 .then(function (logOffResponse) {416 assert.equal(logOffResponse.statusCode, 200);417 })418 // -- cleanup wluser3@demandware.com419 .then(function () {420 setRequestUrlAndMethod(myRequest2, 'CSRF-Generate', 'POST');421 return request(myRequest2);422 })423 .then(function (csrfResponse) {424 setRequestToLogin(myRequest2, csrfResponse, 'wluser3@demandware.com', 'Test123!');425 return request(myRequest2);426 })427 .then(function (response) {428 assert.equal(response.statusCode, 200);429 setCookieJar(myRequest2, cookieJar2);430 setRequestUrlAndMethod(myRequest2, 'Wishlist-RemoveList', 'get');431 return request(myRequest2);432 })433 .then(function (removeListResponse) {434 assert.equal(removeListResponse.statusCode, 200);435 setRequestUrlAndMethod(myRequest2, 'Login-Logout', 'get');436 return request(myRequest2);437 })438 .then(function (logOffResponse) {439 assert.equal(logOffResponse.statusCode, 200);440 })441 // -- cleanup wluser4@demandware.com442 .then(function () {443 setRequestUrlAndMethod(myRequest2, 'CSRF-Generate', 'POST');444 return request(myRequest2);445 })446 .then(function (csrfResponse) {447 setRequestToLogin(myRequest2, csrfResponse, 'wluser4@demandware.com', 'Test123!');448 return request(myRequest2);449 })450 .then(function (response) {451 assert.equal(response.statusCode, 200);452 setCookieJar(myRequest2, cookieJar2);453 setRequestUrlAndMethod(myRequest2, 'Wishlist-RemoveList', 'get');454 return request(myRequest2);455 })456 .then(function (removeListResponse) {457 assert.equal(removeListResponse.statusCode, 200);458 setRequestUrlAndMethod(myRequest2, 'Login-Logout', 'get');459 return request(myRequest2);460 })461 .then(function (logOffResponse) {462 assert.equal(logOffResponse.statusCode, 200);463 })464 // -- cleanup wluser5@demandware.com465 .then(function () {466 setRequestUrlAndMethod(myRequest2, 'CSRF-Generate', 'POST');467 return request(myRequest2);468 })469 .then(function (csrfResponse) {470 setRequestToLogin(myRequest2, csrfResponse, 'wluser5@demandware.com', 'Test123!');471 return request(myRequest2);472 })473 .then(function (response) {474 assert.equal(response.statusCode, 200);475 setCookieJar(myRequest2, cookieJar2);476 setRequestUrlAndMethod(myRequest2, 'Wishlist-RemoveList', 'get');477 return request(myRequest2);478 })479 .then(function (removeListResponse) {480 assert.equal(removeListResponse.statusCode, 200);481 setRequestUrlAndMethod(myRequest2, 'Login-Logout', 'get');482 return request(myRequest2);483 })484 .then(function (logOffResponse) {485 assert.equal(logOffResponse.statusCode, 200);486 })487 // -- cleanup wluser6@demandware.com488 .then(function () {489 setRequestUrlAndMethod(myRequest2, 'CSRF-Generate', 'POST');490 return request(myRequest2);491 })492 .then(function (csrfResponse) {493 setRequestToLogin(myRequest2, csrfResponse, 'wluser6@demandware.com', 'Test123!');494 return request(myRequest2);495 })496 .then(function (response) {497 assert.equal(response.statusCode, 200);498 setCookieJar(myRequest2, cookieJar2);499 setRequestUrlAndMethod(myRequest2, 'Wishlist-RemoveList', 'get');500 return request(myRequest2);501 })502 .then(function (removeListResponse) {503 assert.equal(removeListResponse.statusCode, 200);504 setRequestUrlAndMethod(myRequest2, 'Login-Logout', 'get');505 return request(myRequest2);506 })507 .then(function (logOffResponse) {508 assert.equal(logOffResponse.statusCode, 200);509 })510 // -- cleanup wluser7@demandware.com511 .then(function () {512 setRequestUrlAndMethod(myRequest2, 'CSRF-Generate', 'POST');513 return request(myRequest2);514 })515 .then(function (csrfResponse) {516 setRequestToLogin(myRequest2, csrfResponse, 'wluser7@demandware.com', 'Test123!');517 return request(myRequest2);518 })519 .then(function (response) {520 assert.equal(response.statusCode, 200);521 setCookieJar(myRequest2, cookieJar2);522 setRequestUrlAndMethod(myRequest2, 'Wishlist-RemoveList', 'get');523 return request(myRequest2);524 })525 .then(function (removeListResponse) {526 assert.equal(removeListResponse.statusCode, 200);527 setRequestUrlAndMethod(myRequest2, 'Login-Logout', 'get');528 return request(myRequest2);529 })530 .then(function (logOffResponse) {531 assert.equal(logOffResponse.statusCode, 200);532 })533 // -- cleanup wluser8@demandware.com534 .then(function () {535 setRequestUrlAndMethod(myRequest2, 'CSRF-Generate', 'POST');536 return request(myRequest2);537 })538 .then(function (csrfResponse) {539 setRequestToLogin(myRequest2, csrfResponse, 'wluser8@demandware.com', 'Test123!');540 return request(myRequest2);541 })542 .then(function (response) {543 assert.equal(response.statusCode, 200);544 setCookieJar(myRequest2, cookieJar2);545 setRequestUrlAndMethod(myRequest2, 'Wishlist-RemoveList', 'get');546 return request(myRequest2);547 })548 .then(function (removeListResponse) {549 assert.equal(removeListResponse.statusCode, 200);550 setRequestUrlAndMethod(myRequest2, 'Login-Logout', 'get');551 return request(myRequest2);552 })553 .then(function (logOffResponse) {554 assert.equal(logOffResponse.statusCode, 200);555 })556 // -- cleanup wluser10@demandware.com557 .then(function () {558 setRequestUrlAndMethod(myRequest2, 'CSRF-Generate', 'POST');559 return request(myRequest2);560 })561 .then(function (csrfResponse) {562 setRequestToLogin(myRequest2, csrfResponse, 'wluser10@demandware.com', 'Test123!');563 return request(myRequest2);564 })565 .then(function (response) {566 assert.equal(response.statusCode, 200);567 setCookieJar(myRequest2, cookieJar2);568 setRequestUrlAndMethod(myRequest2, 'Wishlist-RemoveList', 'get');569 return request(myRequest2);570 })571 .then(function (removeListResponse) {572 assert.equal(removeListResponse.statusCode, 200);573 setRequestUrlAndMethod(myRequest2, 'Login-Logout', 'get');574 return request(myRequest2);575 })576 .then(function (logOffResponse) {577 assert.equal(logOffResponse.statusCode, 200);578 });579 });580 it('should return the first page of a search result', function () {581 var expectedResult1 = {582 'results': {583 'totalNumber': 8,584 'pageNumber': 1,585 'pageSize': 8,586 'total': 9,587 'totalString': '9 Results',588 'showMore': true,589 'firstName': '',590 'lastName': 'WLuser',591 'changedList': false592 }593 };594 var mySearchRequest = {595 url: '',596 method: 'POST',597 rejectUnauthorized: false,598 resolveWithFullResponse: true,599 headers: {600 'X-Requested-With': 'XMLHttpRequest'601 }602 };603 mySearchRequest.form = {604 firstName: '',605 lastName: 'WLuser',606 uuids: JSON.stringify([]),607 pageNumber: 1608 };609 mySearchRequest.url = config.baseUrl + '/Wishlist-MoreResults';610 return request(mySearchRequest)611 .then(function (response) {612 assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');613 var bodyAsJson = JSON.parse(response.body);614 assert.lengthOf(bodyAsJson.results.hits, 8);615 bodyAsJson.results.hits.forEach(function (hit) {616 assert.notEqual(hit.firstName, 'WLUser9');617 assert.isNotNull(hit.lastName, 'hit.lastName expected to exist');618 assert.isNotNull(hit.email, 'hit.email expected to exist');619 assert.isNotNull(hit.id, 'hit.id expected to exist');620 assert.isNotNull(hit.url, 'hit.url expected to exist');621 assert.equal(hit.urlTitle, 'View Wishlist');622 assert.equal(hit.urlText, 'View');623 });624 assert.equal(bodyAsJson.results.totalNumber, expectedResult1.results.totalNumber);625 assert.equal(bodyAsJson.results.pageNumber, expectedResult1.results.pageNumber);626 assert.equal(bodyAsJson.results.pageSize, expectedResult1.results.pageSize);627 assert.equal(bodyAsJson.results.total, expectedResult1.results.total);628 assert.equal(bodyAsJson.results.totalString, expectedResult1.results.totalString);629 assert.equal(bodyAsJson.results.showMore, expectedResult1.results.showMore);630 assert.isUndefined(bodyAsJson.results.firstName, expectedResult1.results.firstName);631 assert.equal(bodyAsJson.results.lastName, expectedResult1.results.lastName);632 assert.equal(bodyAsJson.results.changedList, expectedResult1.results.changedList);633 });634 });635 it('should return the second / last page in a search result of wishlist', function () {636 var expectedResult2 = {637 'results': {638 'totalNumber': 1,639 'pageNumber': 2,640 'pageSize': 8,641 'total': 9,642 'totalString': '9 Results',643 'showMore': false,644 'firstName': '',645 'lastName': 'WLuser',646 'changedList': false647 }648 };649 var mySearchRequest = {650 url: '',651 method: 'POST',652 rejectUnauthorized: false,653 resolveWithFullResponse: true,654 jar: cookieJar,655 headers: {656 'X-Requested-With': 'XMLHttpRequest'657 }658 };659 mySearchRequest.form = {660 firstName: '',661 lastName: 'WLuser',662 uuids: JSON.stringify([]),663 pageNumber: 2664 };665 mySearchRequest.url = config.baseUrl + '/Wishlist-MoreResults';666 return request(mySearchRequest)667 .then(function (response) {668 assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');669 var bodyAsJson = JSON.parse(response.body);670 assert.lengthOf(bodyAsJson.results.hits, 1);671 bodyAsJson.results.hits.forEach(function (hit) {672 assert.notEqual(hit.firstName, 'WLUser9');673 assert.isNotNull(hit.lastName, 'hit.lastName expected to exist');674 assert.isNotNull(hit.email, 'hit.email expected to exist');675 assert.isNotNull(hit.id, 'hit.id expected to exist');676 assert.isNotNull(hit.url, 'hit.url expected to exist');677 assert.equal(hit.urlTitle, 'View Wishlist');678 assert.equal(hit.urlText, 'View');679 });680 assert.equal(bodyAsJson.results.totalNumber, expectedResult2.results.totalNumber);681 assert.equal(bodyAsJson.results.pageNumber, expectedResult2.results.pageNumber);682 assert.equal(bodyAsJson.results.pageSize, expectedResult2.results.pageSize);683 assert.equal(bodyAsJson.results.total, expectedResult2.results.total);684 assert.equal(bodyAsJson.results.totalString, expectedResult2.results.totalString);685 assert.equal(bodyAsJson.results.showMore, expectedResult2.results.showMore);686 assert.isUndefined(bodyAsJson.results.firstName, expectedResult2.results.firstName);687 assert.equal(bodyAsJson.results.lastName, expectedResult2.results.lastName);688 assert.equal(bodyAsJson.results.changedList, expectedResult2.results.changedList);689 });690 });691 it('should return hit when first name is used.', function () {692 var mySearchRequest = {693 url: '',694 method: 'POST',695 rejectUnauthorized: false,696 resolveWithFullResponse: true,697 jar: cookieJar,698 headers: {699 'X-Requested-With': 'XMLHttpRequest'700 }701 };702 mySearchRequest.form = {703 firstName: 'WLUser1',704 lastName: '',705 uuids: JSON.stringify([]),706 pageNumber: 1707 };708 mySearchRequest.url = config.baseUrl + '/Wishlist-MoreResults';709 return request(mySearchRequest)710 .then(function (response) {711 assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');712 var bodyAsJson = JSON.parse(response.body);713 var hits = bodyAsJson.results.hits;714 assert.lengthOf(hits, 1);715 assert.equal(hits[0].firstName, 'WLUser1');716 assert.equal(hits[0].lastName, 'WLuser');717 });718 });719 it('should return hit when both first name and last name are used.', function () {720 var mySearchRequest = {721 url: '',722 method: 'POST',723 rejectUnauthorized: false,724 resolveWithFullResponse: true,725 jar: cookieJar,726 headers: {727 'X-Requested-With': 'XMLHttpRequest'728 }729 };730 mySearchRequest.form = {731 firstName: 'WLUser2',732 lastName: 'WLuser',733 uuids: JSON.stringify([]),734 pageNumber: 1735 };736 mySearchRequest.url = config.baseUrl + '/Wishlist-MoreResults';737 return request(mySearchRequest)738 .then(function (response) {739 assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');740 var bodyAsJson = JSON.parse(response.body);741 var hits = bodyAsJson.results.hits;742 assert.lengthOf(hits, 1);743 assert.equal(hits[0].firstName, 'WLUser2');744 assert.equal(hits[0].lastName, 'WLuser');745 assert.isNotNull(hits[0].id, 'hit.id expected to exist');746 assert.isNotNull(hits[0].url, 'hit.url expected to exist');747 });748 });749 it('should return empty hits when there is no match.', function () {750 var mySearchRequest = {751 url: '',752 method: 'POST',753 rejectUnauthorized: false,754 resolveWithFullResponse: true,755 jar: cookieJar,756 headers: {757 'X-Requested-With': 'XMLHttpRequest'758 }759 };760 mySearchRequest.form = {761 firstName: '',762 lastName: 'abc',763 uuids: JSON.stringify([]),764 pageNumber: 1765 };766 mySearchRequest.url = config.baseUrl + '/Wishlist-MoreResults';767 return request(mySearchRequest)768 .then(function (response) {769 assert.equal(response.statusCode, 200, 'Expected statusCode to be 200.');770 var bodyAsJson = JSON.parse(response.body);771 assert.lengthOf(bodyAsJson.results.hits, 0);772 });773 });...
atmosphere-tests.ts
Source:atmosphere-tests.ts
1/// <reference path="atmosphere.d.ts" />2var socket = atmosphere;3var request1:Atmosphere.Request = new atmosphere.AtmosphereRequest();4request1.url = document.location.toString() + 'chat';5request1.contentType = "application/json";6request1.transport = 'websocket';7request1.fallbackTransport = 'long-polling';8var request2:Atmosphere.Request = {9 url: 'http://localhost:8080/chat',10 contentType: "application/json",11 logLevel: 'debug',12 transport: 'websocket',13 fallbackTransport: 'long-polling'14};15request1.onError = function (response?:Atmosphere.Response) {};16request1.onClose = function (response?:Atmosphere.Response) {};17request1.onOpen = function (response?:Atmosphere.Response) {};18request1.onMessage = function (response:Atmosphere.Response) {};19request1.onReopen = function (request?:Atmosphere.Request, response?:Atmosphere.Response) {};20request1.onReconnect = function (request?:Atmosphere.Request, response?:Atmosphere.Response) {};21request1.onMessagePublished = function (response?:Atmosphere.Response) {};22request1.onTransportFailure = function (reason?:string, response?:Atmosphere.Response) {};23request1.onLocalMessage = function (request?:Atmosphere.Request) {};24request1.onFailureToReconnect = function (request?:Atmosphere.Request, response?:Atmosphere.Response) {};25request1.onClientTimeout = function (request?:Atmosphere.Request) {};26request1.subscribe = function (options:Atmosphere.Request) {};27request1.execute = function () {};28request1.close = function () {};29request1.disconnect = function () {};30request1.getUrl = function ():string { return "http://www.toedter.com" };31request1.push = function (message:string, dispatchUrl?:string) {};32request1.getUUID = function () {};33request1.pushLocal = function (message:string) {};34var subSocket:Atmosphere.Request = socket.subscribe(request1);35var subSocket2:Atmosphere.Request = socket.subscribe('http://chat.com', function() {}, request2);36subSocket2.close();37subSocket.push("test");...
Using AI Code Generation
1var wpt = require('wpt');2 console.log(data);3});4var wpt = require('wpt');5 console.log(data);6});7MIT © [Vikram Singh](
Using AI Code Generation
1var wpt = require('wpt');2 if(err){3 console.log(err);4 } else {5 console.log(data);6 }7});8{ statusCode: 200,
Using AI Code Generation
1var wpt = require('wpt');2var request1 = wpt.request1;3request1('url', function(error, response, body) {4 if (!error && response.statusCode == 200) {5 }6})7var wpt = require('wpt');8var request2 = wpt.request2;9request2('url', function(error, response, body) {10 if (!error && response.statusCode == 200) {11 }12})13[MIT](LICENSE)
Using AI Code Generation
1var wpt = require('./wpt.js');2wpt.request1('www.google.com',function(err, data){3 if (err) {4 console.log(err);5 }6 else {7 console.log(data);8 }9});10This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdefghijklmnopqrstuv');3wpt.request1(url, function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});
Using AI Code Generation
1var wpt = require('./wpt');2 console.log(data);3});4var request = require('request');5var wpt = {6 request1: function(url, callback){7 request(url, function(error, response, body){8 if(error){9 callback(error, null);10 }else{11 callback(null, body);12 }13 });14 }15}16module.exports = wpt;
Using AI Code Generation
1var wpt = require('wpt-api');2 console.log(res);3});4var wpt = require('wpt-api');5 console.log(res);6});7var wpt = require('wpt-api');8 console.log(res);9});10var wpt = require('wpt-api');11 console.log(res);12});13var wpt = require('wpt-api');14 console.log(res);15});16var wpt = require('wpt-api');17 console.log(res);18});19var wpt = require('wpt-api');20 console.log(res);21});22var wpt = require('wpt-api');23 console.log(res);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!!