Best JavaScript code snippet using appium
themoviedb.js
Source:themoviedb.js
1/*2 * The MIT License (MIT)3 *4 * Copyright (c) 2016 Franco Cavestri5 *6 * https://github.com/cavestri/themoviedb-javascript-library7 *8 */9var theMovieDb = {};10theMovieDb.common = {11 api_key: "",12 base_uri: "http://api.themoviedb.org/3/",13 images_uri: "http://image.tmdb.org/t/p/",14 timeout: 5000,15 generateQuery: function (options) {16 'use strict';17 var myOptions, query, option;18 myOptions = options || {};19 query = "?api_key=" + theMovieDb.common.api_key;20 if (Object.keys(myOptions).length > 0) {21 for (option in myOptions) {22 if (myOptions.hasOwnProperty(option) && option !== "id" && option !== "body") {23 query = query + "&" + option + "=" + myOptions[option];24 }25 }26 }27 return query;28 },29 validateCallbacks: function (callbacks) {30 'use strict';31 if (typeof callbacks[0] !== "function" || typeof callbacks[1] !== "function") {32 throw "Success and error parameters must be functions!";33 }34 },35 validateRequired: function (args, argsReq, opt, optReq, allOpt) {36 'use strict';37 var i, allOptional;38 allOptional = allOpt || false;39 if (args.length !== argsReq) {40 throw "The method requires " + argsReq + " arguments and you are sending " + args.length + "!";41 }42 if (allOptional) {43 return;44 }45 if (argsReq > 2) {46 for (i = 0; i < optReq.length; i = i + 1) {47 if (!opt.hasOwnProperty(optReq[i])) {48 throw optReq[i] + " is a required parameter and is not present in the options!";49 }50 }51 }52 },53 getImage: function (options) {54 'use strict';55 return theMovieDb.common.images_uri + options.size + "/" + options.file;56 },57 client: function (options, success, error) {58 'use strict';59 var method, status, xhr;60 method = options.method || "GET";61 status = options.status || 200;62 xhr = new XMLHttpRequest();63 xhr.ontimeout = function () {64 error('{"status_code":408,"status_message":"Request timed out"}');65 };66 xhr.open(method, theMovieDb.common.base_uri + options.url, true);67 if(options.method === "POST") {68 xhr.setRequestHeader("Content-Type", "application/json");69 xhr.setRequestHeader("Accept", "application/json");70 }71 xhr.timeout = theMovieDb.common.timeout;72 xhr.onload = function (e) {73 if (xhr.readyState === 4) {74 if (xhr.status === status) {75 success(xhr.responseText);76 } else {77 error(xhr.responseText);78 }79 } else {80 error(xhr.responseText);81 }82 };83 xhr.onerror = function (e) {84 error(xhr.responseText);85 };86 if (options.method === "POST") {87 xhr.send(JSON.stringify(options.body));88 } else {89 xhr.send(null);90 }91 }92};93theMovieDb.configurations = {94 getConfiguration: function (success, error) {95 'use strict';96 theMovieDb.common.validateRequired(arguments, 2);97 theMovieDb.common.validateCallbacks([success, error]);98 theMovieDb.common.client(99 {100 url: "configuration" + theMovieDb.common.generateQuery()101 },102 success,103 error104 );105 }106};107theMovieDb.account = {108 getInformation: function (options, success, error) {109 'use strict';110 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id"]);111 theMovieDb.common.validateCallbacks([success, error]);112 theMovieDb.common.client(113 {114 url: "account" + theMovieDb.common.generateQuery(options)115 },116 success,117 error118 );119 },120 getLists: function (options, success, error) {121 'use strict';122 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "id"]);123 theMovieDb.common.validateCallbacks([success, error]);124 theMovieDb.common.client(125 {126 url: "account/" + options.id + "/lists" + theMovieDb.common.generateQuery(options)127 },128 success,129 error130 );131 },132 getFavoritesMovies: function (options, success, error) {133 'use strict';134 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "id"]);135 theMovieDb.common.validateCallbacks([success, error]);136 theMovieDb.common.client(137 {138 url: "account/" + options.id + "/favorite_movies" + theMovieDb.common.generateQuery(options)139 },140 success,141 error142 );143 },144 addFavorite: function (options, success, error) {145 'use strict';146 var body;147 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "id", "movie_id", "favorite"]);148 theMovieDb.common.validateCallbacks([success, error]);149 body = {150 "movie_id": options.movie_id,151 "favorite": options.favorite152 }153 theMovieDb.common.client(154 {155 url: "account/" + options.id + "/favorite" + theMovieDb.common.generateQuery(options),156 status: 201,157 method: "POST",158 body: body159 },160 success,161 error162 );163 },164 getRatedMovies: function (options, success, error) {165 'use strict';166 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "id"]);167 theMovieDb.common.validateCallbacks([success, error]);168 theMovieDb.common.client(169 {170 url: "account/" + options.id + "/rated_movies" + theMovieDb.common.generateQuery(options)171 },172 success,173 error174 );175 },176 getWatchlist: function (options, success, error) {177 'use strict';178 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "id"]);179 theMovieDb.common.validateCallbacks([success, error]);180 theMovieDb.common.client(181 {182 url: "account/" + options.id + "/movie_watchlist" + theMovieDb.common.generateQuery(options)183 },184 success,185 error186 );187 },188 addMovieToWatchlist: function (options, success, error) {189 'use strict';190 var body;191 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "id", "movie_id", "movie_watchlist"]);192 theMovieDb.common.validateCallbacks([success, error]);193 body = {194 "movie_id": options.movie_id,195 "movie_watchlist": options.movie_watchlist196 }197 theMovieDb.common.client(198 {199 url: "account/" + options.id + "/movie_watchlist" + theMovieDb.common.generateQuery(options),200 method: "POST",201 status: 201,202 body: body203 },204 success,205 error206 );207 }208};209theMovieDb.authentication = {210 generateToken: function (success, error) {211 'use strict';212 theMovieDb.common.validateRequired(arguments, 2);213 theMovieDb.common.validateCallbacks([success, error]);214 theMovieDb.common.client(215 {216 url: "authentication/token/new" + theMovieDb.common.generateQuery()217 },218 success,219 error220 );221 },222 askPermissions: function(options){223 'use strict';224 window.open("https://www.themoviedb.org/authenticate/" + options.token + "?redirect_to=" + options.redirect_to);225 },226 validateUser: function (options, success, error) {227 'use strict';228 theMovieDb.common.validateRequired(arguments, 3, options, ["request_token", "username", "password"]);229 theMovieDb.common.validateCallbacks([success, error]);230 theMovieDb.common.client(231 {232 url: "authentication/token/validate_with_login" + theMovieDb.common.generateQuery(options)233 },234 success,235 error236 );237 },238 generateSession: function (options, success, error) {239 'use strict';240 theMovieDb.common.validateRequired(arguments, 3, options, ["request_token"]);241 theMovieDb.common.validateCallbacks([success, error]);242 theMovieDb.common.client(243 {244 url: "authentication/session/new" + theMovieDb.common.generateQuery(options)245 },246 success,247 error248 );249 },250 generateGuestSession: function (success, error) {251 'use strict';252 theMovieDb.common.validateRequired(arguments, 2);253 theMovieDb.common.validateCallbacks([success, error]);254 theMovieDb.common.client(255 {256 url: "authentication/guest_session/new" + theMovieDb.common.generateQuery()257 },258 success,259 error260 );261 }262};263theMovieDb.certifications = {264 getList: function (success, error) {265 'use strict';266 theMovieDb.common.validateRequired(arguments, 2);267 theMovieDb.common.validateCallbacks([success, error]);268 theMovieDb.common.client(269 {270 url: "certification/movie/list" + theMovieDb.common.generateQuery()271 },272 success,273 error274 );275 }276};277theMovieDb.changes = {278 getMovieChanges: function (options, success, error) {279 'use strict';280 theMovieDb.common.validateRequired(arguments, 3, "", "", true);281 theMovieDb.common.validateCallbacks([success, error]);282 theMovieDb.common.client(283 {284 url: "movie/changes" + theMovieDb.common.generateQuery(options)285 },286 success,287 error288 );289 },290 getPersonChanges: function (options, success, error) {291 'use strict';292 theMovieDb.common.validateRequired(arguments, 3, "", "", true);293 theMovieDb.common.validateCallbacks([success, error]);294 theMovieDb.common.client(295 {296 url: "person/changes" + theMovieDb.common.generateQuery(options)297 },298 success,299 error300 );301 }302};303theMovieDb.collections = {304 getCollection: function (options, success, error) {305 'use strict';306 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);307 theMovieDb.common.validateCallbacks([success, error]);308 theMovieDb.common.client(309 {310 url: "collection/" + options.id + theMovieDb.common.generateQuery(options)311 },312 success,313 error314 );315 },316 getCollectionImages: function (options, success, error) {317 'use strict';318 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);319 theMovieDb.common.validateCallbacks([success, error]);320 theMovieDb.common.client(321 {322 url: "collection/" + options.id + "/images" + theMovieDb.common.generateQuery(options)323 },324 success,325 error326 );327 }328};329theMovieDb.companies = {330 getCompany: function (options, success, error) {331 'use strict';332 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);333 theMovieDb.common.validateCallbacks([success, error]);334 theMovieDb.common.client(335 {336 url: "company/" + options.id + theMovieDb.common.generateQuery(options)337 },338 success,339 error340 );341 },342 getCompanyMovies: function (options, success, error) {343 'use strict';344 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);345 theMovieDb.common.validateCallbacks([success, error]);346 theMovieDb.common.client(347 {348 url: "company/" + options.id + "/movies" + theMovieDb.common.generateQuery(options)349 },350 success,351 error352 );353 }354};355theMovieDb.credits = {356 getCredit: function (options, success, error) {357 'use strict';358 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);359 theMovieDb.common.validateCallbacks([success, error]);360 theMovieDb.common.client(361 {362 url: "credit/" + options.id + theMovieDb.common.generateQuery(options)363 },364 success,365 error366 );367 }368};369theMovieDb.discover = {370 getMovies: function (options, success, error) {371 'use strict';372 theMovieDb.common.validateRequired(arguments, 3, "", "", true);373 theMovieDb.common.validateCallbacks([success, error]);374 theMovieDb.common.client(375 {376 url: "discover/movie" + theMovieDb.common.generateQuery(options)377 },378 success,379 error380 );381 },382 getTvShows: function (options, success, error) {383 'use strict';384 theMovieDb.common.validateRequired(arguments, 3, "", "", true);385 theMovieDb.common.validateCallbacks([success, error]);386 theMovieDb.common.client(387 {388 url: "discover/tv" + theMovieDb.common.generateQuery(options)389 },390 success,391 error392 );393 }394};395theMovieDb.find = {396 getById: function (options, success, error) {397 'use strict';398 theMovieDb.common.validateRequired(arguments, 3, options, ["id", "external_source"]);399 theMovieDb.common.validateCallbacks([success, error]);400 theMovieDb.common.client(401 {402 url: "find/" + options.id + theMovieDb.common.generateQuery(options)403 },404 success,405 error406 );407 }408};409theMovieDb.genres = {410 getList: function (options, success, error) {411 'use strict';412 theMovieDb.common.validateRequired(arguments, 3, "", "", true);413 theMovieDb.common.validateCallbacks([success, error]);414 theMovieDb.common.client(415 {416 url: "genre/list" + theMovieDb.common.generateQuery(options)417 },418 success,419 error420 );421 },422 getMovies: function (options, success, error) {423 'use strict';424 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);425 theMovieDb.common.validateCallbacks([success, error]);426 theMovieDb.common.client(427 {428 url: "genre/" + options.id + "/movies" + theMovieDb.common.generateQuery(options)429 },430 success,431 error432 );433 }434};435theMovieDb.jobs = {436 getList: function (success, error) {437 'use strict';438 theMovieDb.common.validateRequired(arguments, 2);439 theMovieDb.common.validateCallbacks([success, error]);440 theMovieDb.common.client(441 {442 url: "job/list" + theMovieDb.common.generateQuery()443 },444 success,445 error446 );447 }448};449theMovieDb.keywords = {450 getById: function (options, success, error) {451 'use strict';452 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);453 theMovieDb.common.validateCallbacks([success, error]);454 theMovieDb.common.client(455 {456 url: "keyword/" + options.id + theMovieDb.common.generateQuery(options)457 },458 success,459 error460 );461 },462 getMovies: function (options, success, error) {463 'use strict';464 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);465 theMovieDb.common.validateCallbacks([success, error]);466 theMovieDb.common.client(467 {468 url: "keyword/" + options.id + "/movies" + theMovieDb.common.generateQuery(options)469 },470 success,471 error472 );473 }474};475theMovieDb.lists = {476 getById: function (options, success, error) {477 'use strict';478 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);479 theMovieDb.common.validateCallbacks([success, error]);480 theMovieDb.common.client(481 {482 url: "list/" + options.id + theMovieDb.common.generateQuery(options)483 },484 success,485 error486 );487 },488 getStatusById: function (options, success, error) {489 'use strict';490 theMovieDb.common.validateRequired(arguments, 3, options, ["id", "movie_id"]);491 theMovieDb.common.validateCallbacks([success, error]);492 theMovieDb.common.client(493 {494 url: "list/" + options.id + "/item_status" + theMovieDb.common.generateQuery(options)495 },496 success,497 error498 );499 },500 addList: function (options, success, error) {501 'use strict';502 var body;503 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "name", "description"]);504 theMovieDb.common.validateCallbacks([success, error]);505 body = {506 "name": options.name,507 "description": options.description508 };509 delete options.name;510 delete options.description;511 if(options.hasOwnProperty("language")) {512 body["language"] = options.language;513 delete options.language;514 }515 theMovieDb.common.client(516 {517 method: "POST",518 status: 201,519 url: "list" + theMovieDb.common.generateQuery(options),520 body: body521 },522 success,523 error524 );525 },526 addItem: function (options, success, error) {527 'use strict';528 var body;529 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "id", "media_id"]);530 theMovieDb.common.validateCallbacks([success, error]);531 body = {532 "media_id": options.media_id533 };534 theMovieDb.common.client(535 {536 method: "POST",537 status: 201,538 url: "list/" + options.id + "/add_item" + theMovieDb.common.generateQuery(options),539 body: body540 },541 success,542 error543 );544 },545 removeItem: function (options, success, error) {546 'use strict';547 var body;548 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "id", "media_id"]);549 theMovieDb.common.validateCallbacks([success, error]);550 body = {551 "media_id": options.media_id552 };553 theMovieDb.common.client(554 {555 method: "POST",556 status: 201,557 url: "list/" + options.id + "/remove_item" + theMovieDb.common.generateQuery(options),558 body: body559 },560 success,561 error562 );563 },564 removeList: function (options, success, error) {565 'use strict';566 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "id"]);567 theMovieDb.common.validateCallbacks([success, error]);568 theMovieDb.common.client(569 {570 method: "DELETE",571 status: 204,572 url: "list/" + options.id + theMovieDb.common.generateQuery(options)573 },574 success,575 error576 );577 },578 clearList: function (options, success, error) {579 'use strict';580 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "id", "confirm"]);581 theMovieDb.common.validateCallbacks([success, error]);582 theMovieDb.common.client(583 {584 method: "POST",585 status: 204,586 body: {},587 url: "list/" + options.id + "/clear" + theMovieDb.common.generateQuery(options)588 },589 success,590 error591 );592 }593};594theMovieDb.movies = {595 getById: function (options, success, error) {596 'use strict';597 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);598 theMovieDb.common.validateCallbacks([success, error]);599 theMovieDb.common.client(600 {601 url: "movie/" + options.id + theMovieDb.common.generateQuery(options)602 },603 success,604 error605 );606 },607 getAlternativeTitles: function (options, success, error) {608 'use strict';609 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);610 theMovieDb.common.validateCallbacks([success, error]);611 theMovieDb.common.client(612 {613 url: "movie/" + options.id + "/alternative_titles" + theMovieDb.common.generateQuery(options)614 },615 success,616 error617 );618 },619 getCredits: function (options, success, error) {620 'use strict';621 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);622 theMovieDb.common.validateCallbacks([success, error]);623 theMovieDb.common.client(624 {625 url: "movie/" + options.id + "/credits" + theMovieDb.common.generateQuery(options)626 },627 success,628 error629 );630 },631 getImages: function (options, success, error) {632 'use strict';633 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);634 theMovieDb.common.validateCallbacks([success, error]);635 theMovieDb.common.client(636 {637 url: "movie/" + options.id + "/images" + theMovieDb.common.generateQuery(options)638 },639 success,640 error641 );642 },643 getKeywords: function (options, success, error) {644 'use strict';645 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);646 theMovieDb.common.validateCallbacks([success, error]);647 theMovieDb.common.client(648 {649 url: "movie/" + options.id + "/keywords" + theMovieDb.common.generateQuery(options)650 },651 success,652 error653 );654 },655 getReleases: function (options, success, error) {656 'use strict';657 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);658 theMovieDb.common.validateCallbacks([success, error]);659 theMovieDb.common.client(660 {661 url: "movie/" + options.id + "/releases" + theMovieDb.common.generateQuery(options)662 },663 success,664 error665 );666 },667 getTrailers: function (options, success, error) {668 'use strict';669 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);670 theMovieDb.common.validateCallbacks([success, error]);671 theMovieDb.common.client(672 {673 url: "movie/" + options.id + "/trailers" + theMovieDb.common.generateQuery(options)674 },675 success,676 error677 );678 },679 getVideos: function (options, success, error) {680 'use strict';681 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);682 theMovieDb.common.validateCallbacks([success, error]);683 theMovieDb.common.client(684 {685 url: "movie/" + options.id + "/videos" + theMovieDb.common.generateQuery(options)686 },687 success,688 error689 );690 },691 getTranslations: function (options, success, error) {692 'use strict';693 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);694 theMovieDb.common.validateCallbacks([success, error]);695 theMovieDb.common.client(696 {697 url: "movie/" + options.id + "/translations" + theMovieDb.common.generateQuery(options)698 },699 success,700 error701 );702 },703 getSimilarMovies: function (options, success, error) {704 'use strict';705 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);706 theMovieDb.common.validateCallbacks([success, error]);707 theMovieDb.common.client(708 {709 url: "movie/" + options.id + "/similar_movies" + theMovieDb.common.generateQuery(options)710 },711 success,712 error713 );714 },715 getReviews: function (options, success, error) {716 'use strict';717 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);718 theMovieDb.common.validateCallbacks([success, error]);719 theMovieDb.common.client(720 {721 url: "movie/" + options.id + "/reviews" + theMovieDb.common.generateQuery(options)722 },723 success,724 error725 );726 },727 getLists: function (options, success, error) {728 'use strict';729 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);730 theMovieDb.common.validateCallbacks([success, error]);731 theMovieDb.common.client(732 {733 url: "movie/" + options.id + "/lists" + theMovieDb.common.generateQuery(options)734 },735 success,736 error737 );738 },739 getChanges: function (options, success, error) {740 'use strict';741 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);742 theMovieDb.common.validateCallbacks([success, error]);743 theMovieDb.common.client(744 {745 url: "movie/" + options.id + "/changes" + theMovieDb.common.generateQuery(options)746 },747 success,748 error749 );750 },751 getLatest: function (success, error) {752 'use strict';753 theMovieDb.common.validateRequired(arguments, 2);754 theMovieDb.common.validateCallbacks([success, error]);755 theMovieDb.common.client(756 {757 url: "movie/latest" + theMovieDb.common.generateQuery()758 },759 success,760 error761 );762 },763 getUpcoming: function (options, success, error) {764 'use strict';765 theMovieDb.common.validateRequired(arguments, 3, "", "", true);766 theMovieDb.common.validateCallbacks([success, error]);767 theMovieDb.common.client(768 {769 url: "movie/upcoming" + theMovieDb.common.generateQuery(options)770 },771 success,772 error773 );774 },775 getNowPlaying: function (options, success, error) {776 'use strict';777 theMovieDb.common.validateRequired(arguments, 3, "", "", true);778 theMovieDb.common.validateCallbacks([success, error]);779 theMovieDb.common.client(780 {781 url: "movie/now_playing" + theMovieDb.common.generateQuery(options)782 },783 success,784 error785 );786 },787 getPopular: function (options, success, error) {788 'use strict';789 theMovieDb.common.validateRequired(arguments, 3, "", "", true);790 theMovieDb.common.validateCallbacks([success, error]);791 theMovieDb.common.client(792 {793 url: "movie/popular" + theMovieDb.common.generateQuery(options)794 },795 success,796 error797 );798 },799 getTopRated: function (options, success, error) {800 'use strict';801 theMovieDb.common.validateRequired(arguments, 3, "", "", true);802 theMovieDb.common.validateCallbacks([success, error]);803 theMovieDb.common.client(804 {805 url: "movie/top_rated" + theMovieDb.common.generateQuery(options)806 },807 success,808 error809 );810 },811 getStatus: function (options, success, error) {812 'use strict';813 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "id"]);814 theMovieDb.common.validateCallbacks([success, error]);815 theMovieDb.common.client(816 {817 url: "movie/" + options.id + "/account_states" + theMovieDb.common.generateQuery(options)818 },819 success,820 error821 );822 },823 rate: function (options, rate, success, error) {824 'use strict';825 theMovieDb.common.validateRequired(arguments, 4, options, ["session_id", "id"]);826 theMovieDb.common.validateCallbacks([success, error]);827 theMovieDb.common.client(828 {829 method: "POST",830 status: 201,831 url: "movie/" + options.id + "/rating" + theMovieDb.common.generateQuery(options),832 body: { "value": rate }833 },834 success,835 error836 );837 },838 rateGuest: function (options, rate, success, error) {839 'use strict';840 theMovieDb.common.validateRequired(arguments, 4, options, ["guest_session_id", "id"]);841 theMovieDb.common.validateCallbacks([success, error]);842 theMovieDb.common.client(843 {844 method: "POST",845 status: 201,846 url: "movie/" + options.id + "/rating" + theMovieDb.common.generateQuery(options),847 body: { "value": rate }848 },849 success,850 error851 );852 }853};854theMovieDb.networks = {855 getById: function (options, success, error) {856 'use strict';857 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);858 theMovieDb.common.validateCallbacks([success, error]);859 theMovieDb.common.client(860 {861 url: "network/" + options.id + theMovieDb.common.generateQuery(options)862 },863 success,864 error865 );866 }867};868theMovieDb.people = {869 getById: function (options, success, error) {870 'use strict';871 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);872 theMovieDb.common.validateCallbacks([success, error]);873 theMovieDb.common.client(874 {875 url: "person/" + options.id + theMovieDb.common.generateQuery(options)876 },877 success,878 error879 );880 },881 getMovieCredits: function (options, success, error) {882 'use strict';883 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);884 theMovieDb.common.validateCallbacks([success, error]);885 theMovieDb.common.client(886 {887 url: "person/" + options.id + "/movie_credits" + theMovieDb.common.generateQuery(options)888 },889 success,890 error891 );892 },893 getTvCredits: function (options, success, error) {894 'use strict';895 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);896 theMovieDb.common.validateCallbacks([success, error]);897 theMovieDb.common.client(898 {899 url: "person/" + options.id + "/tv_credits" + theMovieDb.common.generateQuery(options)900 },901 success,902 error903 );904 },905 getCredits: function (options, success, error) {906 'use strict';907 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);908 theMovieDb.common.validateCallbacks([success, error]);909 theMovieDb.common.client(910 {911 url: "person/" + options.id + "/combined_credits" + theMovieDb.common.generateQuery(options)912 },913 success,914 error915 );916 },917 getExternalIds: function (options, success, error) {918 'use strict';919 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);920 theMovieDb.common.validateCallbacks([success, error]);921 theMovieDb.common.client(922 {923 url: "person/" + options.id + "/external_ids" + theMovieDb.common.generateQuery(options)924 },925 success,926 error927 );928 },929 getImages: function (options, success, error) {930 'use strict';931 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);932 theMovieDb.common.validateCallbacks([success, error]);933 theMovieDb.common.client(934 {935 url: "person/" + options.id + "/images" + theMovieDb.common.generateQuery(options)936 },937 success,938 error939 );940 },941 getTaggedImages: function(options, sucess, error) {942 'use strict';943 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);944 theMovieDb.common.validateCallbacks([success, error]);945 theMovieDb.common.client(946 {947 url: "person/" + options.id + "/tagged_images" + theMovieDb.common.generateQuery(options)948 },949 success,950 error951 );952 },953 getChanges: function (options, success, error) {954 'use strict';955 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);956 theMovieDb.common.validateCallbacks([success, error]);957 theMovieDb.common.client(958 {959 url: "person/" + options.id + "/changes" + theMovieDb.common.generateQuery(options)960 },961 success,962 error963 );964 },965 getPopular: function (options, success, error) {966 'use strict';967 theMovieDb.common.validateRequired(arguments, 3, "", "", true);968 theMovieDb.common.validateCallbacks([success, error]);969 theMovieDb.common.client(970 {971 url: "person/popular" + theMovieDb.common.generateQuery(options)972 },973 success,974 error975 );976 },977 getLatest: function (success, error) {978 'use strict';979 theMovieDb.common.validateRequired(arguments, 2);980 theMovieDb.common.validateCallbacks([success, error]);981 theMovieDb.common.client(982 {983 url: "person/latest" + theMovieDb.common.generateQuery()984 },985 success,986 error987 );988 }989};990theMovieDb.reviews = {991 getById: function (options, success, error) {992 'use strict';993 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);994 theMovieDb.common.validateCallbacks([success, error]);995 theMovieDb.common.client(996 {997 url: "review/" + options.id + theMovieDb.common.generateQuery(options)998 },999 success,1000 error1001 );1002 }1003};1004theMovieDb.search = {1005 getMovie: function (options, success, error) {1006 'use strict';1007 theMovieDb.common.validateRequired(arguments, 3, options, ["query"]);1008 theMovieDb.common.validateCallbacks([success, error]);1009 theMovieDb.common.client(1010 {1011 url: "search/movie" + theMovieDb.common.generateQuery(options)1012 },1013 success,1014 error1015 );1016 },1017 getCollection: function (options, success, error) {1018 'use strict';1019 theMovieDb.common.validateRequired(arguments, 3, options, ["query"]);1020 theMovieDb.common.validateCallbacks([success, error]);1021 theMovieDb.common.client(1022 {1023 url: "search/collection" + theMovieDb.common.generateQuery(options)1024 },1025 success,1026 error1027 );1028 },1029 getTv: function (options, success, error) {1030 'use strict';1031 theMovieDb.common.validateRequired(arguments, 3, options, ["query"]);1032 theMovieDb.common.validateCallbacks([success, error]);1033 theMovieDb.common.client(1034 {1035 url: "search/tv" + theMovieDb.common.generateQuery(options)1036 },1037 success,1038 error1039 );1040 },1041 getPerson: function (options, success, error) {1042 'use strict';1043 theMovieDb.common.validateRequired(arguments, 3, options, ["query"]);1044 theMovieDb.common.validateCallbacks([success, error]);1045 theMovieDb.common.client(1046 {1047 url: "search/person" + theMovieDb.common.generateQuery(options)1048 },1049 success,1050 error1051 );1052 },1053 getList: function (options, success, error) {1054 'use strict';1055 theMovieDb.common.validateRequired(arguments, 3, options, ["query"]);1056 theMovieDb.common.validateCallbacks([success, error]);1057 theMovieDb.common.client(1058 {1059 url: "search/list" + theMovieDb.common.generateQuery(options)1060 },1061 success,1062 error1063 );1064 },1065 getCompany: function (options, success, error) {1066 'use strict';1067 theMovieDb.common.validateRequired(arguments, 3, options, ["query"]);1068 theMovieDb.common.validateCallbacks([success, error]);1069 theMovieDb.common.client(1070 {1071 url: "search/company" + theMovieDb.common.generateQuery(options)1072 },1073 success,1074 error1075 );1076 },1077 getKeyword: function (options, success, error) {1078 'use strict';1079 theMovieDb.common.validateRequired(arguments, 3, options, ["query"]);1080 theMovieDb.common.validateCallbacks([success, error]);1081 theMovieDb.common.client(1082 {1083 url: "search/keyword" + theMovieDb.common.generateQuery(options)1084 },1085 success,1086 error1087 );1088 }1089};1090theMovieDb.timezones = {1091 getList: function (success, error) {1092 'use strict';1093 theMovieDb.common.validateRequired(arguments, 2);1094 theMovieDb.common.validateCallbacks([success, error]);1095 theMovieDb.common.client(1096 {1097 url: "timezones/list" + theMovieDb.common.generateQuery()1098 },1099 success,1100 error1101 );1102 }1103};1104theMovieDb.tv = {1105 getById: function (options, success, error) {1106 'use strict';1107 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);1108 theMovieDb.common.validateCallbacks([success, error]);1109 theMovieDb.common.client(1110 {1111 url: "tv/" + options.id + theMovieDb.common.generateQuery(options)1112 },1113 success,1114 error1115 );1116 },1117 getSimilar: function (options, success, error) {1118 'use strict';1119 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);1120 theMovieDb.common.validateCallbacks([success, error]);1121 theMovieDb.common.client(1122 {1123 url: "tv/" + options.id + "/similar" + theMovieDb.common.generateQuery(options)1124 },1125 success,1126 error1127 );1128 },1129 getCredits: function (options, success, error) {1130 'use strict';1131 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);1132 theMovieDb.common.validateCallbacks([success, error]);1133 theMovieDb.common.client(1134 {1135 url: "tv/" + options.id + "/credits" + theMovieDb.common.generateQuery(options)1136 },1137 success,1138 error1139 );1140 },1141 getExternalIds: function (options, success, error) {1142 'use strict';1143 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);1144 theMovieDb.common.validateCallbacks([success, error]);1145 theMovieDb.common.client(1146 {1147 url: "tv/" + options.id + "/external_ids" + theMovieDb.common.generateQuery(options)1148 },1149 success,1150 error1151 );1152 },1153 getImages: function (options, success, error) {1154 'use strict';1155 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);1156 theMovieDb.common.validateCallbacks([success, error]);1157 theMovieDb.common.client(1158 {1159 url: "tv/" + options.id + "/images" + theMovieDb.common.generateQuery(options)1160 },1161 success,1162 error1163 );1164 },1165 getTranslations: function (options, success, error) {1166 'use strict';1167 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);1168 theMovieDb.common.validateCallbacks([success, error]);1169 theMovieDb.common.client(1170 {1171 url: "tv/" + options.id + "/translations" + theMovieDb.common.generateQuery(options)1172 },1173 success,1174 error1175 );1176 },1177 getVideos: function (options, success, error) {1178 'use strict';1179 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);1180 theMovieDb.common.validateCallbacks([success, error]);1181 theMovieDb.common.client(1182 {1183 url: "tv/" + options.id + "/videos" + theMovieDb.common.generateQuery(options)1184 },1185 success,1186 error1187 );1188 },1189 getOnTheAir: function (options, success, error) {1190 'use strict';1191 theMovieDb.common.validateRequired(arguments, 3, "", "", true);1192 theMovieDb.common.validateCallbacks([success, error]);1193 theMovieDb.common.client(1194 {1195 url: "tv/on_the_air" + theMovieDb.common.generateQuery(options)1196 },1197 success,1198 error1199 );1200 },1201 getAiringToday: function (options, success, error) {1202 'use strict';1203 theMovieDb.common.validateRequired(arguments, 3, "", "", true);1204 theMovieDb.common.validateCallbacks([success, error]);1205 theMovieDb.common.client(1206 {1207 url: "tv/airing_today" + theMovieDb.common.generateQuery(options)1208 },1209 success,1210 error1211 );1212 },1213 getTopRated: function (options, success, error) {1214 'use strict';1215 theMovieDb.common.validateRequired(arguments, 3, "", "", true);1216 theMovieDb.common.validateCallbacks([success, error]);1217 theMovieDb.common.client(1218 {1219 url: "tv/top_rated" + theMovieDb.common.generateQuery(options)1220 },1221 success,1222 error1223 );1224 },1225 getPopular: function (options, success, error) {1226 'use strict';1227 theMovieDb.common.validateRequired(arguments, 3, "", "", true);1228 theMovieDb.common.validateCallbacks([success, error]);1229 theMovieDb.common.client(1230 {1231 url: "tv/popular" + theMovieDb.common.generateQuery(options)1232 },1233 success,1234 error1235 );1236 }1237};1238theMovieDb.tvSeasons = {1239 getById: function (options, success, error) {1240 'use strict';1241 theMovieDb.common.validateRequired(arguments, 3, options, ["season_number", "id"]);1242 theMovieDb.common.validateCallbacks([success, error]);1243 theMovieDb.common.client(1244 {1245 url: "tv/" + options.id + "/season/" + options.season_number + theMovieDb.common.generateQuery(options)1246 },1247 success,1248 error1249 );1250 },1251 getCredits: function (options, success, error) {1252 'use strict';1253 theMovieDb.common.validateRequired(arguments, 3, options, ["season_number", "id"]);1254 theMovieDb.common.validateCallbacks([success, error]);1255 theMovieDb.common.client(1256 {1257 url: "tv/" + options.id + "/season/" + options.season_number + "/credits" + theMovieDb.common.generateQuery(options)1258 },1259 success,1260 error1261 );1262 },1263 getExternalIds: function (options, success, error) {1264 'use strict';1265 theMovieDb.common.validateRequired(arguments, 3, options, ["season_number", "id"]);1266 theMovieDb.common.validateCallbacks([success, error]);1267 theMovieDb.common.client(1268 {1269 url: "tv/" + options.id + "/season/" + options.season_number + "/external_ids" + theMovieDb.common.generateQuery(options)1270 },1271 success,1272 error1273 );1274 },1275 getImages: function (options, success, error) {1276 'use strict';1277 theMovieDb.common.validateRequired(arguments, 3, options, ["season_number", "id"]);1278 theMovieDb.common.validateCallbacks([success, error]);1279 theMovieDb.common.client(1280 {1281 url: "tv/" + options.id + "/season/" + options.season_number + "/images" + theMovieDb.common.generateQuery(options)1282 },1283 success,1284 error1285 );1286 }1287};1288theMovieDb.tvEpisodes = {1289 getById: function (options, success, error) {1290 'use strict';1291 theMovieDb.common.validateRequired(arguments, 3, options, ["episode_number", "season_number", "id"]);1292 theMovieDb.common.validateCallbacks([success, error]);1293 theMovieDb.common.client(1294 {1295 url: "tv/" + options.id + "/season/" + options.season_number + "/episode/" + options.episode_number + theMovieDb.common.generateQuery(options)1296 },1297 success,1298 error1299 );1300 },1301 getCredits: function (options, success, error) {1302 'use strict';1303 theMovieDb.common.validateRequired(arguments, 3, options, ["episode_number", "season_number", "id"]);1304 theMovieDb.common.validateCallbacks([success, error]);1305 theMovieDb.common.client(1306 {1307 url: "tv/" + options.id + "/season/" + options.season_number + "/episode/" + options.episode_number + "/credits" + theMovieDb.common.generateQuery(options)1308 },1309 success,1310 error1311 );1312 },1313 getExternalIds: function (options, success, error) {1314 'use strict';1315 theMovieDb.common.validateRequired(arguments, 3, options, ["episode_number", "season_number", "id"]);1316 theMovieDb.common.validateCallbacks([success, error]);1317 theMovieDb.common.client(1318 {1319 url: "tv/" + options.id + "/season/" + options.season_number + "/episode/" + options.episode_number + "/external_ids" + theMovieDb.common.generateQuery(options)1320 },1321 success,1322 error1323 );1324 },1325 getImages: function (options, success, error) {1326 'use strict';1327 theMovieDb.common.validateRequired(arguments, 3, options, ["episode_number", "season_number", "id"]);1328 theMovieDb.common.validateCallbacks([success, error]);1329 theMovieDb.common.client(1330 {1331 url: "tv/" + options.id + "/season/" + options.season_number + "/episode/" + options.episode_number + "/images" + theMovieDb.common.generateQuery(options)1332 },1333 success,1334 error1335 );1336 }...
e2e.test.js
Source:e2e.test.js
...148 client.pause(10000).resizeWindow(1024, 636);149 },150 // The app defaults to completed version151 "completed": function(client) {152 client.url("http://localhost:3000").waitForElementVisible(".ui.segment", 5000);153 assertFullyFunctional(client);154 },155 // Matches state of chat app at end of last chapter156 "./App.js": function(client) {157 switchApp("./App", client)158 client.url("http://localhost:3000").waitForElementVisible(".ui.segment", 5000);159 assertCanCreateAndDeleteMessagesNoInitialState(client)160 },161 // All we do is switch to using create store162 "./complete/App-1.js": function(client) {163 switchApp('./complete/App-1', client)164 client.url("http://localhost:3000").waitForElementVisible(".ui.segment", 5000);165 assertCanCreateAndDeleteMessagesNoInitialState(client)166 },167 // Surface doesn't change, we move to using message _objects_ with uuids168 // we also add timestamps169 "./complete/App-2.js": function(client) {170 switchApp("./complete/App-2", client)171 client.url("http://localhost:3000").waitForElementVisible(".ui.segment", 5000);172 assertCanCreateAndDeleteMessagesNoInitialState(client)173 client.174 expect.element('div.ui.comments > div:nth-child(1)').text.to.match(/@\d{13}/)175 },176 // Now we initialize the state with an object177 "./complete/App-3.js": function(client) {178 switchApp("./complete/App-3", client)179 client.url("http://localhost:3000").waitForElementVisible(".ui.segment", 5000);180 assertInitialState(client);181 // but nothing else works182 },183 // Tabs present! But nothing else works184 "./complete/App-4.js": function(client) {185 switchApp("./complete/App-4", client)186 client.url("http://localhost:3000").waitForElementVisible(".ui.segment", 5000);187 assertInitialState(client);188 assertTabularMenu(client);189 },190 // Now we can add messages to the first thread191 "./complete/App-5.js": function(client) {192 switchApp("./complete/App-5", client)193 client.url("http://localhost:3000").waitForElementVisible(".ui.segment", 5000);194 assertInitialState(client);195 assertCanCreateMessagesWithInitialState(client);196 },197 // Now we can add and delete messages from the first thread198 "./complete/App-6.js": function(client) {199 switchApp("./complete/App-6", client)200 client.url("http://localhost:3000").waitForElementVisible(".ui.segment", 5000);201 assertInitialState(client);202 assertCanCreateAndDeleteMessagesWithInitialState(client);203 },204 // Now we can switch between threads and add and delete messages from them!!!205 "./complete/App-7.js": function(client) {206 switchApp("./complete/App-7", client)207 client.url("http://localhost:3000").waitForElementVisible(".ui.segment", 5000);208 assertInitialState(client);209 assertFullyFunctional(client, true);210 },211 // Internal refactor212 "./complete/App-8.js": function(client) {213 switchApp("./complete/App-8", client)214 client.url("http://localhost:3000").waitForElementVisible(".ui.segment", 5000);215 assertInitialState(client);216 assertFullyFunctional(client, true);217 },218 // Deletes don't work because we're using an incomplete messagesReducer()219 "./complete/App-9.js": function(client) {220 switchApp("./complete/App-9", client)221 client.url("http://localhost:3000").waitForElementVisible(".ui.segment", 5000);222 assertInitialState(client);223 assertCanCreateMessagesWithInitialState(client, true);224 },225 // Internal refactor226 "./complete/App-10.js": function(client) {227 switchApp("./complete/App-10", client)228 client.url("http://localhost:3000").waitForElementVisible(".ui.segment", 5000);229 assertInitialState(client);230 assertFullyFunctional(client, true);231 },232 // Works except no initial state233 "./complete/App-11.js": function(client) {234 switchApp("./complete/App-11", client)235 client.url("http://localhost:3000").waitForElementVisible(".ui.segment", 5000);236 assertFullyFunctional(client);237 },238 // All changes under the hood, works239 "./complete/App-12.js": function(client) {240 switchApp("./complete/App-12", client)241 client.url("http://localhost:3000").waitForElementVisible(".ui.segment", 5000);242 assertFullyFunctional(client);243 },244 // All changes under the hood, works245 "./complete/App-13.js": function(client) {246 switchApp("./complete/App-13", client)247 client.url("http://localhost:3000").waitForElementVisible(".ui.segment", 5000);248 assertFullyFunctional(client);249 },250 // Breaks, tabs work251 "./complete/App-14.js": function(client) {252 switchApp("./complete/App-14", client)253 client.url("http://localhost:3000").waitForElementVisible(".ui.segment", 5000);254 assertWorkingTabularMenu(client);255 },256 // Back257 "./complete/App-15.js": function(client) {258 switchApp("./complete/App-15", client)259 client.url("http://localhost:3000").waitForElementVisible(".ui.segment", 5000);260 assertFullyFunctional(client);261 },262 "./App-16.js": function(client) {263 switchApp("./complete/App-16", client)264 client.url("http://localhost:3000").waitForElementVisible(".ui.segment", 5000);265 assertFullyFunctional(client);266 },267 "./App-17.js": function(client) {268 switchApp("./complete/App-17", client)269 client.url("http://localhost:3000").waitForElementVisible(".ui.segment", 5000);270 assertFullyFunctional(client);271 },272 after: function(client) {273 switchApp('./complete/App-17', client)274 client.end();275 }...
paphos-service.js
Source:paphos-service.js
1'use strict';2var async = require('async'),3 request = require('request');4var subscriptionConfig = {5 "method": "api/services/subscribe",6 "protocol": "http"7};8function BaseService(app, collection) {9 this.app = app;10 this.client = {};11 this.collection = collection;12 this.defaultServiceData = ['title', 'name', 'moduleUrl', 'apiUrl'];13 this.defaultClientData = ['name', 'clientUrl'];14 this.statusNames = {15 0: "Unsubscribed",16 1: "Subscribed"17 };18 console.log("Initialize new base service");19 try {20 this.db = this.app.db;21 } catch (err) {22 this.app.log.error(err);23 next(err);24 }25}26BaseService.prototype.CheckStack = function (next) {27 var uncheckedServicesList = this.db[this.collection].find({status: 0});28 if (!uncheckedServicesList.length) return next();29 var self = this;30 var checkList = uncheckedServicesList.map((record) => {31 return new Promise(function (resolve, reject) {32 self.Serve(record, reject);33 });34 });35 Promise.all(checkList)36 .then(function (resp) {37 console.log(resp);38 next();39 })40 .catch(next);41};42BaseService.prototype.Call = function (clientData, next) {43 var self = this;44 async.auto({45 validate: next => {46 self.Validate(clientData, next);47 },48 saveClient: ['validate', (next, result) => {49 self.AddClient(result.validate, next);50 }]51 },52 err => {53 if (err) {54 console.error(err);55 return next(err);56 }57 console.info("Successfully connected with client ID - " + clientData.clientUrl);58 next();59 });60}61BaseService.prototype.Ping = function (clientUrl, next) {62 var record = this.db[this.collection].findOne({clientUrl: clientUrl});63 if (!record) return next("There are no subscriber with ID: " + clientUrl);64 if (record.status === 0) return next("Subscriber with ID: " + clientUrl + " is not subscribed. Please make a new call to the service.");65 next(null, record);66}67BaseService.prototype.Serve = function (clientData, next) {68 var self = this,69 config = this.app.config;70 async.auto({71 send: function (next) {72 var openPort = config.port !== 80 ? ":" + config.port : "",73 protocolMatcher = /(http|https|tcp):\/\//,74 protocol = config.url.match(protocolMatcher).length ? config.url.match(protocolMatcher)[0] : "",75 urlMatch = new RegExp('/(\)/'),76 splitter = function (slice, index) {77 return index == 0 ? slice + openPort : slice78 },79 moduleUrl = protocol + config.url.replace(protocolMatcher, "").split('/').map(splitter).join('/'),80 apiUrl = protocol + config.apiUrl.replace(protocolMatcher, "").split('/').map(splitter).join('/'),81 sendData = {82 moduleUrl: moduleUrl,83 apiUrl: apiUrl,84 name: config.serviceData.name,85 title: config.serviceData.title86 };87 console.log(sendData);88 request89 .post({90 url: subscriptionConfig.protocol + "://" + clientData.clientUrl + "/" + subscriptionConfig.method,91 form: sendData92 },93 function (err, response, body) {94 if (err || response.statusCode !== 200) {95 err = body || "An error occured when trying to send post req to: " + clientData.clientUrl;96 console.error(err);97 return next(err);98 }99 console.info("Successfully subscribe client.");100 next();101 });102 next();103 },104 updateRecord: ['send', function (next) {105 var find = {clientUrl: clientData.clientUrl},106 dataToUpdate = {107 status: 1108 },109 options = {110 multi: false,111 upsert: false112 };113 var errorMessage, updated;114 try {115 updated = self.db[self.collection].update(find, dataToUpdate, options);116 } catch (err) {117 errorMessage = err;118 } finally {119 if (errorMessage !== undefined || updated.updated !== 1) {120 errorMessage = errorMessage || "There are error happend when trying to update DB record: " + JSON.stringify(clientData);121 console.error(errorMessage);122 return next(errorMessage);123 }124 console.info("Subscriber " + clientData.clientUrl + " was succesfully subscribed.");125 next();126 }127 }]128 });129 next();130}131BaseService.prototype.AddClient = function (clientData, next) {132 var self = this;133 if (!clientData || !clientData.clientUrl) {134 var err = "There no clientUrl in request: " + JSON.stringify(clientData);135 this.app.log.error(err);136 return next(err);137 }138 async.auto({139 // check if record is not in the DB140 recordCheck: function (next) {141 var record = self.db[self.collection].findOne({clientUrl: clientData.clientUrl});142 if (record && record.status === 1) {143 var message = "Subscriber is in DB. No need to add it.";144 console.error(message);145 return next(message);146 }147 record = record || clientData;148 next(null, record);149 },150 // insert record to the DB? or if it already in DB - send request to subscriber151 insert: ['recordCheck', function (next, record) {152 record = record.recordCheck;153 // check if subscriber is in DB, and if it is - send request to him154 if (record.status !== undefined && record.status === 0) return next(null, record);155 record.status = 0;156 try {157 self.db[self.collection].save(record);158 } catch (err) {159 console.error("Error when trying to insert to DB: " + err);160 return next(err);161 }162 next(null, record);163 }],164 // send request to subscriber165 serve: ['insert', function (next, record) {166 self.Serve(record.insert, next);167 }]168 },169 function (err) {170 if (err) {171 return next(err);172 }173 next();174 });175 next();176}177BaseService.prototype.Validate = function (clientData, next) {178 var self = this, clientObjectKeys = Object.keys(clientData);179 var results = clientObjectKeys.filter(key => {180 return ~self.defaultClientData.indexOf(key);181 });182 if (this.defaultClientData.length !== results.length) return next("Please provide mandatory fields! They are: " + this.defaultClientData.join(', '));183 var protocolChk = new RegExp("/~http/", "gi");184 if (!protocolChk.test(results.clientUrl)) {185 results.clientUrl = "http://" + results.clientUrl;186 }187 var resultingData = {};188 results.forEach(param => {189 resultingData[param] = clientData[param];190 });191 next(null, resultingData);192}...
paper-attributes.js
Source:paper-attributes.js
...11 url = e2eHelpers.staticUrl('/demo/paper/index.html');12 client = e2eHelpers.client(done);13 });14 it('should be visible', function(done) {15 client.url(url)16 .waitForExist('#paper .joint-type-basic-path')17 .then(function(exists) {18 expect(exists).to.equal(true);19 done();20 });21 });22 describe('Attributes', function() {23 it('origin x should be changable', function(done) {24 client.url(url)25 .changeRange('#ox', 60/* orig range */, 80/* new range */)26 .then(function(data) {27 expect(data.transform).to.equal('translate(101,0)');28 done();29 });30 });31 it('origin y should be changable', function(done) {32 client.url(url)33 .changeRange('#oy', 60/* orig range */, 80/* new range */)34 .then(function(data) {35 expect(data.transform).to.equal('translate(0,101)');36 done();37 });38 });39 it('scale x should be changable', function(done) {40 client.url(url)41 .changeRange('#sx', 35/* orig range */, 80/* new range */)42 .then(function(data) {43 expect(data.transform).to.equal('scale(2.3,1)');44 done();45 });46 });47 it('scale y should be changable', function(done) {48 client.url(url)49 .changeRange('#sy', 35/* orig range */, 80/* new range */)50 .then(function(data) {51 expect(data.transform).to.equal('scale(1,2.3)');52 done();53 });54 });55 it('width should be changable', function(done) {56 client.url(url)57 .changeRange('#width', 55/* orig range */, 80/* new range */)58 .then(function(data) {59 expect(data.width).to.equal('928');60 done();61 });62 });63 it('height should be changable', function(done) {64 client.url(url)65 .changeRange('#height', 35/* orig range */, 80/* new range */)66 .then(function(data) {67 expect(data.height).to.equal('928');68 done();69 });70 });71 });72 describe('Fit to content', function() {73 it('padding should be changable', function(done) {74 client.url(url)75 .changeRange('#ftc-padding', 10/* orig range */, 80/* new range */)76 .then(function(data) {77 expect(data.transform).to.equal('translate(0,25)');78 expect(data.width).to.equal('625');79 expect(data.height).to.equal('440');80 done();81 });82 });83 it('grid width should be changable', function(done) {84 client.url(url)85 .changeRange('#ftc-grid-width', 10/* orig range */, 80/* new range */)86 .then(function(data) {87 expect(data.transform).to.equal('translate(-75,-50)');88 expect(data.width).to.equal('525');89 expect(data.height).to.equal('290');90 done();91 });92 });93 it('grid height should be changable', function(done) {94 client.url(url)95 .changeRange('#ftc-grid-height', 10/* orig range */, 80/* new range */)96 .then(function(data) {97 expect(data.transform).to.equal('translate(-75,0)');98 expect(data.width).to.equal('475');99 expect(data.height).to.equal('375');100 done();101 });102 });103 });104 describe('Scale content to fit', function() {105 it('padding should be changable', function(done) {106 client.url(url)107 .changeRange('#stf-padding', 10/* orig range */, 50/* new range */)108 .then(function(data) {109 expect(data.transform).not.to.equal(null);110 done();111 });112 });113 });...
test.js
Source:test.js
1var supertest = require('supertest'),2 config = require('../config.json'),3 filedb = require('diskdb'),4 express = require('express'),5 bodyParser = require('body-parser'),6 request = require('request'),7 http_post = require('http-post'),8 should = require('should');9var testclientPort = 8090,10 clientHost = "127.0.0.1:" + config.port,11 testClientUrl = '127.0.0.1:' + testclientPort,12 server = supertest.agent(clientHost),13 app = express(), serverCall;14var collection = config.db.collection,15 db = filedb.connect(config.db.dir, [collection]);16var testPostForm = require('../paphos-discover.json');17describe("Tests", function () {18 var clientApp;19 function removeTestSample(done) {20 db[collection].remove();21 //db[collection].remove({clientUrl: clientHost}, true);22 //db[collection].remove({clientUrl: testClientUrl}, true);23 done();24 }25 before(function (done) {26 db[collection].remove();27 clientApp = require('../app');28 app.use(bodyParser.urlencoded({extended: false}));29 app.use(bodyParser.json());30 serverCall = app.listen(testclientPort);31 console.info("*** Start test server ***");32 //removeTestSample(done);33 done();34 });35 after(function (done) {36 clientApp.server.close();37 serverCall.close();38 console.info("*** Stop test server ***");39 //removeTestSample(done);40 done();41 });42 // REST tests43 describe("REST tests", function () {44 this.timeout(60000);45 it("should return default api page", function (done) {46 server47 .get('/ok')48 .expect("Content-type", /json/)49 .expect(200)50 .end(function (err, res) {51 if (err) throw err;52 should(res.body.success).equal(true);53 done();54 });55 });56 it("should check service call", function (done) {57 app.post('/api/services/subscribe', function (req, res) {58 should(req.status).ok();59 should(req.body.error).not.equal(true);60 should(req.body).have.property('name', testPostForm.name);61 should(req.body).have.property('clientUrl', testPostForm.clientUrl);62 should(req.body).have.property('status');63 should(+req.body.status).equal(0);64 done();65 });66 http_post('http://' + clientHost + '/api/subscription/subscribe', testPostForm);67 });68 var sendTestPostData = {69 name: "testSubscriber",70 clientUrl: clientHost71 };72 it("should return success message for insertion in DB", function (done) {73 server74 .post('/api/subscription/subscribe')75 .send(sendTestPostData)76 .end(function (err, res) {77 if (err) throw err;78 should(res.status).ok();79 should(res.body).have.property('msg');80 should(res.statusCode).equal(200);81 done();82 });83 });84 it("should return subscriber data", function (done) {85 server86 .get('/api/subscription/ping?clientUrl=' + clientHost)87 .end(function (err, res) {88 if (err) throw err;89console.info(res.statusCode)90 should(res.status).ok();91 should(res.body).have.property('msg');92 should(res.statusCode).equal(200);93 should(res.body.msg.clientUrl).equal(clientHost);94 should(res.body.msg.status).equal(1);95 done();96 });97 })98 it("should return ERROR message for duplicate insertion in DB", function (done) {99 server100 .post('/api/subscription/subscribe')101 .send(sendTestPostData)102 .end(function (err, res) {103 if (err) throw err;104 should(res.status).not.ok();105 should(res.body).have.property('code');106 should(res.body).have.property('message');107 should(res.statusCode).equal(500);108 done();109 });110 });111 });...
options.js
Source:options.js
1import { getSettings, setSettings } from "./settings";2function isDefaultClient() {3 return document.getElementById("default-client").checked;4}5function setDefaultClient(defaultClient) {6 document.getElementById("default-client").checked = defaultClient;7}8function isInitialDefaultClient() {9 return document.getElementById("default-client").dataset.initial === "true";10}11function setInitialDefaultClient(defaultClient) {12 document.getElementById("default-client").dataset.initial = defaultClient;13}14function getCustomClientUrl() {15 return document.getElementById("custom-client-url").value;16}17function setCustomClientUrl(customClientUrl) {18 document.getElementById("custom-client-url").value = customClientUrl;19}20function getInitialCustomClientUrl() {21 return document.getElementById("custom-client-url").dataset.initial;22}23function setInitialCustomClientUrl(customClientUrl) {24 document.getElementById("custom-client-url").dataset.initial = customClientUrl;25}26function showCustomClientUrl(visible) {27 document.getElementById("custom-client-url-section").style.display = visible ? "block" : "none";28}29function enableSaveButton(enabled) {30 document.getElementById("save").disabled = !enabled;31}32function update() {33 showCustomClientUrl(!isDefaultClient());34 enableSaveButton(isDefaultClient() !== isInitialDefaultClient()35 || getCustomClientUrl() !== getInitialCustomClientUrl());36}37async function initUI() {38 const {defaultClient, customClientUrl} = await getSettings();39 setInitialDefaultClient(defaultClient);40 setDefaultClient(defaultClient);41 setInitialCustomClientUrl(customClientUrl);42 setCustomClientUrl(customClientUrl);43 update();44}45async function saveSettings() {46 await setSettings({47 defaultClient: isDefaultClient(),48 customClientUrl: getCustomClientUrl()49 });50 setInitialDefaultClient(isDefaultClient());51 setInitialCustomClientUrl(getCustomClientUrl());52 update();53}54document.addEventListener("DOMContentLoaded", initUI);55document.getElementById("default-client").addEventListener("click", update);56document.getElementById("custom-client-url").addEventListener("keyup", update);...
server.js
Source:server.js
1var common = require("./commonscripts.js");2var Client = require('node-rest-client').Client;3var client = new Client();4var express = require('express');5var app = express();6var url=common.baseQueryUrl;7app.use(express.static('/usr/local/spendanalytics/WebServices/public'));8require('./listCustomers')(app,client,url);9require('./listExpensesByCategoryWeekly')(app,client,url);10require('./listExpensesByCategoryMonthly')(app,client,url);11require('./listExpensesByCategoryYearly')(app,client,url);12require('./listExpensesByCategoryQuarterly')(app,client,url);13require('./getMonthlyIncomeExpenses')(app,client,url);14require('./getYearlyIncomeExpenses')(app,client,url);15//require('./authenticateUser')(app,client,url);16require('./getAllYearIncomeExpenses')(app,client,url);17require('./getDaywiseExpensesforMonth')(app,client,url);18require('./getAllMonthExpenses')(app,client,url);19require('./listtransactiondata')(app,client,url);20require('./listExpensesByWeek')(app,client,url);21require('./listCustomerDetails')(app,client,url);22require('./listCategorySubcategoryExpense')(app,client,url);23require('./AvgSpendCategory')(app,client,url);24require('./addTransactions')(app,client,url);25require('./updateTransaction')(app,client,url);26require('./updateSubcategory')(app,client,url);27var server = app.listen(8081, function () {28 var host = server.address().address29 var port = server.address().port30 console.log("SpendAnalytics app listening at http://%s:%s", host, port)...
settings.js
Source:settings.js
1import browser from 'webextension-polyfill';2export const DEFAULT_CLIENT_URL = "https://client.moera.org/releases/latest";3export async function getSettings() {4 let {defaultClient, customClientUrl} = await browser.storage.local.get(["defaultClient", "customClientUrl"]);5 defaultClient = defaultClient != null ? defaultClient : true;6 customClientUrl = customClientUrl ? customClientUrl : DEFAULT_CLIENT_URL;7 return {defaultClient, customClientUrl};8}9export async function setSettings({defaultClient, customClientUrl}) {10 await browser.storage.local.set({defaultClient, customClientUrl});11}12export async function getClientUrl() {13 const {defaultClient, customClientUrl} = await browser.storage.local.get(["defaultClient", "customClientUrl"]);14 return defaultClient == null || defaultClient ? DEFAULT_CLIENT_URL : customClientUrl;...
Using AI Code Generation
1client.source(function(err, res) {2 console.log(res);3});4client.execute("mobile: swipe", {direction: 'down'}, function(err, res) {5 console.log(res);6});7client.execute("mobile: scroll", {direction: 'down'}, function(err, res) {8 console.log(res);9});10client.execute("mobile: scroll", {direction: 'down', element: 'elementId'}, function(err, res) {11 console.log(res);12});13client.execute("mobile: scroll", {direction: 'down', element: 'elementId', toVisible: true}, function(err, res) {14 console.log(res);15});16client.execute("mobile: scroll", {direction: 'down', element: 'elementId', toVisible: true, maxSwipes: 3}, function(err, res) {17 console.log(res);18});19client.execute("mobile: scroll", {direction: 'down', element: 'elementId', toVisible: true, maxSwipes: 3, timeout: 1000}, function(err, res) {20 console.log(res);21});22client.execute("mobile: scroll", {direction: 'down', element: 'elementId', toVisible: true, maxSwipes: 3, timeout: 1000, strategy: 'name'}, function(err, res) {23 console.log(res);24});25client.execute("mobile: scroll", {direction: 'down', element: 'elementId', toVisible: true, maxSwipes: 3, timeout: 1000, strategy: 'name', name: 'elementName'}, function(err, res) {26 console.log(res);27});
Using AI Code Generation
1client.navigate().back();2client.navigate().forward();3client.navigate().refresh();4client.getTitle().then(function(title) {5});6client.getPageSource().then(function(source) {7});8client.getWindowHandle().then(function(handle) {9});10client.getWindowHandles().then(function(handles) {11});12client.switchToWindow('windowHandle');13client.switchToFrame('frameHandle');14client.switchToParentFrame();15client.getCurrentDeviceActivity().then(function(activity) {16});17client.startDeviceActivity('appPackage', 'appActivity');18client.getDeviceTime().then(function(time) {19});20client.setDeviceTime('time');21client.hideKeyboard();22client.openNotifications();23client.getOrientation().then(function(orientation) {24});25client.setOrientation('orientation');26client.getGeoLocation().then(function(location) {
Using AI Code Generation
1client.getTitle().then(function(title) {2 console.log("Title is: " + title);3});4client.setValue('#lst-ib', 'WebdriverIO')5client.click('#tsbb')6client.pause(10000)7client.end();8Test Suites: 1 passed, 1 total (100% completed)9Tests: 1 passed, 1 total (100% completed)
Using AI Code Generation
1describe('Test', function() {2 it('should open a website', function() {3 .getTitle().then(function(title) {4 console.log('Title was: ' + title);5 })6 .end();7 });8});9describe('Test', function() {10 it('should open a website', function() {11 .getTitle().then(function(title) {12 console.log('Title was: ' + title);13 })14 .end();15 });16});17exports.config = {
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!!