How to use done method in storybook-root

Best JavaScript code snippet using storybook-root

test.js

Source:test.js Github

copy

Full Screen

...41 }42 })43 }44 }45 done();46}47describe('Ajax', function() {48 var dogName="dog"+Math.floor(Math.random()*10000);49 var dogData=JSON.stringify({type:"dog",name:dogName});50 var dogURI='https://api.usergrid.com/yourorgname/sandbox/dogs'51 it('should POST to a URI',function(done){52 Ajax.post(dogURI, dogData).then(function(err, data){53 assert(!err, err);54 done();55 })56 })57 it('should GET a URI',function(done){58 Ajax.get(dogURI+'/'+dogName).then(function(err, data){59 assert(!err, err);60 done();61 })62 })63 it('should PUT to a URI',function(done){64 Ajax.put(dogURI+'/'+dogName, {"favorite":true}).then(function(err, data){65 assert(!err, err);66 done();67 })68 })69 it('should DELETE a URI',function(done){70 Ajax.delete(dogURI+'/'+dogName, dogData).then(function(err, data){71 assert(!err, err);72 done();73 })74 })75});76describe('UsergridError', function() {77 var errorResponse={78 "error":"service_resource_not_found",79 "timestamp":1392067967144,80 "duration":0,81 "exception":"org.usergrid.services.exceptions.ServiceResourceNotFoundException",82 "error_description":"Service resource not found"83 };84 it('should unmarshal a response from Usergrid into a proper Javascript error',function(done){85 var error = UsergridError.fromResponse(errorResponse);86 assert(error.name===errorResponse.error, "Error name not set correctly");87 assert(error.message===errorResponse.error_description, "Error message not set correctly");88 done();89 });90});91describe('Usergrid', function(){92 describe('SDK Version', function(){93 it('should contain a minimum SDK version',function(){94 var parts=Usergrid.VERSION.split('.').map(function(i){return i.replace(/^0+/,'')}).map(function(i){return parseInt(i)});95 assert(parts[1]>=10, "expected minor version >=10");96 assert(parts[1]>10||parts[2]>=8, "expected minimum version >=8");97 });98 });99 describe('Usergrid Request/Response', function() {100 var dogName="dog"+Math.floor(Math.random()*10000);101 var dogData=JSON.stringify({type:"dog",name:dogName});102 var dogURI='https://api.usergrid.com/yourorgname/sandbox/dogs'103 it('should POST to a URI',function(done){104 var req=new Usergrid.Request("POST", dogURI, {}, dogData, function(err, response){105 console.error(err, response);106 assert(!err, err);107 assert(response instanceof Usergrid.Response, "Response is not and instance of Usergrid.Response");108 done();109 })110 })111 it('should GET a URI',function(done){112 var req=new Usergrid.Request("GET", dogURI+'/'+dogName, {}, null, function(err, response){113 assert(!err, err);114 assert(response instanceof Usergrid.Response, "Response is not and instance of Usergrid.Response");115 done();116 })117 })118 it('should GET an array of entity data from the Usergrid.Response object',function(done){119 var req=new Usergrid.Request("GET", dogURI, {}, null, function(err, response){120 assert(!err, err);121 assert(response instanceof Usergrid.Response, "Response is not and instance of Usergrid.Response");122 var entities=response.getEntities();123 assert(entities && entities.length, "Nothing was returned")124 done();125 })126 })127 it('should GET entity data from the Usergrid.Response object',function(done){128 var req=new Usergrid.Request("GET", dogURI+'/'+dogName, {}, null, function(err, response){129 var entity=response.getEntity();130 assert(!err, err);131 assert(response instanceof Usergrid.Response, "Response is not and instance of Usergrid.Response");132 assert(entity, "Nothing was returned")133 done();134 })135 })136 it('should PUT to a URI',function(done){137 var req=new Usergrid.Request("PUT", dogURI+'/'+dogName, {}, {favorite:true}, function(err, response){138 assert(!err, err);139 assert(response instanceof Usergrid.Response, "Response is not and instance of Usergrid.Response");140 done();141 })142 })143 it('should DELETE a URI',function(done){144 var req=new Usergrid.Request("DELETE", dogURI+'/'+dogName, {}, null, function(err, response){145 assert(!err, err);146 assert(response instanceof Usergrid.Response, "Response is not and instance of Usergrid.Response");147 done();148 })149 })150 it('should NOT allow an invalid method',function(done){151 try{152 var req=new Usergrid.Request("INVALID", dogURI+'/'+dogName, {}, null, function(err, response){153 assert(true, "Should have thrown an UsergridInvalidHTTPMethodError");154 done();155 })156 }catch(e){157 assert(e instanceof UsergridInvalidHTTPMethodError, "Error is not and instance of UsergridInvalidHTTPMethodError");158 done()159 }160 })161 it('should NOT allow an invalid URI',function(done){162 try{163 var req=new Usergrid.Request("GET", "://apigee.com", {}, null, function(err, response){164 assert(true, "Should have thrown an UsergridInvalidURIError");165 done();166 })167 }catch(e){168 assert(e instanceof UsergridInvalidURIError, "Error is not and instance of UsergridInvalidURIError");169 done()170 }171 })172 it('should return a UsergridError object on an invalid URI',function(done){173 var req=new Usergrid.Request("GET", dogURI+'/'+dogName+'zzzzz', {}, null, function(err, response){174 assert(err, "Should have returned an error");175 assert(response instanceof Usergrid.Response, "Response is not and instance of Usergrid.Response");176 assert(err instanceof UsergridError, "Error is not and instance of UsergridError");177 done();178 })179 })180 });181 describe('Usergrid Client', function() {182 var client = getClient();183 describe('Usergrid CRUD request', function() {184 before(function(done) {185 this.timeout(10000);186 //Make sure our dog doesn't already exist187 client.request({188 method: 'DELETE',189 endpoint: 'users/fred'190 }, function(err, data) {191 done();192 });193 });194 var options = {195 method: 'GET',196 endpoint: 'users'197 };198 it('should persist default query parameters', function(done) {199 //create new client with default params200 var client=new Usergrid.Client({201 orgName: 'yourorgname',202 appName: 'sandbox',203 logging: false, //optional - turn on logging, off by default204 buildCurl: true, //optional - turn on curl commands, off by default205 qs:{206 test1:'test1',207 test2:'test2'208 }209 });210 var default_qs=client.getObject('default_qs');211 assert(default_qs.test1==='test1', "the default query parameters were not persisted");212 assert(default_qs.test2==='test2', "the default query parameters were not persisted");213 client.request({214 method: 'GET',215 endpoint: 'users'216 }, function(err, data) {217 assert(data.params.test2[0]==='test2', "the default query parameters were not sent to the backend");218 assert(data.params.test1[0]==='test1', "the default query parameters were not sent to the backend");219 done();220 });221 });222 it('should CREATE a new user', function(done) {223 client.request({224 method: 'POST',225 endpoint: 'users',226 body: {227 username: 'fred',228 password: 'secret'229 }230 }, function(err, data) {231 usergridTestHarness(err, data, done, [232 function(err, data) {233 assert(!err)234 }235 ]);236 });237 });238 it('should RETRIEVE an existing user', function(done) {239 client.request({240 method: 'GET',241 endpoint: 'users/fred',242 body: {}243 }, function(err, data) {244 usergridTestHarness(err, data, done, [245 function(err, data) {246 assert(true)247 }248 ]);249 });250 });251 it('should UPDATE an existing user', function(done) {252 client.request({253 method: 'PUT',254 endpoint: 'users/fred',255 body: {256 newkey: 'newvalue'257 }258 }, function(err, data) {259 usergridTestHarness(err, data, done, [260 function(err, data) {261 assert(true)262 }263 ]);264 });265 });266 it('should DELETE the user from the database', function(done) {267 client.request({268 method: 'DELETE',269 endpoint: 'users/fred'270 }, function(err, data) {271 usergridTestHarness(err, data, done, [272 function(err, data) {273 assert(true)274 }275 ]);276 });277 });278 });279 describe('Usergrid REST', function() {280 it('should return a list of users', function(done) {281 client.request({282 method: 'GET',283 endpoint: 'users'284 }, function(err, data) {285 usergridTestHarness(err, data, done, [286 function(err, data) {287 assert(data.entities.length>=0, "Request should return at least one user");288 }289 ]);290 });291 });292 it('should return no entities when an endpoint does not exist', function(done) {293 client.request({294 method: 'GET',295 endpoint: 'nonexistantendpoint'296 }, function(err, data) {297 usergridTestHarness(err, data, done, [298 function(err, data) {299 assert(data.entities.length===0, "Request should return no entities");300 }301 ]);302 });303 });304 });305 describe('Usergrid convenience methods', function(){306 before(function(){ client.logout();});307 it('createEntity',function(done){308 client.createEntity({type:'dog',name:'createEntityTestDog'}, function(err, response, dog){309 console.warn(err, response, dog);310 assert(!err, "createEntity returned an error")311 assert(dog, "createEntity did not return a dog")312 assert(dog.get("name")==='createEntityTestDog', "The dog's name is not 'createEntityTestDog'")313 done();314 })315 })316 it('createEntity - existing entity',function(done){317 client.createEntity({type:'dog',name:'createEntityTestDog'}, function(err, response, dog){318 try{319 assert(err, "createEntity should return an error")320 }catch(e){321 assert(true, "trying to create an entity that already exists throws an error");322 }finally{323 done();324 }325 });326 })327 var testGroup;328 it('createGroup',function(done){329 client.createGroup({path:'dogLovers'},function(err, response, group){330 try{331 assert(!err, "createGroup returned an error")332 }catch(e){333 assert(true, "trying to create a group that already exists throws an error");334 }finally{335 done();336 }337 /*assert(!err, "createGroup returned an error: "+err);338 assert(group, "createGroup did not return a group");339 assert(group instanceof Usergrid.Group, "createGroup did not return a Usergrid.Group");340 testGroup=group;341 done();*/342 })343 done();344 })345 it('buildAssetURL',function(done){346 var assetURL='https://api.usergrid.com/yourorgname/sandbox/assets/00000000-0000-0000-000000000000/data';347 assert(assetURL===client.buildAssetURL('00000000-0000-0000-000000000000'), "buildAssetURL doesn't work")348 done();349 })350 var dogEntity;351 it('getEntity',function(done){352 client.getEntity({type:'dog',name:'createEntityTestDog'}, function(err, response, dog){353 assert(!err, "createEntity returned an error")354 assert(dog, "createEntity returned a dog")355 assert(dog.get("uuid")!==null, "The dog's UUID was not returned")356 dogEntity=dog;357 done();358 })359 })360 it('restoreEntity',function(done){361 var serializedDog=dogEntity.serialize();362 var dog=client.restoreEntity(serializedDog);363 assert(dog, "restoreEntity did not return a dog")364 assert(dog.get("uuid")===dogEntity.get("uuid"), "The dog's UUID was not the same as the serialized dog")365 assert(dog.get("type")===dogEntity.get("type"), "The dog's type was not the same as the serialized dog")366 assert(dog.get("name")===dogEntity.get("name"), "The dog's name was not the same as the serialized dog")367 done();368 })369 var dogCollection;370 it('createCollection',function(done){371 client.createCollection({type:'dogs'},function(err, response, dogs){372 assert(!err, "createCollection returned an error");373 assert(dogs, "createCollection did not return a dogs collection");374 dogCollection=dogs;375 done();376 })377 })378 it('restoreCollection',function(done){379 var serializedDogs=dogCollection.serialize();380 var dogs=client.restoreCollection(serializedDogs);381 console.warn('restoreCollection',dogs, dogCollection);382 assert(dogs._type===dogCollection._type, "The dog collection type was not the same as the serialized dog collection")383 assert(dogs._qs==dogCollection._qs, "The query strings do not match")384 assert(dogs._list.length===dogCollection._list.length, "The collections have a different number of entities")385 done();386 })387 var activityUser;388 before(function(done){389 activityUser=new Usergrid.Entity({client:client,data:{"type":"user",'username':"testActivityUser"}});390 console.warn(activityUser);391 activityUser.fetch(function(err, data){392 console.warn(err, data, activityUser);393 if(err){394 activityUser.save(function(err, data){395 activityUser.set(data);396 done();397 });398 }else{399 activityUser.set(data);400 done();401 }402 })403 })404 it('createUserActivity',function(done){405 var options = {406 "actor" : {407 "displayName" :"Test Activity User",408 "uuid" : activityUser.get("uuid"),409 "username" : "testActivityUser",410 "email" : "usergrid@apigee.com",411 "image" : {412 "height" : 80,413 "url" : "http://placekitten.com/80/80",414 "width" : 80415 }416 },417 "verb" : "post",418 "content" : "test post for createUserActivity",419 "lat" : 48.856614,420 "lon" : 2.352222421 };422 client.createUserActivity("testActivityUser", options, function(err, activity){423 assert(!err, "createUserActivity returned an error");424 assert(activity, "createUserActivity returned no activity object")425 done();426 })427 })428 it('createUserActivityWithEntity',function(done){429 client.createUserActivityWithEntity(activityUser, "Another test activity with createUserActivityWithEntity", function(err, activity){430 assert(!err, "createUserActivityWithEntity returned an error "+err);431 assert(activity, "createUserActivityWithEntity returned no activity object")432 done();433 })434 })435 it('getFeedForUser',function(done){436 client.getFeedForUser('testActivityUser', function(err, data, items){437 assert(!err, "getFeedForUser returned an error");438 assert(data, "getFeedForUser returned no data object")439 assert(items, "getFeedForUser returned no items array")440 done();441 })442 })443 var testProperty="____test_item"+Math.floor(Math.random()*10000),444 testPropertyValue="test"+Math.floor(Math.random()*10000),445 testPropertyObjectValue={test:testPropertyValue};446 it('set',function(done){447 client.set(testProperty, testPropertyValue);448 done();449 })450 it('get',function(done){451 var retrievedValue=client.get(testProperty);452 assert(retrievedValue===testPropertyValue, "Get is not working properly");453 done();454 })455 it('setObject',function(done){456 client.set(testProperty, testPropertyObjectValue);457 done();458 })459 it('getObject',function(done){460 var retrievedValue=client.get(testProperty);461 assert(retrievedValue==testPropertyObjectValue, "getObject is not working properly");462 done();463 })464 /*it('setToken',function(done){465 client.setToken("dummytoken");466 done();467 })468 it('getToken',function(done){469 assert(client.getToken()==="dummytoken");470 done();471 })*/472 it('remove property',function(done){473 client.set(testProperty);474 assert(client.get(testProperty)===null);475 done();476 })477 var newUser;478 it('signup',function(done){479 client.signup("newUsergridUser", "Us3rgr1d15Aw3s0m3!", "usergrid@apigee.com", "Another Satisfied Developer", function(err, user){480 assert(!err, "signup returned an error");481 assert(user, "signup returned no user object")482 newUser=user;483 done();484 })485 })486 it('login',function(done){487 client.login("newUsergridUser", "Us3rgr1d15Aw3s0m3!", function(err, data, user){488 assert(!err, "login returned an error");489 assert(user, "login returned no user object")490 done();491 })492 })493 /*it('reAuthenticateLite',function(done){494 client.reAuthenticateLite(function(err){495 assert(!err, "reAuthenticateLite returned an error");496 done();497 })498 })*/499 /*it('reAuthenticate',function(done){500 client.reAuthenticate("usergrid@apigee.com", function(err, data, user, organizations, applications){501 assert(!err, "reAuthenticate returned an error");502 done();503 })504 })*/505 /*it('loginFacebook',function(done){506 assert(true, "Not sure how feasible it is to test this with Mocha")507 done();508 })*/509 it('isLoggedIn',function(done){510 assert(client.isLoggedIn()===true, "isLoggedIn is not detecting that we have logged in.")511 done();512 })513 it('getLoggedInUser',function(done){514 setTimeout(function(){515 client.getLoggedInUser(function(err, data, user){516 assert(!err, "getLoggedInUser returned an error");517 assert(user, "getLoggedInUser returned no user object")518 done();519 })520 },1000);521 })522 before(function(done){523 //please enjoy this musical interlude.524 setTimeout(function(){done()},1000);525 })526 it('logout',function(done){527 client.logout();528 assert(null===client.getToken(), "we logged out, but the token still remains.")529 done();530 })531 it('getLoggedInUser',function(done){532 client.getLoggedInUser(function(err, data, user){533 assert(err, "getLoggedInUser should return an error after logout");534 assert(user, "getLoggedInUser should not return data after logout")535 done();536 })537 })538 it('isLoggedIn',function(done){539 assert(client.isLoggedIn()===false, "isLoggedIn still returns true after logout.")540 done();541 })542 after(function (done) {543 client.request({544 method: 'DELETE',545 endpoint: 'users/newUsergridUser'546 }, function (err, data) {547 done();548 });549 })550 it('buildCurlCall',function(done){551 done();552 })553 it('getDisplayImage',function(done){554 done();555 })556 after(function(done){557 dogEntity.destroy();558 //dogCollection.destroy();559 //testGroup.destroy();560 done();561 })562 });563 });564 describe('Usergrid Entity', function() {565 var client = getClient();566 var dog;567 before(function(done) {568 //Make sure our dog doesn't already exist569 client.request({570 method: 'DELETE',571 endpoint: 'dogs/Rocky'572 }, function(err, data) {573 assert(true);574 done();575 });576 });577 it('should CREATE a new dog', function(done) {578 var options = {579 type: 'dogs',580 name: 'Rocky'581 }582 dog=new Usergrid.Entity({client:client,data:options});583 dog.save(function(err, entity) {584 assert(!err, "dog not created");585 done();586 });587 });588 it('should RETRIEVE the dog', function(done) {589 if (!dog) {590 assert(false, "dog not created");591 done();592 return;593 }594 //once the dog is created, you can set single properties:595 dog.fetch(function(err) {596 assert(!err, "dog not fetched");597 done();598 });599 });600 it('should UPDATE the dog', function(done) {601 if (!dog) {602 assert(false, "dog not created");603 done();604 return;605 }606 //once the dog is created, you can set single properties:607 dog.set('breed', 'Dinosaur');608 //the set function can also take a JSON object:609 var data = {610 master: 'Fred',611 state: 'hungry'612 }613 //set is additive, so previously set properties are not overwritten614 dog.set(data);615 //finally, call save on the object to save it back to the database616 dog.save(function(err) {617 assert(!err, "dog not saved");618 done();619 });620 });621 it('should DELETE the dog', function(done) {622 if (!dog) {623 assert(false, "dog not created");624 done();625 return;626 }627 //once the dog is created, you can set single properties:628 dog.destroy(function(err) {629 assert(!err, "dog not removed");630 done();631 });632 });633 });634 describe('Usergrid Collections', function() {635 var client = getClient();636 var dog, dogs = {};637 before(function(done) {638 //Make sure our dog doesn't already exist639 var options = {640 type: 'dogs',641 qs: {642 limit: 50643 } //limit statement set to 50644 }645 client.createCollection(options, function(err, response, dogs) {646 if (!err) {647 assert(!err, "could not retrieve list of dogs: " + dogs.error_description);648 //we got 50 dogs, now display the Entities:649 //do doggy cleanup650 //if (dogs.hasNextEntity()) {651 while (dogs.hasNextEntity()) {652 //get a reference to the dog653 var dog = dogs.getNextEntity();654 console.warn(dog);655 //notice('removing dog ' + dogname + ' from database');656 if(dog === null) continue;657 dog.destroy(function(err, data) {658 assert(!err, dog.get('name') + " not removed: " + data.error_description);659 if (!dogs.hasNextEntity()) {660 done();661 }662 });663 }664 //} else {665 done();666 //}667 }668 });669 });670 it('should CREATE a new dogs collection', function(done) {671 var options = {672 client:client,673 type: 'dogs',674 qs: {675 ql: 'order by index'676 }677 }678 dogs=new Usergrid.Collection(options);679 assert(dogs!==undefined&&dogs!==null, "could not create dogs collection");680 done();681 });682 it('should CREATE dogs in the collection', function(done) {683 this.timeout(10000);684 var totalDogs = 30;685 Array.apply(0, Array(totalDogs)).forEach(function(x, y) {686 var dogNum = y + 1;687 var options = {688 type: 'dogs',689 name: 'dog' + dogNum,690 index: y691 }692 dogs.addEntity(options, function(err, dog) {693 assert(!err, "dog not created");694 if (dogNum === totalDogs) {695 done();696 }697 });698 })699 });700 it('should RETRIEVE dogs from the collection', function(done) {701 while (dogs.hasNextEntity()) {702 //get a reference to the dog703 dog = dogs.getNextEntity();704 }705 if (done) done();706 });707 it('should RETRIEVE the next page of dogs from the collection', function(done) {708 if (dogs.hasNextPage()) {709 dogs.getNextPage(function(err) {710 loop(done);711 });712 } else {713 done();714 }715 });716 it('should RETRIEVE the previous page of dogs from the collection', function(done) {717 if (dogs.hasPreviousPage()) {718 dogs.getPreviousPage(function(err) {719 loop(done);720 });721 } else {722 done();723 }724 });725 it('should RETRIEVE an entity by UUID.', function(done) {726 var uuid=dogs.getFirstEntity().get("uuid")727 dogs.getEntityByUUID(uuid,function(err, data){728 assert(!err, "getEntityByUUID returned an error.");729 assert(uuid==data.get("uuid"), "We didn't get the dog we asked for.");730 done();731 })732 });733 it('should RETRIEVE the first entity from the collection', function() {734 assert(dogs.getFirstEntity(), "Could not retrieve the first dog");735 });736 it('should RETRIEVE the last entity from the collection', function() {737 assert(dogs.getLastEntity(), "Could not retrieve the last dog");738 });739 it('should reset the paging', function() {740 dogs.resetPaging();741 assert(!dogs.hasPreviousPage(), "Could not resetPaging");742 });743 it('should reset the entity pointer', function() {744 dogs.resetEntityPointer();745 assert(!dogs.hasPrevEntity(), "Could not reset the pointer");746 assert(dogs.hasNextEntity(), "Dog has no more entities");747 assert(dogs.getNextEntity(), "Could not retrieve the next dog");748 });749 it('should RETRIEVE the next entity from the collection', function() {750 assert(dogs.hasNextEntity(), "Dog has no more entities");751 assert(dogs.getNextEntity(), "Could not retrieve the next dog");752 });753 it('should RETRIEVE the previous entity from the collection', function() {754 assert(dogs.getNextEntity(), "Could not retrieve the next dog");755 assert(dogs.hasPrevEntity(), "Dogs has no previous entities");756 assert(dogs.getPrevEntity(), "Could not retrieve the previous dog");757 });758 it('should DELETE the entities from the collection', function(done) {759 this.timeout(20000);760 function remove(){761 if(dogs.hasNextEntity()){762 dogs.destroyEntity(dogs.getNextEntity(),function(err, data){763 assert(!err, "Could not destroy dog.");764 remove();765 })766 }else if(dogs.hasNextPage()){767 dogs.getNextPage();768 remove();769 }else{770 done();771 }772 }773 remove();774 });775 });776 describe('Usergrid Counters', function() {777 var client = getClient();778 var counter;779 var MINUTE = 1000 * 60;780 var HOUR = MINUTE * 60;781 var time = Date.now() - HOUR;782 it('should CREATE a counter', function(done) {783 counter = new Usergrid.Counter({784 client: client,785 data: {786 category: 'mocha_test',787 timestamp: time,788 name: "test",789 counters: {790 test: 0,791 test_counter: 0792 }793 }794 });795 assert(counter, "Counter not created");796 done();797 });798 it('should save a counter', function(done) {799 counter.save(function(err, data) {800 assert(!err, data.error_description);801 done();802 });803 });804 it('should reset a counter', function(done) {805 time += MINUTE * 10806 counter.set("timestamp", time);807 counter.reset({808 name: 'test'809 }, function(err, data) {810 assert(!err, data.error_description);811 done();812 });813 });814 it("should increment 'test' counter", function(done) {815 time += MINUTE * 10816 counter.set("timestamp", time);817 counter.increment({818 name: 'test',819 value: 1820 }, function(err, data) {821 assert(!err, data.error_description);822 done();823 });824 });825 it("should increment 'test_counter' counter by 4", function(done) {826 time += MINUTE * 10827 counter.set("timestamp", time);828 counter.increment({829 name: 'test_counter',830 value: 4831 }, function(err, data) {832 assert(!err, data.error_description);833 done();834 });835 });836 it("should decrement 'test' counter", function(done) {837 time += MINUTE * 10838 counter.set("timestamp", time);839 counter.decrement({840 name: 'test',841 value: 1842 }, function(err, data) {843 assert(!err, data.error_description);844 done();845 });846 });847 it('should fetch the counter', function(done) {848 counter.fetch(function(err, data) {849 assert(!err, data.error_description);850 done();851 });852 });853 it('should fetch counter data', function(done) {854 counter.getData({855 resolution: 'all',856 counters: ['test', 'test_counter']857 }, function(err, data) {858 assert(!err, data.error_description);859 done();860 });861 });862 });863 describe('Usergrid Folders and Assets', function() {864 var client = getClient();865 var folder,866 asset,867 user,868 image_type,869 image_url = 'http://placekitten.com/160/90',870 // image_url="https://api.usergrid.com/yourorgname/sandbox/assets/a4025e7a-8ab1-11e3-b56c-5d3c6e4ca93f/data",871 test_image,872 filesystem,873 file_url,874 filename = "kitten.jpg",875 foldername = "kittens",876 folderpath = '/test/' + Math.round(10000 * Math.random()),877 filepath = [folderpath, foldername, filename].join('/');878 before(function(done) {879 var req = new XMLHttpRequest();880 req.open('GET', image_url, true);881 req.responseType = 'blob';882 req.onload = function() {883 test_image = req.response;884 image_type = req.getResponseHeader('Content-Type');885 done();886 }887 req.onerror = function(err) {888 console.error(err);889 done();890 };891 req.send(null);892 });893 before(function(done) {894 this.timeout(10000);895 client.request({896 method: 'GET',897 endpoint: 'Assets'898 }, function(err, data) {899 var assets = [];900 if(data && data.entities && data.entities.length){901 assets.concat(data.entities.filter(function(asset) {902 return asset.name === filename903 }));904 }905 if (assets.length) {906 assets.forEach(function(asset) {907 client.request({908 method: 'DELETE',909 endpoint: 'assets/' + asset.uuid910 });911 });912 done();913 } else {914 done();915 }916 });917 });918 before(function(done) {919 this.timeout(10000);920 client.request({921 method: 'GET',922 endpoint: 'folders'923 }, function(err, data) {924 var folders = [];925 if(data && data.entities && data.entities.length){926 folders.concat(data.entities.filter(function(folder) {927 return folder.name === foldername928 }));929 }930 if (folders.length) {931 folders.forEach(function(folder) {932 client.request({933 method: 'DELETE',934 endpoint: 'folders/' + folder.uuid935 });936 });937 done();938 } else {939 done();940 }941 });942 });943 before(function(done) {944 this.timeout(10000);945 user = new Usergrid.Entity({946 client: client,947 data: {948 type: 'users',949 username: 'assetuser'950 }951 });952 user.fetch(function(err, data) {953 if (err) {954 user.save(function() {955 done();956 })957 } else {958 done();959 }960 })961 });962 it('should CREATE a folder', function(done) {963 folder = new Usergrid.Folder({964 client: client,965 data: {966 name: foldername,967 owner: user.get("uuid"),968 path: folderpath969 }970 }, function(err, response, folder) {971 assert(!err, err);972 done();973 });974 });975 it('should CREATE an asset', function(done) {976 asset = new Usergrid.Asset({977 client: client,978 data: {979 name: filename,980 owner: user.get("uuid"),981 path: filepath982 }983 }, function(err, response, asset) {984 if(err){985 assert(false, err);986 }987 done();988 });989 });990 it('should RETRIEVE an asset', function(done) {991 asset.fetch(function(err, response, entity){992 if(err){993 assert(false, err);994 }else{995 asset=entity;996 }997 done();998 })999 });1000 it('should upload asset data', function(done) {1001 this.timeout(5000);1002 asset.upload(test_image, function(err, response, asset) {1003 if(err){1004 assert(false, err.error_description);1005 }1006 done();1007 });1008 });1009 it('should retrieve asset data', function(done) {1010 this.timeout(5000);1011 asset.download(function(err, response, asset) {1012 if(err){1013 assert(false, err.error_description);1014 }1015 assert(asset.get('content-type') == test_image.type, "MIME types don't match");1016 assert(asset.get('size') == test_image.size, "sizes don't match");1017 done();1018 });1019 });1020 it('should add the asset to a folder', function(done) {1021 folder.addAsset({1022 asset: asset1023 }, function(err, data) {1024 if(err){1025 assert(false, err.error_description);1026 }1027 done();1028 })1029 });1030 it('should list the assets from a folder', function(done) {1031 folder.getAssets(function(err, assets) {1032 if(err){1033 assert(false, err.error_description);1034 }1035 done();1036 })1037 });1038 it('should remove the asset from a folder', function(done) {1039 folder.removeAsset({1040 asset: asset1041 }, function(err, data) {1042 if(err){1043 assert(false, err.error_description);1044 }1045 done();1046 })1047 });1048 after(function(done) {1049 asset.destroy(function(err, data) {1050 if(err){1051 assert(false, err.error_description);1052 }1053 done();1054 })1055 });1056 after(function(done) {1057 folder.destroy(function(err, data) {1058 if(err){1059 assert(false, err.error_description);1060 }1061 done();1062 })1063 });1064 });...

Full Screen

Full Screen

gallery-router-test.js

Source:gallery-router-test.js Github

copy

Full Screen

...42 .send(exampleGallery)43 .set({Authorization: `Bearer ${this.tempToken}`})44 .end((err, res) => {45 if (err)46 return done(err)47 expect(res.body.name).to.equal(exampleGallery.name)48 expect(res.body.desc).to.equal(exampleGallery.desc)49 expect(res.body.userID).to.equal(this.tempUser._id.toString())50 let date = new Date(res.body.created).toString()51 expect(date).to.not.equal('Invalid Date')52 done()53 })54 })55 })56 describe('with invalid token', () => {57 before(done => mockUser.call(this, done))58 it('should respond with status 401', done => {59 request.post(`${url}/api/gallery`)60 .send(exampleGallery)61 .set({Authorization: `Bearer ${this.tempToken}bad`})62 .end((err, res) => {63 expect(res.status).to.equal(401)64 expect(res.text).to.equal('UnauthorizedError')65 done()66 })67 })68 })69 describe('with invalid Bearer auth', () => {70 before(done => mockUser.call(this, done))71 it('should respond with status 400', done => {72 request.post(`${url}/api/gallery`)73 .send(exampleGallery)74 .set({Authorization: 'not bearer auth'})75 .end((err, res) => {76 expect(res.status).to.equal(400)77 expect(res.text).to.equal('BadRequestError')78 done()79 })80 })81 })82 describe('with no Authorization header', () => {83 before(done => mockUser.call(this, done))84 it('should respond with status 400', done => {85 request.post(`${url}/api/gallery`)86 .send(exampleGallery)87 .end((err, res) => {88 expect(res.status).to.equal(400)89 expect(res.text).to.equal('BadRequestError')90 done()91 })92 })93 })94 describe('with no name', () => {95 before(done => mockUser.call(this, done))96 it('should respond with status 400', done => {97 request.post(`${url}/api/gallery`)98 .set({Authorization: `Bearer ${this.tempToken}`})99 .send({ desc: exampleGallery.desc})100 .end((err, res) => {101 expect(res.status).to.equal(400)102 expect(res.text).to.equal('BadRequestError')103 done()104 })105 })106 })107 describe('with no desc', () => {108 before(done => mockUser.call(this, done))109 it('should respond with status 400', done => {110 request.post(`${url}/api/gallery`)111 .set({Authorization: `Bearer ${this.tempToken}`})112 .send({ name: exampleGallery.name})113 .end((err, res) => {114 expect(res.status).to.equal(400)115 expect(res.text).to.equal('BadRequestError')116 done()117 })118 })119 })120 })121 describe('testing GET to /api/gallery/:id', () => {122 // create this.tempToken, this.tempUser, this.tempGallery123 describe('with valid token and id', function(){124 before(done => mockGallery.call(this, done))125 it('should return a gallery', done => {126 request.get(`${url}/api/gallery/${this.tempGallery._id}`)127 .set({128 Authorization: `Bearer ${this.tempToken}`,129 })130 .end((err, res) => {131 if (err)132 return done(err)133 expect(res.body.name).to.equal(exampleGallery.name)134 expect(res.body.desc).to.equal(exampleGallery.desc)135 expect(res.body.userID).to.equal(this.tempUser._id.toString())136 let date = new Date(res.body.created).toString()137 expect(date).to.equal(this.tempGallery.created.toString())138 done()139 })140 })141 })142 describe('with many pictures', function(){143 before(done => mockManyPics.call(this, 100, done))144 it('should return a gallery', done => {145 request.get(`${url}/api/gallery/${this.tempGallery._id}`)146 .set({147 Authorization: `Bearer ${this.tempToken}`,148 })149 .end((err, res) => {150 if (err)151 return done(err)152 expect(res.body.name).to.equal(exampleGallery.name)153 expect(res.body.desc).to.equal(exampleGallery.desc)154 expect(res.body.userID).to.equal(this.tempUser._id.toString())155 expect(Array.isArray(res.body.pics)).to.equal(true)156 expect(res.body.pics.length).to.equal(100)157 let date = new Date(res.body.created).toString()158 expect(date).to.equal(this.tempGallery.created.toString())159 for (let i=0; i< res.body.pics.length; i++){160 expect(res.body.pics[i]._id.toString()).to.equal(this.tempPics[i]._id.toString())161 expect(res.body.pics[i].name).to.equal(this.tempPics[i].name)162 expect(res.body.pics[i].desc).to.equal(this.tempPics[i].desc)163 expect(res.body.pics[i].imageURI).to.equal(this.tempPics[i].imageURI)164 }165 done()166 })167 })168 })169 describe('with ?itemcount=10&itempage=2', function(){170 before(done => mockManyPics.call(this, 100, done))171 it('should return a gallery', done => {172 request.get(`${url}/api/gallery/${this.tempGallery._id}?itemcount=10&itempage=2`)173 .set({174 Authorization: `Bearer ${this.tempToken}`,175 })176 .end((err, res) => {177 if (err)178 return done(err)179 expect(res.body.name).to.equal(exampleGallery.name)180 expect(res.body.desc).to.equal(exampleGallery.desc)181 expect(res.body.userID).to.equal(this.tempUser._id.toString())182 expect(Array.isArray(res.body.pics)).to.equal(true)183 expect(res.body.pics.length).to.equal(10)184 let date = new Date(res.body.created).toString()185 expect(date).to.equal(this.tempGallery.created.toString())186 for (let i=0; i< res.body.pics.length; i++){187 expect(res.body.pics[i]._id.toString()).to.equal(this.tempPics[i + 10 ]._id.toString())188 expect(res.body.pics[i].name).to.equal(this.tempPics[i + 10].name)189 expect(res.body.pics[i].desc).to.equal(this.tempPics[i + 10].desc)190 expect(res.body.pics[i].imageURI).to.equal(this.tempPics[i + 10].imageURI)191 }192 done()193 })194 })195 })196 describe('with many pictures and ?itemcount=10', function(){197 before(done => mockManyPics.call(this, 100, done))198 it('should return a gallery', done => {199 request.get(`${url}/api/gallery/${this.tempGallery._id}?itemcount=10`)200 .set({201 Authorization: `Bearer ${this.tempToken}`,202 })203 .end((err, res) => {204 if (err)205 return done(err)206 expect(res.body.name).to.equal(exampleGallery.name)207 expect(res.body.desc).to.equal(exampleGallery.desc)208 expect(res.body.userID).to.equal(this.tempUser._id.toString())209 expect(Array.isArray(res.body.pics)).to.equal(true)210 expect(res.body.pics.length).to.equal(10)211 let date = new Date(res.body.created).toString()212 expect(date).to.equal(this.tempGallery.created.toString())213 for (let i=0; i< res.body.pics.length; i++){214 expect(res.body.pics[i]._id.toString()).to.equal(this.tempPics[i]._id.toString())215 expect(res.body.pics[i].name).to.equal(this.tempPics[i].name)216 expect(res.body.pics[i].desc).to.equal(this.tempPics[i].desc)217 expect(res.body.pics[i].imageURI).to.equal(this.tempPics[i].imageURI)218 }219 done()220 })221 })222 })223 describe('with many pictures and ?itemcount=10&itemsort=dsc', function(){224 before(done => mockManyPics.call(this, 100, done))225 it('should return a gallery', done => {226 request.get(`${url}/api/gallery/${this.tempGallery._id}?itemcount=10&itemsort=dsc`)227 .set({228 Authorization: `Bearer ${this.tempToken}`,229 })230 .end((err, res) => {231 if (err)232 return done(err)233 expect(res.body.name).to.equal(exampleGallery.name)234 expect(res.body.desc).to.equal(exampleGallery.desc)235 expect(res.body.userID).to.equal(this.tempUser._id.toString())236 expect(Array.isArray(res.body.pics)).to.equal(true)237 expect(res.body.pics.length).to.equal(10)238 let date = new Date(res.body.created).toString()239 expect(date).to.equal(this.tempGallery.created.toString())240 let tempPicsLength = this.tempPics.length241 for (let i=0; i< res.body.pics.length; i++){242 expect(res.body.pics[i]._id.toString()).to.equal(this.tempPics[tempPicsLength - 1 - i]._id.toString())243 expect(res.body.pics[i].name).to.equal(this.tempPics[tempPicsLength - 1 - i].name)244 expect(res.body.pics[i].desc).to.equal(this.tempPics[tempPicsLength - 1 - i].desc)245 expect(res.body.pics[i].imageURI).to.equal(this.tempPics[tempPicsLength - 1 - i].imageURI)246 }247 done()248 })249 })250 })251 describe('with many pictures and ?itemcount=10&itemsort=dsc?itemoffset=1', function(){252 before(done => mockManyPics.call(this, 100, done))253 it('should return a gallery', done => {254 request.get(`${url}/api/gallery/${this.tempGallery._id}?itemcount=10&itemsort=dsc&itemoffset=1`)255 .set({256 Authorization: `Bearer ${this.tempToken}`,257 })258 .end((err, res) => {259 if (err)260 return done(err)261 expect(res.body.name).to.equal(exampleGallery.name)262 expect(res.body.desc).to.equal(exampleGallery.desc)263 expect(res.body.userID).to.equal(this.tempUser._id.toString())264 expect(Array.isArray(res.body.pics)).to.equal(true)265 expect(res.body.pics.length).to.equal(10)266 let date = new Date(res.body.created).toString()267 expect(date).to.equal(this.tempGallery.created.toString())268 let tempPicsLength = this.tempPics.length269 for (let i=0; i< res.body.pics.length; i++){270 expect(res.body.pics[i]._id.toString()).to.equal(this.tempPics[tempPicsLength - 2 - i]._id.toString())271 expect(res.body.pics[i].name).to.equal(this.tempPics[tempPicsLength - 2 - i].name)272 expect(res.body.pics[i].desc).to.equal(this.tempPics[tempPicsLength - 2 - i].desc)273 expect(res.body.pics[i].imageURI).to.equal(this.tempPics[tempPicsLength - 2 - i].imageURI)274 }275 done()276 })277 })278 })279 describe('with many pictures and ?itemcount=10&itemoffset=1', function(){280 before(done => mockManyPics.call(this, 100, done))281 it('should return a gallery', done => {282 request.get(`${url}/api/gallery/${this.tempGallery._id}?itemcount=10&itemoffset=1`)283 .set({284 Authorization: `Bearer ${this.tempToken}`,285 })286 .end((err, res) => {287 if (err)288 return done(err)289 expect(res.body.name).to.equal(exampleGallery.name)290 expect(res.body.desc).to.equal(exampleGallery.desc)291 expect(res.body.userID).to.equal(this.tempUser._id.toString())292 expect(Array.isArray(res.body.pics)).to.equal(true)293 expect(res.body.pics.length).to.equal(10)294 let date = new Date(res.body.created).toString()295 expect(date).to.equal(this.tempGallery.created.toString())296 for (let i=0; i< res.body.pics.length; i++){297 expect(res.body.pics[i]._id.toString()).to.equal(this.tempPics[i + 1]._id.toString())298 expect(res.body.pics[i].name).to.equal(this.tempPics[i + 1].name)299 expect(res.body.pics[i].desc).to.equal(this.tempPics[i + 1].desc)300 expect(res.body.pics[i].imageURI).to.equal(this.tempPics[i + 1].imageURI)301 }302 done()303 })304 })305 })306 describe('with invalid token', function(){307 before(done => mockGallery.call(this, done))308 it('should respond with status 401', done => {309 request.get(`${url}/api/gallery/${this.tempGallery._id}`)310 .set({311 Authorization: `Bearer ${this.tempToken}bad`,312 })313 .end((err, res) => {314 expect(res.status).to.equal(401)315 expect(res.text).to.equal('UnauthorizedError')316 done()317 })318 })319 })320 describe('with invalid Bearer auth', function(){321 before(done => mockGallery.call(this, done))322 it('should respond with status 400', done => {323 request.get(`${url}/api/gallery/${this.tempGallery._id}`)324 .set({ Authorization: 'bad request' })325 .end((err, res) => {326 expect(res.status).to.equal(400)327 expect(res.text).to.equal('BadRequestError')328 done()329 })330 })331 })332 describe('with no Authorization header', function(){333 before(done => mockGallery.call(this, done))334 it('should respond with status 400', done => {335 request.get(`${url}/api/gallery/${this.tempGallery._id}`)336 .end((err, res) => {337 expect(res.status).to.equal(400)338 expect(res.text).to.equal('BadRequestError')339 done()340 })341 })342 })343 describe('with invalid id', function(){344 before(done => mockGallery.call(this, done))345 it('should return a gallery', done => {346 request.get(`${url}/api/gallery/${this.tempGallery._id}bad`)347 .set({348 Authorization: `Bearer ${this.tempToken}`,349 })350 .end((err, res) => {351 expect(res.status).to.equal(400)352 expect(res.text).to.equal('BadRequestError')353 done()354 })355 })356 })357 describe('with user whos been removed', function(){358 before(done => mockGallery.call(this, done))359 before(done => {360 User.remove({})361 .then(() => done())362 .catch(done)363 })364 it('should respond with status 401', done => {365 request.get(`${url}/api/gallery/${this.tempGallery._id}`)366 .set({367 Authorization: `Bearer ${this.tempToken}`,368 })369 .end((err, res) => {370 expect(res.status).to.equal(401)371 expect(res.text).to.equal('UnauthorizedError')372 done()373 })374 })375 })376 describe('with wrong user', function(){377 // mock user, password, token, and gallery378 before(done => mockGallery.call(this, done))379 // overwrite user, password, and token with new user380 before(done => mockUser.call(this, done))381 it('should respond with status 401', done => {382 request.get(`${url}/api/gallery/${this.tempGallery._id}`)383 .set({384 Authorization: `Bearer ${this.tempToken}`,385 })386 .end((err, res) => {387 expect(res.status).to.equal(401)388 expect(res.text).to.equal('UnauthorizedError')389 done()390 })391 })392 })393 })394 describe('testing PUT /api/gallery/:galleryID', function(){395 describe('update name ande desc', function(){396 // mock user, password, token, and gallery397 before(done => mockGallery.call(this, done))398 it('should return a gallery', done => {399 request.put(`${url}/api/gallery/${this.tempGallery._id}`)400 .send({401 name: 'hello',402 desc: 'cool',403 })404 .set({405 Authorization: `Bearer ${this.tempToken}`,406 })407 .end((err, res) => {408 if(err) return done(err)409 expect(res.status).to.equal(200)410 expect(res.body.name).to.equal('hello')411 expect(res.body.desc).to.equal('cool')412 done()413 })414 })415 })416 describe('update name ande desc', function(){417 // mock user, password, token, and gallery418 before(done => mockGallery.call(this, done))419 before(done => mockUser.call(this, done))420 it('should return a gallery', done => {421 request.put(`${url}/api/gallery/${this.tempGallery._id}`)422 .send({423 name: 'hello',424 desc: 'cool',425 })426 .set({427 Authorization: `Bearer ${this.tempToken}`,428 })429 .end((err, res) => {430 expect(res.status).to.equal(401)431 done()432 })433 })434 })435 describe('update name', function(){436 // mock user, password, token, and gallery437 before(done => mockGallery.call(this, done))438 it('should return a gallery', done => {439 request.put(`${url}/api/gallery/${this.tempGallery._id}`)440 .send({441 name: 'hello',442 })443 .set({444 Authorization: `Bearer ${this.tempToken}`,445 })446 .end((err, res) => {447 if (err) return done(err)448 expect(res.status).to.equal(200)449 expect(res.body.name).to.equal('hello')450 expect(res.body.desc).to.equal(this.tempGallery.desc)451 done()452 })453 })454 })455 describe('update desc', function(){456 // mock user, password, token, and gallery457 before(done => mockGallery.call(this, done))458 it('should return a gallery', done => {459 request.put(`${url}/api/gallery/${this.tempGallery._id}`)460 .send({461 desc: 'cool',462 })463 .set({464 Authorization: `Bearer ${this.tempToken}`,465 })466 .end((err, res) => {467 if (err) return done(err)468 expect(res.status).to.equal(200)469 expect(res.body.name).to.equal(this.tempGallery.name)470 expect(res.body.desc).to.equal('cool')471 done()472 })473 })474 })475 describe('with bad galeryID', function(){476 // mock user, password, token, and gallery477 before(done => mockGallery.call(this, done))478 it('should return a gallery', done => {479 request.put(`${url}/api/gallery/${this.tempGallery._id}bad`)480 .send({481 desc: 'cool',482 })483 .set({484 Authorization: `Bearer ${this.tempToken}`,485 })486 .end((err, res) => {487 expect(res.status).to.equal(404)488 expect(res.text).to.equal('NotFoundError')489 done()490 })491 })492 })493 describe('with bad token', function(){494 // mock user, password, token, and gallery495 before(done => mockGallery.call(this, done))496 it('should respond with status 401', done => {497 request.put(`${url}/api/gallery/${this.tempGallery._id}`)498 .send({499 desc: 'cool',500 })501 .set({502 Authorization: `Bearer ${this.tempToken}bad`,503 })504 .end((err, res) => {505 expect(res.status).to.equal(401)506 expect(res.text).to.equal('UnauthorizedError')507 done()508 })509 })510 })511 describe('witn no auth', function(){512 // mock user, password, token, and gallery513 before(done => mockGallery.call(this, done))514 it('should respond with status 400', done => {515 request.put(`${url}/api/gallery/${this.tempGallery._id}bad`)516 .send({517 desc: 'cool',518 })519 .end((err, res) => {520 expect(res.status).to.equal(400)521 expect(res.text).to.equal('BadRequestError')522 done()523 })524 })525 })526 })527 describe('testing DELETE /api/gallery/:galleryID', function(){528 describe('should respond with status 204', function(){529 // mock user, password, token, and gallery530 before(done => mockGallery.call(this, done))531 it('should return a gallery', done => {532 request.delete(`${url}/api/gallery/${this.tempGallery._id}`)533 .set({534 Authorization: `Bearer ${this.tempToken}`,535 })536 .end((err, res) => {537 expect(res.status).to.equal(204)538 done()539 })540 })541 })542 describe('with invalid galleryID', function(){543 // mock user, password, token, and gallery544 before(done => mockGallery.call(this, done))545 it('should return a gallery', done => {546 request.delete(`${url}/api/gallery/${this.tempGallery._id}bad`)547 .set({ Authorization: `Bearer ${this.tempToken}` })548 .end((err, res) => {549 expect(res.status).to.equal(404)550 expect(res.text).to.equal('NotFoundError')551 done()552 })553 })554 })555 describe('with invalid galleryID', function(){556 // mock user, password, token, and gallery557 before(done => mockGallery.call(this, done))558 before(done => mockUser.call(this, done))559 it('should return a gallery', done => {560 request.delete(`${url}/api/gallery/${this.tempGallery._id}`)561 .set({ Authorization: `Bearer ${this.tempToken}` })562 .end((err, res) => {563 expect(res.status).to.equal(401)564 done()565 })566 })567 })568 describe('with invalid token', function(){569 // mock user, password, token, and gallery570 before(done => mockGallery.call(this, done))571 it('should respond with status 401', done => {572 request.delete(`${url}/api/gallery/${this.tempGallery._id}`)573 .set({574 Authorization: `Bearer ${this.tempToken}bad`,575 })576 .end((err, res) => {577 expect(res.status).to.equal(401)578 expect(res.text).to.equal('UnauthorizedError')579 done()580 })581 })582 })583 describe('witn no auth', function(){584 // mock user, password, token, and gallery585 before(done => mockGallery.call(this, done))586 it('should respond with status 400', done => {587 request.delete(`${url}/api/gallery/${this.tempGallery._id}`)588 .end((err, res) => {589 expect(res.status).to.equal(400)590 expect(res.text).to.equal('BadRequestError')591 done()592 })593 })594 })595 })596 describe('testing GET /api/gallery', function(){597 describe('with valid request', function(){598 before( done => mockManyGallerys.call(this, 100, done))599 it('should respond with status 400', done => {600 request.get(`${url}/api/gallery`)601 .set({ Authorization: `Bearer ${this.tempToken}` })602 .end((err, res) => {603 expect(res.status).to.equal(200)604 expect(Array.isArray(res.body)).to.equal(true)605 expect(res.body.length).to.equal(50)606 done()607 })608 })609 })610 describe('with ?pagesize=10', function(){611 before( done => mockManyGallerys.call(this, 100, done))612 it('should return 10 notes', done => {613 request.get(`${url}/api/gallery?pagesize=5`)614 .set({ Authorization: `Bearer ${this.tempToken}` })615 .end((err, res) => {616 expect(res.status).to.equal(200)617 expect(Array.isArray(res.body)).to.equal(true)618 expect(res.body.length).to.equal(5)619 for (let i=0; i < res.body.length; i++){620 expect(res.body[i].name).to.equal(this.tempGallerys[i].name)621 }622 done()623 })624 })625 })626 describe('with ?sort=dsc', function(){627 before( done => mockManyGallerys.call(this, 100, done))628 it('should return 10 notes', done => {629 request.get(`${url}/api/gallery?sort=dsc`)630 .set({ Authorization: `Bearer ${this.tempToken}` })631 .end((err, res) => {632 expect(res.status).to.equal(200)633 expect(Array.isArray(res.body)).to.equal(true)634 expect(res.body.length).to.equal(50)635 for (let i=0; i < res.body.length; i++){636 expect(res.body[i].name).to.equal(this.tempGallerys[this.tempGallerys.length - i - 1].name)637 }638 done()639 })640 })641 })642 describe('with ?sort=dsc?offset=3', function(){643 before( done => mockManyGallerys.call(this, 100, done))644 it('should return 10 notes', done => {645 request.get(`${url}/api/gallery?sort=dsc&offset=3`)646 .set({ Authorization: `Bearer ${this.tempToken}` })647 .end((err, res) => {648 expect(res.status).to.equal(200)649 expect(Array.isArray(res.body)).to.equal(true)650 expect(res.body.length).to.equal(50)651 for (let i=0; i < res.body.length; i++){652 let index = this.tempGallerys.length - i - 4 653 expect(res.body[i].name).to.equal(this.tempGallerys[index].name)654 }655 done()656 })657 })658 })659 describe('with offset=1', function(){660 before( done => mockManyGallerys.call(this, 100, done))661 it('should return 10 notes', done => {662 request.get(`${url}/api/gallery?offset=1`)663 .set({ Authorization: `Bearer ${this.tempToken}` })664 .end((err, res) => {665 expect(res.status).to.equal(200)666 expect(Array.isArray(res.body)).to.equal(true)667 expect(res.body.length).to.equal(50)668 for (let i=0; i < res.body.length; i++){669 expect(res.body[i].name).to.equal(this.tempGallerys[i + 1].name)670 }671 done()672 })673 })674 })675 describe('with ?page=2', function(){676 before( done => mockManyGallerys.call(this, 100, done))677 it('should return 10 notes', done => {678 request.get(`${url}/api/gallery?page=2`)679 .set({ Authorization: `Bearer ${this.tempToken}` })680 .end((err, res) => {681 expect(res.status).to.equal(200)682 expect(Array.isArray(res.body)).to.equal(true)683 expect(res.body.length).to.equal(50)684 for (let i=0; i < res.body.length; i++){685 expect(res.body[i].name).to.equal(this.tempGallerys[i + 50].name)686 }687 done()688 })689 })690 })691 describe('with ?page=3&?offset=1', function(){692 before( done => mockManyGallerys.call(this, 150, done))693 it('should return 10 notes', done => {694 request.get(`${url}/api/gallery?page=3&offset=1`)695 .set({ Authorization: `Bearer ${this.tempToken}` })696 .end((err, res) => {697 expect(res.status).to.equal(200)698 expect(Array.isArray(res.body)).to.equal(true)699 expect(res.body.length).to.equal(49)700 for (let i=0; i < res.body.length; i++){701 expect(res.body[i].name).to.equal(this.tempGallerys[i + 101].name)702 }703 done()704 })705 })706 })707 describe('with ?page=-1', function(){708 before( done => mockManyGallerys.call(this, 150, done))709 it('should return 10 notes', done => {710 request.get(`${url}/api/gallery?page=-1`)711 .set({ Authorization: `Bearer ${this.tempToken}` })712 .end((err, res) => {713 expect(res.status).to.equal(200)714 expect(Array.isArray(res.body)).to.equal(true)715 expect(res.body.length).to.equal(50)716 for (let i=0; i < res.body.length; i++){717 expect(res.body[i].name).to.equal(this.tempGallerys[i].name)718 }719 done()720 })721 })722 })723 describe('with ?pagesize=-1', function(){724 before( done => mockManyGallerys.call(this, 50, done))725 it('should return 10 notes', done => {726 request.get(`${url}/api/gallery?pagesize=-1`)727 .set({ Authorization: `Bearer ${this.tempToken}` })728 .end((err, res) => {729 expect(res.status).to.equal(200)730 expect(Array.isArray(res.body)).to.equal(true)731 expect(res.body.length).to.equal(1)732 for (let i=0; i < res.body.length; i++){733 expect(res.body[i].name).to.equal(this.tempGallerys[i].name)734 }735 done()736 })737 })738 })739 describe('with ?pagesize=300', function(){740 before( done => mockManyGallerys.call(this, 300, done))741 it('should return 10 notes', done => {742 request.get(`${url}/api/gallery?pagesize=250`)743 .set({ Authorization: `Bearer ${this.tempToken}` })744 .end((err, res) => {745 expect(res.status).to.equal(200)746 expect(Array.isArray(res.body)).to.equal(true)747 expect(res.body.length).to.equal(250)748 for (let i=0; i < res.body.length; i++){749 expect(res.body[i].name).to.equal(this.tempGallerys[i].name)750 }751 done()752 })753 })754 })755 describe('with invalid token', function(){756 before( done => mockManyGallerys.call(this, 50, done))757 it('should respond with status 401', done => {758 request.get(`${url}/api/gallery`)759 .set({ Authorization: `Bearer ${this.tempToken}bad` })760 .end((err, res) => {761 expect(res.status).to.equal(401)762 expect(res.text).to.equal('UnauthorizedError')763 done()764 })765 })766 })767 describe('with ?name=co', function(){768 before( done => mockManyGallerys.call(this, 100, done))769 it('should respond nodes with fuzzy match co', done => {770 request.get(`${url}/api/gallery?name=co`)771 .set({ Authorization: `Bearer ${this.tempToken}` })772 .end((err, res) => {773 expect(res.status).to.equal(200)774 expect(Array.isArray(res.body)).to.equal(true)775 console.log('matching notes', res.body.length)776 let fuzzyName = fuzzyRegex('co')777 for (let i=0; i < res.body.length; i++){778 expect(res.body[i].name).to.match(fuzzyName)779 }780 done()781 })782 })783 })784 describe('with ?desc=co', function(){785 before( done => mockManyGallerys.call(this, 100, done))786 it('should respond nodes with fuzzy match co', done => {787 request.get(`${url}/api/gallery?desc=co`)788 .set({ Authorization: `Bearer ${this.tempToken}` })789 .end((err, res) => {790 expect(res.status).to.equal(200)791 expect(Array.isArray(res.body)).to.equal(true)792 console.log('matching notes', res.body.length)793 let fuzzyName = fuzzyRegex('co')794 for (let i=0; i < res.body.length; i++){795 expect(res.body[i].desc).to.match(fuzzyName)796 }797 done()798 })799 })800 })801 })802 describe('testing GET /api/public/gallery', function(){803 describe('with valid request', function(){804 let options = {805 users: 4,806 gallerys: 3,807 pics: 4,808 }809 before( done => mockManyEverything.call(this, options, done))810 it('should respond nodes with fuzzy match co', done => {811 request.get(`${url}/api/public/gallery`)812 .end((err, res) => {813 expect(res.status).to.equal(200)814 expect(Array.isArray(res.body)).to.equal(true)815 done()816 })817 })818 })819 describe('with ?username=lu', function(){820 let options = {821 users: 30,822 gallerys: 1,823 pics: 1,824 }825 before( done => mockManyEverything.call(this, options, done))826 it('should respond nodes with fuzzy match lu', done => {827 request.get(`${url}/api/public/gallery?username=lu`)828 .end((err, res) => {829 expect(res.status).to.equal(200)830 expect(Array.isArray(res.body)).to.equal(true)831 let fuzzy = fuzzyRegex('lu')832 console.log('matches found', res.body.length)833 for (let i=0; i < res.body.length; i++){834 expect(res.body[i].username).to.match(fuzzy)835 }836 done()837 })838 })839 })840 describe('with ?name=lu', function(){841 let options = {842 users: 5,843 gallerys: 10,844 pics: 1,845 }846 before( done => mockManyEverything.call(this, options, done))847 it('should respond nodes with fuzzy match lu', done => {848 request.get(`${url}/api/public/gallery?name=lu`)849 .end((err, res) => {850 expect(res.status).to.equal(200)851 expect(Array.isArray(res.body)).to.equal(true)852 let fuzzy = fuzzyRegex('lu')853 console.log('matches found', res.body.length)854 for (let i=0; i < res.body.length; i++){855 expect(res.body[i].name).to.match(fuzzy)856 }857 done()858 })859 })860 })861 describe('with ?itemcount=4', function(){862 let options = {863 users: 2,864 gallerys: 5,865 pics: 10,866 }867 before( done => mockManyEverything.call(this, options, done))868 it('each galery should have 4 pics', done => {869 request.get(`${url}/api/public/gallery?itemcount=4`)870 .end((err, res) => {871 expect(res.status).to.equal(200)872 expect(Array.isArray(res.body)).to.equal(true)873 for (let i=0; i < res.body.length; i++){874 expect(res.body[i].pics.length).to.equal(4)875 }876 done()877 })878 })879 })880 describe('with ?pagesize=4', function(){881 let options = {882 users: 2,883 gallerys: 5,884 pics: 10,885 }886 before( done => mockManyEverything.call(this, options, done))887 it('show top 4 galerys with 10 pics', done => {888 request.get(`${url}/api/public/gallery?pagesize=4`)889 .end((err, res) => {890 expect(res.status).to.equal(200)891 expect(Array.isArray(res.body)).to.equal(true)892 expect(res.body.length).to.equal(4)893 for (let i=0; i < res.body.length; i++){894 expect(res.body[i].pics.length).to.equal(10)895 }896 done()897 })898 })899 })900 })...

Full Screen

Full Screen

management-sdk.js

Source:management-sdk.js Github

copy

Full Screen

...37 result = result.then(function () {38 return testErrors(f);39 });40 });41 result.done(function () {42 done();43 });44 // Test that the proper error code and text is passed through on a server error45 function testErrors(method) {46 return Q.Promise(function (resolve, reject, notify) {47 method().done(function () {48 assert.fail("Should have thrown an error");49 reject();50 }, function (error) {51 assert.equal(error.message, "Text");52 assert(error.statusCode);53 resolve();54 });55 });56 }57 });58 it("isAuthenticated handles successful auth", function (done) {59 mockReturn(JSON.stringify({ authenticated: true }), 200, {});60 manager.isAuthenticated()61 .done(function (authenticated) {62 assert(authenticated, "Should be authenticated");63 done();64 });65 });66 it("isAuthenticated handles unsuccessful auth", function (done) {67 mockReturn("Unauthorized", 401, {});68 manager.isAuthenticated()69 .done(function (authenticated) {70 assert(!authenticated, "Should not be authenticated");71 done();72 });73 });74 it("isAuthenticated handles unsuccessful auth with promise rejection", function (done) {75 mockReturn("Unauthorized", 401, {});76 // use optional parameter to ask for rejection of the promise if not authenticated77 manager.isAuthenticated(true)78 .done(function (authenticated) {79 assert.fail("isAuthenticated should have rejected the promise");80 done();81 }, function (err) {82 assert.equal(err.message, "Unauthorized", "Error message should be 'Unauthorized'");83 done();84 });85 });86 it("isAuthenticated handles unexpected status codes", function (done) {87 mockReturn("Not Found", 404, {});88 manager.isAuthenticated()89 .done(function (authenticated) {90 assert.fail("isAuthenticated should have rejected the promise");91 done();92 }, function (err) {93 assert.equal(err.message, "Not Found", "Error message should be 'Not Found'");94 done();95 });96 });97 it("addApp handles successful response", function (done) {98 mockReturn(JSON.stringify({ success: true }), 201, { location: "/appName" });99 manager.addApp("appName")100 .done(function (obj) {101 assert.ok(obj);102 done();103 }, rejectHandler);104 });105 it("addApp handles error response", function (done) {106 mockReturn(JSON.stringify({ success: false }), 404, {});107 manager.addApp("appName")108 .done(function (obj) {109 throw new Error("Call should not complete successfully");110 }, function (error) { return done(); });111 });112 it("getApp handles JSON response", function (done) {113 mockReturn(JSON.stringify({ app: {} }), 200, {});114 manager.getApp("appName")115 .done(function (obj) {116 assert.ok(obj);117 done();118 }, rejectHandler);119 });120 it("updateApp handles success response", function (done) {121 mockReturn(JSON.stringify({ apps: [] }), 200, {});122 manager.renameApp("appName", "newAppName")123 .done(function (obj) {124 assert.ok(!obj);125 done();126 }, rejectHandler);127 });128 it("removeApp handles success response", function (done) {129 mockReturn("", 200, {});130 manager.removeApp("appName")131 .done(function (obj) {132 assert.ok(!obj);133 done();134 }, rejectHandler);135 });136 it("transferApp handles successful response", function (done) {137 mockReturn("", 201);138 manager.transferApp("appName", "email1")139 .done(function (obj) {140 assert.ok(!obj);141 done();142 }, rejectHandler);143 });144 it("addDeployment handles success response", function (done) {145 mockReturn(JSON.stringify({ deployment: { name: "name", key: "key" } }), 201, { location: "/deploymentName" });146 manager.addDeployment("appName", "deploymentName")147 .done(function (obj) {148 assert.ok(obj);149 done();150 }, rejectHandler);151 });152 it("getDeployment handles JSON response", function (done) {153 mockReturn(JSON.stringify({ deployment: {} }), 200, {});154 manager.getDeployment("appName", "deploymentName")155 .done(function (obj) {156 assert.ok(obj);157 done();158 }, rejectHandler);159 });160 it("getDeployments handles JSON response", function (done) {161 mockReturn(JSON.stringify({ deployments: [] }), 200, {});162 manager.getDeployments("appName")163 .done(function (obj) {164 assert.ok(obj);165 done();166 }, rejectHandler);167 });168 it("renameDeployment handles success response", function (done) {169 mockReturn(JSON.stringify({ apps: [] }), 200, {});170 manager.renameDeployment("appName", "deploymentName", "newDeploymentName")171 .done(function (obj) {172 assert.ok(!obj);173 done();174 }, rejectHandler);175 });176 it("removeDeployment handles success response", function (done) {177 mockReturn("", 200, {});178 manager.removeDeployment("appName", "deploymentName")179 .done(function (obj) {180 assert.ok(!obj);181 done();182 }, rejectHandler);183 });184 it("getDeploymentHistory handles success response with no packages", function (done) {185 mockReturn(JSON.stringify({ history: [] }), 200);186 manager.getDeploymentHistory("appName", "deploymentName")187 .done(function (obj) {188 assert.ok(obj);189 assert.equal(obj.length, 0);190 done();191 }, rejectHandler);192 });193 it("getDeploymentHistory handles success response with two packages", function (done) {194 mockReturn(JSON.stringify({ history: [{ label: "v1" }, { label: "v2" }] }), 200);195 manager.getDeploymentHistory("appName", "deploymentName")196 .done(function (obj) {197 assert.ok(obj);198 assert.equal(obj.length, 2);199 assert.equal(obj[0].label, "v1");200 assert.equal(obj[1].label, "v2");201 done();202 }, rejectHandler);203 });204 it("getDeploymentHistory handles error response", function (done) {205 mockReturn("", 404);206 manager.getDeploymentHistory("appName", "deploymentName")207 .done(function (obj) {208 throw new Error("Call should not complete successfully");209 }, function (error) { return done(); });210 });211 it("clearDeploymentHistory handles success response", function (done) {212 mockReturn("", 204);213 manager.clearDeploymentHistory("appName", "deploymentName")214 .done(function (obj) {215 assert.ok(!obj);216 done();217 }, rejectHandler);218 });219 it("clearDeploymentHistory handles error response", function (done) {220 mockReturn("", 404);221 manager.clearDeploymentHistory("appName", "deploymentName")222 .done(function (obj) {223 throw new Error("Call should not complete successfully");224 }, function (error) { return done(); });225 });226 it("addCollaborator handles successful response", function (done) {227 mockReturn("", 201, { location: "/collaborators" });228 manager.addCollaborator("appName", "email1")229 .done(function (obj) {230 assert.ok(!obj);231 done();232 }, rejectHandler);233 });234 it("addCollaborator handles error response", function (done) {235 mockReturn("", 404, {});236 manager.addCollaborator("appName", "email1")237 .done(function (obj) {238 throw new Error("Call should not complete successfully");239 }, function (error) { return done(); });240 });241 it("getCollaborators handles success response with no collaborators", function (done) {242 mockReturn(JSON.stringify({ collaborators: {} }), 200);243 manager.getCollaborators("appName")244 .done(function (obj) {245 assert.ok(obj);246 assert.equal(Object.keys(obj).length, 0);247 done();248 }, rejectHandler);249 });250 it("getCollaborators handles success response with multiple collaborators", function (done) {251 mockReturn(JSON.stringify({252 collaborators: {253 "email1": { permission: "Owner", isCurrentAccount: true },254 "email2": { permission: "Collaborator", isCurrentAccount: false }255 }256 }), 200);257 manager.getCollaborators("appName")258 .done(function (obj) {259 assert.ok(obj);260 assert.equal(obj["email1"].permission, "Owner");261 assert.equal(obj["email2"].permission, "Collaborator");262 done();263 }, rejectHandler);264 });265 it("removeCollaborator handles success response", function (done) {266 mockReturn("", 200, {});267 manager.removeCollaborator("appName", "email1")268 .done(function (obj) {269 assert.ok(!obj);270 done();271 }, rejectHandler);272 });273 it("patchRelease handles success response", function (done) {274 mockReturn(JSON.stringify({ package: { description: "newDescription" } }), 200);275 manager.patchRelease("appName", "deploymentName", "label", { description: "newDescription" })276 .done(function (obj) {277 assert.ok(!obj);278 done();279 }, rejectHandler);280 });281 it("patchRelease handles error response", function (done) {282 mockReturn("", 400);283 manager.patchRelease("appName", "deploymentName", "label", {})284 .done(function (obj) {285 throw new Error("Call should not complete successfully");286 }, function (error) { return done(); });287 });288 it("promote handles success response", function (done) {289 mockReturn(JSON.stringify({ package: { description: "newDescription" } }), 200);290 manager.promote("appName", "deploymentName", "newDeploymentName", { description: "newDescription" })291 .done(function (obj) {292 assert.ok(!obj);293 done();294 }, rejectHandler);295 });296 it("promote handles error response", function (done) {297 mockReturn("", 400);298 manager.promote("appName", "deploymentName", "newDeploymentName", { rollout: 123 })299 .done(function (obj) {300 throw new Error("Call should not complete successfully");301 }, function (error) { return done(); });302 });303 it("rollback handles success response", function (done) {304 mockReturn(JSON.stringify({ package: { label: "v1" } }), 200);305 manager.rollback("appName", "deploymentName", "v1")306 .done(function (obj) {307 assert.ok(!obj);308 done();309 }, rejectHandler);310 });311 it("rollback handles error response", function (done) {312 mockReturn("", 400);313 manager.rollback("appName", "deploymentName", "v1")314 .done(function (obj) {315 throw new Error("Call should not complete successfully");316 }, function (error) { return done(); });317 });318});319// Helper method that is used everywhere that an assert.fail() is needed in a promise handler320function rejectHandler(val) {321 assert.fail();322}323// Wrapper for superagent-mock that abstracts away information not needed for SDK tests324function mockReturn(bodyText, statusCode, header) {325 if (header === void 0) { header = {}; }326 require("superagent-mock")(request, [{327 pattern: "http://localhost/(\\w+)/?",328 fixtures: function (match, params) {329 var isOk = statusCode >= 200 && statusCode < 300;330 if (!isOk) {...

Full Screen

Full Screen

animateCss.spec.js

Source:animateCss.spec.js Github

copy

Full Screen

...43 });44 describe('[addClass]', function() {45 it('should not trigger an animation if the class doesn\'t exist',46 inject(function($animateCss) {47 $animateCss(element, { addClass: 'something-fake' }).start().done(doneSpy);48 triggerAnimationStartFrame();49 assertHasClass(element, 'something-fake');50 expect(doneSpy).toHaveBeenCalled();51 }));52 it('should not trigger an animation if the class doesn\'t contain a transition value or a keyframe value',53 inject(function($animateCss) {54 ss.addRule('.something-real', 'background-color:orange');55 $animateCss(element, { addClass: 'something-real' }).start().done(doneSpy);56 triggerAnimationStartFrame();57 assertHasClass(element, 'something-real');58 expect(doneSpy).toHaveBeenCalled();59 }));60 it('should trigger an animation if a transition is detected on the class that is being added',61 inject(function($animateCss) {62 ss.addRule('.something-shiny', 'transition:0.5s linear all; background-color: gold;');63 $animateCss(element, { addClass: 'something-shiny' }).start().done(doneSpy);64 triggerAnimationStartFrame();65 expect(doneSpy).not.toHaveBeenCalled();66 moveAnimationClock(1);67 expect(doneSpy).toHaveBeenCalled();68 }));69 it('should trigger an animation if a keyframe is detected on the class that is being added',70 inject(function($animateCss) {71 ss.addRule('.something-spinny', '-webkit-animation: 0.5s rotate linear; animation: 0.5s rotate linear;');72 $animateCss(element, { addClass: 'something-spinny' }).start().done(doneSpy);73 triggerAnimationStartFrame();74 expect(doneSpy).not.toHaveBeenCalled();75 moveAnimationClock(1);76 expect(doneSpy).toHaveBeenCalled();77 }));78 it('should trigger an animation if both a transition and keyframe is detected on the class that is being added and choose the max duration value',79 inject(function($animateCss) {80 ss.addRule('.something-shiny', 'transition:1.5s linear all; background-color: gold;');81 ss.addRule('.something-spinny', '-webkit-animation: 0.5s rotate linear; animation: 0.5s rotate linear;');82 $animateCss(element, { addClass: 'something-spinny something-shiny' }).start().done(doneSpy);83 triggerAnimationStartFrame();84 expect(doneSpy).not.toHaveBeenCalled();85 moveAnimationClock(1.5);86 expect(doneSpy).toHaveBeenCalled();87 }));88 it('should trigger an animation if a non-animatable class is added with a duration property',89 inject(function($animateCss) {90 ss.addRule('.something-boring', 'border:20px solid red;');91 $animateCss(element, {92 addClass: 'something-boring',93 duration: 294 }).start().done(doneSpy);95 triggerAnimationStartFrame();96 expect(doneSpy).not.toHaveBeenCalled();97 moveAnimationClock(2);98 expect(doneSpy).toHaveBeenCalled();99 }));100 });101 describe('[removeClass]', function() {102 it('should not trigger an animation if the animatable className is removed',103 inject(function($animateCss) {104 element.addClass(removeClassVal);105 $animateCss(element, {106 removeClass: removeClassVal107 }).start().done(doneSpy);108 triggerAnimationStartFrame();109 assertHasClass(element, removeClassVal, true);110 }));111 it('should trigger an animation if the element contains a transition already when the class is removed',112 inject(function($animateCss) {113 element.addClass(removeClassVal);114 element.addClass('something-to-remove');115 $animateCss(element, {116 removeClass: 'something-to-remove'117 }).start().done(doneSpy);118 triggerAnimationStartFrame();119 expect(doneSpy).not.toHaveBeenCalled();120 moveAnimationClock(0.5);121 expect(doneSpy).toHaveBeenCalled();122 }));123 it('should trigger an animation if the element contains a keyframe already when the class is removed',124 inject(function($animateCss) {125 ss.addRule('.something-that-spins', '-webkit-animation: 0.5s rotate linear; animation: 0.5s rotate linear;');126 element.addClass('something-that-spins');127 element.addClass('something-to-remove');128 $animateCss(element, {129 removeClass: 'something-to-remove'130 }).start().done(doneSpy);131 triggerAnimationStartFrame();132 expect(doneSpy).not.toHaveBeenCalled();133 moveAnimationClock(0.5);134 expect(doneSpy).toHaveBeenCalled();135 }));136 it('should still perform an animation if an animatable class is removed, but a [duration] property is used',137 inject(function($animateCss) {138 ss.addRule('.something-that-is-hidden', 'transition:0.5s linear all; opacity:0;');139 element.addClass('something-that-spins');140 $animateCss(element, {141 removeClass: 'something-that-is-hidden',142 duration: 0.5143 }).start().done(doneSpy);144 triggerAnimationStartFrame();145 expect(doneSpy).not.toHaveBeenCalled();146 moveAnimationClock(0.5);147 expect(doneSpy).toHaveBeenCalled();148 }));149 });150 describe('[transitionStyle]', function() {151 it('should not trigger an animation if the property is the only thing property',152 inject(function($animateCss) {153 $animateCss(element, {154 transitionStyle: '3s linear all'155 }).start().done(doneSpy);156 triggerAnimationStartFrame();157 expect(doneSpy).toHaveBeenCalled();158 }));159 it('should apply the provided porperty to the animation if there are [toStyles] used',160 inject(function($animateCss) {161 $animateCss(element, {162 transitionStyle: '3s linear all',163 to: toStyles164 }).start().done(doneSpy);165 triggerAnimationStartFrame();166 expect(doneSpy).not.toHaveBeenCalled();167 moveAnimationClock(3);168 expect(doneSpy).toHaveBeenCalled();169 }));170 it('should apply the provided porperty to the animation if there are [addClass] used',171 inject(function($animateCss) {172 ss.addRule('.boring-class', 'border:20px solid red;');173 $animateCss(element, {174 transitionStyle: '3s linear all',175 addClass: 'boring-class'176 }).start().done(doneSpy);177 triggerAnimationStartFrame();178 expect(doneSpy).not.toHaveBeenCalled();179 moveAnimationClock(3);180 expect(doneSpy).toHaveBeenCalled();181 }));182 it('should apply the provided porperty to the animation if there are [removeClass] used',183 inject(function($animateCss) {184 ss.addRule('.boring-class', 'border:20px solid red;');185 element.addClass('boring-class');186 $animateCss(element, {187 transitionStyle: '3s linear all',188 removeClass: 'boring-class'189 }).start().done(doneSpy);190 triggerAnimationStartFrame();191 expect(doneSpy).not.toHaveBeenCalled();192 moveAnimationClock(3);193 expect(doneSpy).toHaveBeenCalled();194 }));195 });196 describe('[from]', function() {197 it('should not trigger an animation to run when only a [from] property is passed in',198 inject(function($animateCss) {199 $animateCss(element, {200 from: fromStyles201 }).start().done(doneSpy);202 triggerAnimationStartFrame();203 expect(doneSpy).toHaveBeenCalled();204 }));205 it('should not trigger an animation to run when a [from] and a [duration] property are passed in',206 inject(function($animateCss) {207 $animateCss(element, {208 from: fromStyles,209 duration: 1210 }).start().done(doneSpy);211 triggerAnimationStartFrame();212 expect(doneSpy).toHaveBeenCalled();213 }));214 it('should apply the styles as soon as the animation is called',215 inject(function($animateCss) {216 var animator = $animateCss(element, {217 from: fromStyles218 });219 assertStyle(element, fromStyles);220 }));221 });222 describe('[to]', function() {223 it('should not trigger an animation to run when only a [to] property is passed in',224 inject(function($animateCss) {225 $animateCss(element, {226 to: toStyles227 }).start().done(doneSpy);228 triggerAnimationStartFrame();229 expect(doneSpy).toHaveBeenCalled();230 }));231 it('should trigger an animation to run when both a [to] and a [duration] property are passed in',232 inject(function($animateCss) {233 $animateCss(element, {234 to: toStyles,235 duration: 1236 }).start().done(doneSpy);237 triggerAnimationStartFrame();238 expect(doneSpy).not.toHaveBeenCalled();239 moveAnimationClock(1);240 expect(doneSpy).toHaveBeenCalled();241 }));242 it('should apply the styles right after the next frame',243 inject(function($animateCss) {244 $animateCss(element, {245 to: toStyles246 }).start().done(doneSpy);247 triggerAnimationStartFrame();248 assertStyle(element, toStyles);249 }));250 });251 describe('[from] and [to]', function() {252 it('should not trigger an animation if [duration] is not passed in',253 inject(function($animateCss) {254 $animateCss(element, {255 from: fromStyles,256 to: toStyles257 }).start().done(doneSpy);258 triggerAnimationStartFrame();259 expect(doneSpy).toHaveBeenCalled();260 }));261 it('should trigger an animation if [duration] is passed in',262 inject(function($animateCss) {263 $animateCss(element, {264 from: fromStyles,265 to: toStyles,266 duration: 1267 }).start().done(doneSpy);268 triggerAnimationStartFrame();269 expect(doneSpy).not.toHaveBeenCalled();270 moveAnimationClock(1);271 expect(doneSpy).toHaveBeenCalled();272 }));273 it('should trigger an animation if detected from the provided [addClass] class value',274 inject(function($animateCss) {275 $animateCss(element, {276 from: fromStyles,277 to: toStyles,278 addClass: addClassVal279 }).start().done(doneSpy);280 assertStyle(element, fromStyles);281 triggerAnimationStartFrame();282 assertStyle(element, toStyles);283 expect(doneSpy).not.toHaveBeenCalled();284 moveAnimationClock(1);285 expect(doneSpy).toHaveBeenCalled();286 }));287 it('should trigger an animation if detected from the provided [removeClass] class value',288 inject(function($animateCss) {289 element.addClass(removeClassVal + ' something-else-to-remove');290 $animateCss(element, {291 from: fromStyles,292 to: toStyles,293 removeClass: 'something-else-to-remove'294 }).start().done(doneSpy);295 assertStyle(element, fromStyles);296 triggerAnimationStartFrame();297 assertStyle(element, toStyles);298 expect(doneSpy).not.toHaveBeenCalled();299 moveAnimationClock(1);300 expect(doneSpy).toHaveBeenCalled();301 }));302 });303 describe('[duration]', function() {304 it('should not apply a duration if it is the only property used',305 inject(function($animateCss) {306 element.addClass(removeClassVal + ' something-else-to-remove');307 $animateCss(element, {308 duration: 2309 }).start().done(doneSpy);310 triggerAnimationStartFrame();311 expect(doneSpy).toHaveBeenCalled();312 }));313 it('should apply a duration as an inline transition-duration style',314 inject(function($animateCss) {315 element.addClass(removeClassVal + ' something-else-to-remove');316 $animateCss(element, {317 duration: 2,318 to: toStyles319 }).start().done(doneSpy);320 triggerAnimationStartFrame();321 assertStyle(element, 'transition-duration', '2s');322 }));323 it('should apply a duration as an inline animation-duration style if only keyframes are used',324 inject(function($animateCss) {325 element.addClass(removeClassVal + ' something-else-to-remove');326 $animateCss(element, {327 keyframeStyle: '1s rotate linear',328 duration: 2329 }).start().done(doneSpy);330 triggerAnimationStartFrame();331 assertStyle(element, 'animation-duration', '2s');332 }));333 });334 function assertHasClass(element, className, not) {335 expect(element.hasClass(className)).toBe(!not);336 }337 function assertStyle(element, prop, val, not) {338 var node = element[0];339 var webKit = '-webkit-';340 var otherVal;341 var otherAssertion;342 var key;343 if (typeof prop === 'string') {...

Full Screen

Full Screen

pic-router-test.js

Source:pic-router-test.js Github

copy

Full Screen

...39 .field('desc', examplePic.desc)40 .attach('file', examplePic.file)41 .end((err, res) => {42 if (err)43 return done(err)44 expect(res.status).to.equal(200)45 expect(res.body.name).to.equal(examplePic.name)46 expect(res.body.desc).to.equal(examplePic.desc)47 expect(res.body.imageURI).to.equal(awsMocks.uploadMock.Location)48 expect(res.body.objectKey).to.equal(awsMocks.uploadMock.Key)49 done()50 })51 })52 })53 describe('with no name', function(){54 before(done => galleryMock.call(this, done))55 it('should respond with status 400', done => {56 request.post(`${url}/api/gallery/${this.tempGallery._id}/pic`)57 .set({Authorization: `Bearer ${this.tempToken}`})58 .field('desc', examplePic.desc)59 .attach('file', examplePic.file)60 .end((err, res) => {61 expect(res.status).to.equal(400)62 expect(res.text).to.equal('BadRequestError')63 done()64 })65 })66 })67 describe('with no desc', function(){68 before(done => galleryMock.call(this, done))69 it('should respond with status 400', done => {70 request.post(`${url}/api/gallery/${this.tempGallery._id}/pic`)71 .set({Authorization: `Bearer ${this.tempToken}`})72 .field('name', examplePic.name)73 .attach('file', examplePic.file)74 .end((err, res) => {75 expect(res.status).to.equal(400)76 expect(res.text).to.equal('BadRequestError')77 done()78 })79 })80 })81 describe('with no file', function(){82 before(done => galleryMock.call(this, done))83 it('should respond with status 400', done => {84 request.post(`${url}/api/gallery/${this.tempGallery._id}/pic`)85 .set({Authorization: `Bearer ${this.tempToken}`})86 .field('desc', examplePic.desc)87 .field('name', examplePic.name)88 .end((err, res) => {89 expect(res.status).to.equal(400)90 expect(res.text).to.equal('BadRequestError')91 done()92 })93 })94 })95 describe('with invalid token', function(){96 before(done => galleryMock.call(this, done))97 it('should respond with status 401', done => {98 request.post(`${url}/api/gallery/${this.tempGallery._id}/pic`)99 .set({Authorization: `Bearer ${this.tempToken}bad`})100 .field('desc', examplePic.desc)101 .field('name', examplePic.name)102 .attach('file', examplePic.file)103 .end((err, res) => {104 expect(res.status).to.equal(401)105 expect(res.text).to.equal('UnauthorizedError')106 done()107 })108 })109 })110 describe('with invalid galleryID', function(){111 before(done => galleryMock.call(this, done))112 it('should respond with status 404', done => {113 request.post(`${url}/api/gallery/${this.tempGallery._id}bad/pic`)114 .set({Authorization: `Bearer ${this.tempToken}`})115 .field('desc', examplePic.desc)116 .field('name', examplePic.name)117 .attach('file', examplePic.file)118 .end((err, res) => {119 expect(res.status).to.equal(404)120 expect(res.text).to.equal('NotFoundError')121 done()122 })123 })124 })125 })126 describe('testing DELETE /api/gallery/:gallryID/pic/:picID', function(){127 describe('with valid token and ids', function(){128 before(done => picMock.call(this, done))129 it('should respond with status 204', done => {130 request.delete(`${url}/api/gallery/${this.tempGallery._id}/pic/${this.tempPic._id}`)131 .set({Authorization: `Bearer ${this.tempToken}`})132 .end((err, res) => {133 if (err)134 return done(err)135 expect(res.status).to.equal(204)136 done()137 })138 })139 })140 describe('with invalid token', function(){141 before(done => picMock.call(this, done))142 it('should respond with status 401', done => {143 request.delete(`${url}/api/gallery/${this.tempGallery._id}/pic/${this.tempPic._id}`)144 .set({Authorization: `Bearer ${this.tempToken}bad`})145 .end((err, res) => {146 expect(res.status).to.equal(401)147 expect(res.text).to.equal('UnauthorizedError')148 done()149 })150 })151 })152 describe('should resond with 401', function(){153 before(done => picMock.call(this, done))154 before(done => userMock.call(this, done))155 it('should respond with status 401', done => {156 request.delete(`${url}/api/gallery/${this.tempGallery._id}/pic/${this.tempPic._id}`)157 .set({Authorization: `Bearer ${this.tempToken}`})158 .end((err, res) => {159 expect(res.status).to.equal(401)160 done()161 })162 })163 })164 describe('no auth header', function(){165 before(done => picMock.call(this, done))166 it('should respond with status 400', done => {167 request.delete(`${url}/api/gallery/${this.tempGallery._id}/pic/${this.tempPic._id}`)168 .end((err, res) => {169 expect(res.status).to.equal(400)170 expect(res.text).to.equal('BadRequestError')171 done()172 })173 })174 })175 describe('with no bearer auth', function(){176 before(done => picMock.call(this, done))177 it('should respond with status 400', done => {178 request.delete(`${url}/api/gallery/${this.tempGallery._id}/pic/${this.tempPic._id}`)179 .set({Authorization: 'lul this is bad'})180 .end((err, res) => {181 expect(res.status).to.equal(400)182 expect(res.text).to.equal('BadRequestError')183 done()184 })185 })186 })187 describe('with invalid galleryID', function(){188 before(done => picMock.call(this, done))189 it('should respond with status 404', done => {190 request.delete(`${url}/api/gallery/${this.tempGallery._id}bad/pic/${this.tempPic._id}`)191 .set({Authorization: `Bearer ${this.tempToken}`})192 .end((err, res) => {193 expect(res.status).to.equal(404)194 expect(res.text).to.equal('NotFoundError')195 done()196 })197 })198 })199 describe('with invalid picID', function(){200 before(done => picMock.call(this, done))201 it('should respond with status 404', done => {202 request.delete(`${url}/api/gallery/${this.tempGallery._id}/pic/${this.tempPic._id}bad`)203 .set({Authorization: `Bearer ${this.tempToken}`})204 .end((err, res) => {205 expect(res.status).to.equal(404)206 expect(res.text).to.equal('NotFoundError')207 done()208 })209 })210 })211 })212 describe('testing GET /api/public/pic', function(){213 describe('with valid request', function(){214 before(done => mockManyPics.call(this, 100, done))215 it ('should return an array of pics', done => {216 request.get(`${url}/api/public/pic`)217 .end((err, res) => {218 if (err)219 return done(err)220 expect(res.status).to.equal(200)221 expect(Array.isArray(res.body)).to.equal(true)222 expect(res.body.length).to.equal(50)223 for(let i=0; i<res.body.length; i++){224 expect(res.body[i]._id.toString()).to.equal(this.tempPics[i]._id.toString())225 }226 done()227 })228 })229 })230 describe('with ?name=do', function(){231 before(done => mockManyPics.call(this, 100, done))232 it ('should return an array of pics', done => {233 request.get(`${url}/api/public/pic?name=do`)234 .end((err, res) => {235 if (err)236 return done(err)237 expect(res.status).to.equal(200)238 expect(Array.isArray(res.body)).to.equal(true)239 let fuzzy = fuzzyRegex('do')240 for(let i=0; i<res.body.length; i++){241 expect(res.body[i].name).to.match(fuzzy)242 }243 done()244 })245 })246 })247 describe('with ?desc=lorem', function(){248 before(done => mockManyPics.call(this, 50, done))249 it ('should return an array of pics', done => {250 request.get(`${url}/api/public/pic?desc=lorem`)251 .end((err, res) => {252 if (err)253 return done(err)254 expect(res.status).to.equal(200)255 expect(Array.isArray(res.body)).to.equal(true)256 let fuzzy = fuzzyRegex('lorem')257 for(let i=0; i<res.body.length; i++){258 expect(res.body[i].desc).to.match(fuzzy)259 }260 done()261 })262 })263 })264 describe('with ?desc=lorem%20ip', function(){265 before(done => mockManyPics.call(this, 50, done))266 it ('should return an array of pics', done => {267 request.get(`${url}/api/public/pic?desc=lorem%20ip`)268 .end((err, res) => {269 if (err)270 return done(err)271 expect(res.status).to.equal(200)272 expect(Array.isArray(res.body)).to.equal(true)273 let fuzzy = fuzzyRegex('lorem ip')274 for(let i=0; i<res.body.length; i++){275 expect(res.body[i].desc).to.match(fuzzy)276 }277 done()278 })279 })280 })281 describe('with ?desc=lo&name=do', function(){282 before(done => mockManyPics.call(this, 100, done))283 it ('should return an array of pics', done => {284 request.get(`${url}/api/public/pic?desc=lorem&name=do`)285 .end((err, res) => {286 if (err)287 return done(err)288 expect(res.status).to.equal(200)289 expect(Array.isArray(res.body)).to.equal(true)290 let fuzzyName = fuzzyRegex('do')291 let fuzzyDesc = fuzzyRegex('lo')292 for(let i=0; i<res.body.length; i++){293 expect(res.body[i].name).to.match(fuzzyName)294 expect(res.body[i].desc).to.match(fuzzyDesc)295 }296 done()297 })298 })299 })300 describe('with ?username=lop', function(){301 let options = {302 users: 20,303 gallerys: 2,304 pics: 5,305 }306 before(done => mockManyEverything.call(this, options, done))307 //before(function(done){308 //this.timeout(5000)309 //mockManyEverything.call(this, 20, function(err){310 //if(err) return done(err)311 //done()312 //})313 //})314 it ('should return an array of pics', done => {315 request.get(`${url}/api/public/pic?username=lop`)316 .end((err, res) => {317 if (err)318 return done(err)319 expect(res.status).to.equal(200)320 expect(Array.isArray(res.body)).to.equal(true)321 let fuzzyuser = fuzzyRegex('lo')322 console.log('pics in response', res.body.length)323 for(let i=0; i<res.body.length; i++){324 expect(res.body[i].username).to.match(fuzzyuser)325 }326 done()327 })328 })329 })330 })331 describe('testing GET /api/pic', function(){332 describe('with valid token', function(){333 before(done => mockManyPics.call(this, 100, done))334 it ('should return an array of pics', done => {335 request.get(`${url}/api/pic`)336 .set({Authorization: `Bearer ${this.tempToken}`})337 .end((err, res) => {338 if (err)339 return done(err)340 expect(res.status).to.equal(200)341 expect(Array.isArray(res.body)).to.equal(true)342 for(let i=0; i<res.body.length; i++){343 expect(res.body[i].name).to.equal(this.tempPics[i].name)344 }345 done()346 })347 })348 })349 describe('with invalid token', function(){350 before(done => mockManyPics.call(this, 100, done))351 it ('should return an array of pics', done => {352 request.get(`${url}/api/pic`)353 .set({Authorization: `Bearer ${this.tempToken}bad`})354 .end((err, res) => {355 expect(res.status).to.equal(401)356 done()357 })358 })359 })360 361 describe('with ?name=do', function(){362 before(done => mockManyPics.call(this, 100, done))363 it ('should return an array of pics', done => {364 request.get(`${url}/api/pic?name=do`)365 .set({Authorization: `Bearer ${this.tempToken}`})366 .end((err, res) => {367 expect(res.status).to.equal(200)368 let fuzzyName = fuzzyRegex('do')369 for(let i=0; i<res.body.length; i++){370 expect(res.body[i].name).to.match(fuzzyName)371 }372 done()373 })374 })375 })376 describe('with ?desc=do', function(){377 before(done => mockManyPics.call(this, 10, done))378 it ('should return an array of pics', done => {379 request.get(`${url}/api/pic?desc=do`)380 .set({Authorization: `Bearer ${this.tempToken}`})381 .end((err, res) => {382 expect(res.status).to.equal(200)383 let fuzzyName = fuzzyRegex('do')384 for(let i=0; i<res.body.length; i++){385 expect(res.body[i].desc).to.match(fuzzyName)386 }387 done()388 })389 })390 })391 })...

Full Screen

Full Screen

runnable.spec.js

Source:runnable.spec.js Github

copy

Full Screen

...121 });122 test.run(function(err){123 calls.should.equal(1);124 test.duration.should.be.type('number');125 done(err);126 })127 })128 })129 describe('when an exception is thrown', function(){130 it('should invoke the callback', function(done){131 var calls = 0;132 var test = new Runnable('foo', function(){133 ++calls;134 throw new Error('fail');135 });136 test.run(function(err){137 calls.should.equal(1);138 err.message.should.equal('fail');139 done();140 })141 })142 })143 describe('when an exception is thrown and is allowed to remain uncaught', function(){144 it('throws an error when it is allowed', function(done) {145 var test = new Runnable('foo', function(){146 throw new Error('fail');147 });148 test.allowUncaught = true;149 function fail() {150 test.run(function(err) {});151 }152 fail.should.throw('fail');153 done();154 })155 })156 })157 describe('when timeouts are disabled', function() {158 it('should not error with timeout', function(done) {159 var test = new Runnable('foo', function(done){160 setTimeout(process.nextTick.bind(undefined, done), 2);161 });162 test.timeout(1);163 test.enableTimeouts(false);164 test.run(done);165 });166 });167 describe('when async', function(){168 describe('without error', function(){169 it('should invoke the callback', function(done){170 var calls = 0;171 var test = new Runnable('foo', function(done){172 process.nextTick(done);173 });174 test.run(done);175 })176 })177 describe('when the callback is invoked several times', function(){178 describe('without an error', function(){179 it('should emit a single "error" event', function(done){180 var calls = 0;181 var errCalls = 0;182 var test = new Runnable('foo', function(done){183 process.nextTick(done);184 process.nextTick(done);185 process.nextTick(done);186 process.nextTick(done);187 });188 test.on('error', function(err){189 ++errCalls;190 err.message.should.equal('done() called multiple times');191 calls.should.equal(1);192 errCalls.should.equal(1);193 done();194 });195 test.run(function(){196 ++calls;197 });198 })199 })200 describe('with an error', function(){201 it('should emit a single "error" event', function(done){202 var calls = 0;203 var errCalls = 0;204 var test = new Runnable('foo', function(done){205 done(new Error('fail'));206 process.nextTick(done);207 done(new Error('fail'));208 process.nextTick(done);209 process.nextTick(done);210 });211 test.on('error', function(err){212 ++errCalls;213 err.message.should.equal('fail');214 calls.should.equal(1);215 errCalls.should.equal(1);216 done();217 });218 test.run(function(){219 ++calls;220 });221 })222 })223 })224 describe('when an exception is thrown', function(){225 it('should invoke the callback', function(done){226 var calls = 0;227 var test = new Runnable('foo', function(done){228 throw new Error('fail');229 process.nextTick(done);230 });231 test.run(function(err){232 err.message.should.equal('fail');233 done();234 });235 })236 it('should not throw its own exception if passed a non-object', function (done) {237 var test = new Runnable('foo', function(done) {238 throw null;239 process.nextTick(done);240 });241 test.run(function(err) {242 err.message.should.equal(utils.undefinedError().message);243 done();244 })245 });246 })247 describe('when an exception is thrown and is allowed to remain uncaught', function(){248 it('throws an error when it is allowed', function(done) {249 var test = new Runnable('foo', function(done){250 throw new Error('fail');251 process.nextTick(done);252 });253 test.allowUncaught = true;254 function fail() {255 test.run(function(err) {});256 }257 fail.should.throw('fail');258 done();259 })260 })261 describe('when an error is passed', function(){262 it('should invoke the callback', function(done){263 var calls = 0;264 var test = new Runnable('foo', function(done){265 done(new Error('fail'));266 });267 test.run(function(err){268 err.message.should.equal('fail');269 done();270 });271 })272 })273 describe('when done() is invoked with a non-Error object', function(){274 it('should invoke the callback', function(done){275 var test = new Runnable('foo', function(done){276 done({ error: 'Test error' });277 });278 test.run(function(err){279 err.message.should.equal('done() invoked with non-Error: {"error":"Test error"}');280 done();281 });282 })283 })284 describe('when done() is invoked with a string', function(){285 it('should invoke the callback', function(done){286 var test = new Runnable('foo', function(done){287 done('Test error');288 });289 test.run(function(err){290 err.message.should.equal('done() invoked with non-Error: Test error');291 done();292 });293 })294 })295 it('should allow updating the timeout', function(done){296 var callCount = 0;297 var increment = function() {298 callCount++;299 };300 var test = new Runnable('foo', function(done){301 setTimeout(increment, 1);302 setTimeout(increment, 100);303 });304 test.timeout(10);305 test.run(function(err){306 err.should.be.ok();307 callCount.should.equal(1);308 done();309 });310 })311 it('should allow a timeout of 0')312 })313 describe('when fn returns a promise', function(){314 describe('when the promise is fulfilled with no value', function(){315 var fulfilledPromise = {316 then: function (fulfilled, rejected) {317 process.nextTick(fulfilled);318 }319 };320 it('should invoke the callback', function(done){321 var test = new Runnable('foo', function(){322 return fulfilledPromise;323 });324 test.run(done);325 })326 })327 describe('when the promise is fulfilled with a value', function(){328 var fulfilledPromise = {329 then: function (fulfilled, rejected) {330 process.nextTick(function () {331 fulfilled({});332 });333 }334 };335 it('should invoke the callback', function(done){336 var test = new Runnable('foo', function(){337 return fulfilledPromise;338 });339 test.run(done);340 })341 })342 describe('when the promise is rejected', function(){343 var expectedErr = new Error('fail');344 var rejectedPromise = {345 then: function (fulfilled, rejected) {346 process.nextTick(function () {347 rejected(expectedErr);348 });349 }350 };351 it('should invoke the callback', function(done){352 var test = new Runnable('foo', function(){353 return rejectedPromise;354 });355 test.run(function(err){356 err.should.equal(expectedErr);357 done();358 });359 })360 })361 describe('when the promise is rejected without a reason', function(){362 var expectedErr = new Error('Promise rejected with no or falsy reason');363 var rejectedPromise = {364 then: function (fulfilled, rejected) {365 process.nextTick(function () {366 rejected();367 });368 }369 };370 it('should invoke the callback', function(done){371 var test = new Runnable('foo', function(){372 return rejectedPromise;373 });374 test.run(function(err){375 err.should.eql(expectedErr);376 done();377 });378 })379 })380 describe('when the promise takes too long to settle', function(){381 var foreverPendingPromise = {382 then: function () { }383 };384 it('should give the timeout error', function(done){385 var test = new Runnable('foo', function(){386 return foreverPendingPromise;387 });388 test.timeout(10);389 test.run(function(err){390 err.should.be.ok();391 done();392 });393 })394 })395 })396 describe('when fn returns a non-promise', function(){397 it('should invoke the callback', function(done){398 var test = new Runnable('foo', function(){399 return { then: "i ran my tests" };400 });401 test.run(done);402 })403 })404 })405})

Full Screen

Full Screen

recipe-router-test.js

Source:recipe-router-test.js Github

copy

Full Screen

...41 exampleProfile.userID = this.tempUser._id.toString();42 new Profile(exampleProfile).save()43 .then( profile => {44 this.tempProfile = profile;45 done();46 })47 .catch(done);48 })49 .catch(done);50 });51 afterEach( done => {52 Promise.all([53 User.remove({}),54 Profile.remove({})55 ])56 .then( () => {57 delete exampleProfile.userID;58 done();59 })60 .catch(done);61 });62 describe('POST /api/recipe', () => {63 afterEach(done => {64 Recipe.remove({})65 .then( () => {66 delete exampleRecipe.profileID;67 done();68 })69 .catch(done);70 });71 describe('with a valid body', () => {72 it('should return a token', done => {73 request.post(`${url}/api/recipe`)74 .set( { Authorization: `Bearer ${this.tempToken}` } )75 .send(exampleRecipe)76 .end((err, res) => {77 if(err) return done(err);78 let date = new Date(res.body.created).toString();79 expect(res.status).to.equal(200);80 expect(res.body.recipe.ingredients.toString()).to.equal(exampleRecipe.ingredients.toString());81 expect(res.body.recipe.instructions).to.equal(exampleRecipe.instructions);82 expect(res.body.recipe.categories.toString()).to.equal(exampleRecipe.categories.toString());83 expect(res.body.recipe.recipeName).to.equal(exampleRecipe.recipeName);84 expect(res.body.profile.recipes[0]).to.equal(res.body.recipe._id);85 expect(date).to.not.equal('invalid date');86 done();87 });88 });89 });90 describe('with an invalid body', () => {91 it('should return a 400 error', done => {92 request.post(`${url}/api/recipe`)93 .set( { Authorization: `Bearer ${this.tempToken}` } )94 .end((err, res) => {95 expect(err.status).to.equal(400);96 expect(res.text).to.equal('request body expected');97 done();98 });99 });100 });101 describe('with an invalid token', () => {102 it('should return 401 error', done => {103 request.post(`${url}/api/profile`)104 .send(exampleProfile)105 .end((err, res) => {106 expect(err.status).to.equal(401);107 expect(res.text).to.equal('authorization header required');108 done();109 });110 });111 });112 });113 describe('GET /api/recipe/:id', () => {114 beforeEach( done => {115 exampleRecipe.profileID = this.tempProfile._id;116 new Recipe(exampleRecipe).save()117 .then( recipe => {118 this.tempRecipe = recipe;119 done();120 })121 .catch(done);122 });123 afterEach( done => {124 Recipe.remove({})125 .then( () => {126 delete exampleRecipe.profileID;127 done();128 })129 .catch(done);130 });131 describe('with a valid recipe id', () => {132 it('should return a recipe', done => {133 request.get(`${url}/api/recipe/${this.tempRecipe._id.toString()}`)134 .end((err, res) => {135 if (err) return done(err);136 expect(res.status).to.equal(200);137 expect(res.body.ingredients.toString()).to.equal(exampleRecipe.ingredients.toString());138 expect(res.body.instructions).to.equal(exampleRecipe.instructions);139 expect(res.body.categories.toString()).to.equal(exampleRecipe.categories.toString());140 expect(res.body.recipeName).to.equal(exampleRecipe.recipeName);141 done();142 });143 });144 });145 describe('without a valid recipe id', () => {146 it('should return a 404 error', done => {147 request.get(`${url}/api/recipe/alskdjf`)148 .end( err => {149 expect(err.status).to.equal(404);150 done();151 });152 });153 });154 });155 describe('GET /api/allrecipes/:profileID', () => {156 beforeEach( done => {157 exampleRecipe.profileID = this.tempProfile._id;158 new Recipe(exampleRecipe).save()159 .then( recipe => {160 this.tempRecipe = recipe;161 this.tempProfile.recipes.push(this.tempRecipe._id);162 return Profile.findByIdAndUpdate(this.tempProfile._id, { $set: {recipes: this.tempProfile.recipes } }, { new: true } );163 })164 .then( () => done())165 .catch(done);166 });167 afterEach( done => {168 Recipe.remove({})169 .then( () => {170 delete exampleRecipe.profileID;171 done();172 })173 .catch(done);174 });175 describe('with a valid profile id', () => {176 it('should return a list of recipes', done => {177 request.get(`${url}/api/allrecipes/${this.tempProfile._id.toString()}`)178 .end((err, res) => {179 if (err) return done(err);180 expect(res.status).to.equal(200);181 expect(res.body.recipes[0]._id.toString()).to.equal(this.tempRecipe._id.toString());182 expect(res.body.recipes[0].profileID.toString()).to.equal(this.tempRecipe.profileID.toString());183 expect(res.body.recipes[0].categories.toString()).to.equal(this.tempRecipe.categories.toString());184 expect(res.body.recipes[0].ingredients.toString()).to.equal(this.tempRecipe.ingredients.toString());185 expect(res.body.recipes[0].instructions).to.equal(this.tempRecipe.instructions);186 expect(res.body.recipes[0].recipeName).to.equal(this.tempRecipe.recipeName);187 expect(res.body.recipes.length).to.equal(1);188 done();189 });190 });191 });192 describe('without a valid user id', () => {193 it('should return a 404 error', done => {194 request.get(`${url}/api/allrecipes/alskdjf`)195 .end( err => {196 expect(err.status).to.equal(404);197 done();198 });199 });200 });201 describe('without a valid profile id', () => {202 it('should return a 404 error', done => {203 request.get(`${url}/api/profile/n0taval1d1d00p5`)204 .set( { Authorization: `Bearer ${this.tempToken}` } )205 .end( err => {206 expect(err.status).to.equal(404);207 done();208 });209 });210 });211 });212 describe('GET /api/allrecipes', () => {213 beforeEach( done => {214 exampleRecipe.profileID = this.tempProfile._id;215 new Recipe(exampleRecipe).save()216 .then( recipe => {217 this.tempRecipe = recipe;218 this.tempProfile.recipes.push(this.tempRecipe._id);219 return Profile.findByIdAndUpdate(this.tempProfile._id, { $set: {recipes: this.tempProfile.recipes } }, { new: true } );220 })221 .then( () => done())222 .catch(done);223 });224 afterEach( done => {225 Recipe.remove({})226 .then( () => {227 delete exampleRecipe.profileID;228 done();229 })230 .catch(done);231 });232 describe('with a valid path', () => {233 it('should return a list of all recipes for all profiles', done => {234 request.get(`${url}/api/allrecipes`)235 .end((err, res) => {236 if (err) return done(err);237 expect(res.status).to.equal(200);238 expect(res.body[0]._id.toString()).to.equal(this.tempRecipe._id.toString());239 expect(res.body[0].profileID.toString()).to.equal(this.tempRecipe.profileID.toString());240 expect(res.body[0].categories.toString()).to.equal(this.tempRecipe.categories.toString());241 expect(res.body[0].ingredients.toString()).to.equal(this.tempRecipe.ingredients.toString());242 expect(res.body[0].instructions).to.equal(this.tempRecipe.instructions);243 expect(res.body[0].recipeName).to.equal(this.tempRecipe.recipeName);244 expect(res.body.length).to.equal(1);245 done();246 });247 });248 });249 });250 describe('PUT /api/recipe/:id', () => {251 beforeEach( done => {252 exampleRecipe.profileID = this.tempProfile._id;253 new Recipe(exampleRecipe).save()254 .then( recipe => {255 this.tempRecipe = recipe;256 done();257 })258 .catch(done);259 });260 afterEach( done => {261 Recipe.remove({})262 .then( () => {263 delete exampleRecipe.profileID;264 done();265 })266 .catch(done);267 });268 const updated = {269 ingredients: ['updated ingredient 1', 'updated ingredient 2', 'updated ingredient 3'],270 instructions: 'updated instructions'271 };272 describe('with a valid recipe id and body', () => {273 it('should return an updated recipe', done => {274 request.put(`${url}/api/recipe/${this.tempRecipe._id.toString()}`)275 .set( { Authorization: `Bearer ${this.tempToken}`} )276 .send(updated)277 .end((err, res) => {278 if (err) return done(err);279 expect(res.status).to.equal(200);280 expect(res.body.ingredients.toString()).to.equal(updated.ingredients.toString());281 expect(res.body.instructions).to.equal(updated.instructions);282 expect(res.body.recipeName).to.equal(exampleRecipe.recipeName);283 done();284 });285 });286 });287 describe('without a valid recipe id', () => {288 it('should return a 404 error', done => {289 request.put(`${url}/api/recipe/n0taval1d1d00p5`)290 .set( { Authorization: `Bearer ${this.tempToken}`} )291 .send(updated)292 .end((err, res) => {293 expect(err.status).to.equal(404);294 expect(res.text).to.equal('NotFoundError');295 done();296 });297 });298 });299 describe('without a valid body', () => {300 it('should return a 400 error', done => {301 request.put(`${url}/api/recipe/${this.tempRecipe._id}`)302 .set( { Authorization: `Bearer ${this.tempToken}`} )303 .end((err, res) => {304 expect(err.status).to.equal(400);305 expect(res.text).to.equal('nothing to update');306 done();307 });308 });309 });310 });311 describe('DELETE /api/recipe/:id', () => {312 beforeEach( done => {313 exampleRecipe.profileID = this.tempProfile._id;314 new Recipe(exampleRecipe).save()315 .then( recipe => {316 this.tempRecipe = recipe;317 this.tempProfile.recipes.push(this.tempRecipe._id);318 return Profile.findByIdAndUpdate(this.tempProfile._id, { $set: {recipes: this.tempProfile.recipes } }, { new: true } );319 })320 .then( () => done())321 .catch(done);322 });323 afterEach( done => {324 Recipe.remove({})325 .then( () => {326 delete exampleRecipe.profileID;327 done();328 })329 .catch(done);330 });331 describe('with a valid recipe id', () => {332 it('should return a 204 status', done => {333 request.delete(`${url}/api/recipe/${this.tempRecipe._id.toString()}`)334 .set( { Authorization: `Bearer ${this.tempToken}`} )335 .end((err, res) => {336 if (err) return done(err);337 expect(res.status).to.equal(204);338 Profile.findById(this.tempProfile._id)339 .then( profile => {340 expect(profile.recipes.indexOf(this.tempRecipe._id)).to.equal(-1);341 done();342 })343 .catch(done);344 });345 });346 });347 describe('without a valid recipe id', () => {348 it('should return a 404 error', done => {349 request.delete(`${url}/api/profile/n0taval1d1d00p5`)350 .set( { Authorization: `Bearer ${this.tempToken}` } )351 .end( err => {352 expect(err.status).to.equal(404);353 done();354 });355 });356 });357 });...

Full Screen

Full Screen

pokemon.js

Source:pokemon.js Github

copy

Full Screen

...13 name: 'Ivysaur',14 price: 270.5,15 stock: 8,16 }]))17 .then(done());18 describe('GET', () => {19 before(seedPkmns);20 after((done) =>21 Pokemon.destroy({ where: {} }).then(done())22 );23 it('should return an array which children have a Id property', (done) => {24 api25 .get('/pokemon/')26 .expect(200)27 .end((err, res) => {28 if (err) {29 return done(err);30 }31 expect(res.body.length).to.be.above(0);32 expect(res.body).to.have.all.property('id');33 return done();34 });35 });36 it('should return an array which children have a Name property', (done) => {37 api38 .get('/pokemon/')39 .expect(200)40 .end((err, res) => {41 if (err) {42 return done(err);43 }44 expect(res.body.length).to.be.above(0);45 expect(res.body).to.have.all.property('name');46 return done();47 });48 });49 it('should return an array which children have an Price property', (done) => {50 api51 .get('/pokemon/')52 .expect(200)53 .end((err, res) => {54 if (err) {55 return done(err);56 }57 expect(res.body.length).to.be.above(0);58 expect(res.body).to.have.all.property('price');59 return done();60 });61 });62 it('should return an array which children have an Stock property', (done) => {63 api64 .get('/pokemon/')65 .expect(200)66 .end((err, res) => {67 if (err) {68 return done(err);69 }70 expect(res.body.length).to.be.above(0);71 expect(res.body).to.have.all.property('stock');72 return done();73 });74 });75 it('should return an array which children have an updatedAt property', (done) => {76 api77 .get('/pokemon/')78 .expect(200)79 .end((err, res) => {80 if (err) {81 return done(err);82 }83 expect(res.body.length).to.be.above(0);84 expect(res.body).to.have.all.property('updatedAt');85 return done();86 });87 });88 it('should return an array which children have an createdAt property', (done) => {89 api90 .get('/pokemon/')91 .expect(200)92 .end((err, res) => {93 if (err) {94 return done(err);95 }96 expect(res.body.length).to.be.above(0);97 expect(res.body).to.have.all.property('createdAt');98 return done();99 });100 });101 it('should return an empty array when there is no content', (done) => {102 Pokemon103 .destroy({ where: {} })104 .then(() => {105 api106 .get('/pokemon/')107 .expect(200)108 .end((err, res) => {109 if (err) {110 return done(err);111 }112 expect(res.status).to.be.equal(200);113 expect(res.body.length).to.be.equal(0);114 return done();115 });116 }); // Clean the DB to simulate no content117 });118 describe('Details [GET /:id]', () => {119 before(seedPkmns);120 it('should return 404 if no record matches the Id', (done) => {121 const pkmnId = 99999;122 api123 .get(`/pokemon/${pkmnId}`)124 .expect(404)125 .end((err) => {126 if (err) {127 return done(err);128 }129 return done();130 });131 });132 it('should return the same data as the actual record', (done) => {133 Pokemon134 .findOne({ where: {} })135 .then((record) => {136 api137 .get(`/pokemon/${record.id}`)138 .expect(200)139 .end((err, res) => {140 if (err) {141 return done(err);142 }143 // Compare the equality of the objects144 expect({145 name: res.body.name,146 price: res.body.price,147 stock: res.body.stock,148 })149 .to150 .eql({151 name: record.name,152 price: record.price,153 stock: record.stock,154 });155 return done();156 });157 });158 });159 });160 });161 describe('POST', () => {162 it('should return 201 Created status code ', (done) => {163 const pkmnData = {164 name: 'Charmander',165 price: 740.6,166 stock: 15,167 };168 api169 .post('/pokemon/')170 .expect(201)171 .send(pkmnData)172 .end((err, res) => {173 if (err) {174 return done(err);175 }176 expect(res.status).to.be.equal(201);177 return done();178 });179 });180 it('should return data matching the sent parameters', (done) => {181 const pkmnData = {182 name: 'Charmeleon',183 price: 830.6,184 stock: 18,185 };186 api187 .post('/pokemon/')188 .send(pkmnData)189 .expect(201)190 .end((err, res) => {191 if (err) {192 return done(err);193 }194 // Check equality of objects195 expect({196 name: res.body.name,197 price: res.body.price,198 stock: res.body.stock,199 })200 .to.deep.equal(pkmnData);201 return done();202 });203 });204 it('should return an error message when no Name is passed', (done) => {205 const pkmnData = {206 price: 830.6,207 stock: 18,208 };209 api210 .post('/pokemon/')211 .send(pkmnData)212 .expect(400)213 .end((err, res) => {214 if (err) {215 return done(err);216 }217 expect(res.body).to.contain.keys('error');218 return done();219 });220 });221 it('should return an error message when no Price is passed', (done) => {222 const pkmnData = {223 name: 'Pikachu',224 stock: 18,225 };226 api227 .post('/pokemon/')228 .send(pkmnData)229 .expect(400)230 .end((err, res) => {231 if (err) {232 return done(err);233 }234 expect(res.body).to.contain.keys('error');235 return done();236 });237 });238 it('should set Stock to 1 when no value is passed', (done) => {239 const pkmnData = {240 name: 'Pikachu',241 price: 830.6,242 };243 api244 .post('/pokemon/')245 .send(pkmnData)246 .expect(201)247 .end((err, res) => {248 if (err) {249 return done(err);250 }251 expect(res.body).to.contain.property('stock', 1);252 return done();253 });254 });255 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import React from 'react';2import { storiesOf } from '@storybook/react';3import { action } from '@storybook/addon-actions';4import { linkTo } from '@storybook/addon-links';5import { Button, Welcome } from '@storybook/react/demo';6import { withRoot } from '../src';7storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} />);8storiesOf('Button', module)9 .add('with text', () => <Button onClick={action('clicked')}>Hello Button</Button>)10 .add('with some emoji', () => (11 <Button onClick={action('clicked')}>12 ));13storiesOf('Button', module)14 .addDecorator(withRoot)15 .add('with text', () => <Button onClick={action('clicked')}>Hello Button</Button>)16 .add('with some emoji', () => (17 <Button onClick={action('clicked')}>18 ));19import React from 'react';20import { storiesOf } from '@storybook/react';21import { action } from '@storybook/addon-actions';22import { linkTo } from '@storybook/addon-links';23import { Button, Welcome } from '@storybook/react/demo';24import { withRoot } from '../src';25storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} />);26storiesOf('Button', module)27 .add('with text', () => <Button onClick={action('clicked')}>Hello Button</Button>)28 .add('with some emoji', () => (29 <Button onClick={action('clicked')}>30 ));31storiesOf('Button', module)32 .addDecorator(withRoot)33 .add('with text', () => <Button onClick={action('clicked')}>Hello Button</Button>)34 .add('with some emoji', () => (35 <Button onClick={action

Full Screen

Using AI Code Generation

copy

Full Screen

1import { storiesOf } from "@storybook/react";2import { withInfo } from "@storybook/addon-info";3import { withKnobs, text } from "@storybook/addon-knobs";4import { withTests } from "@storybook/addon-jest";5import results from "../../../.jest-test-results.json";6import { action } from "@storybook/addon-actions";7import { withA11y } from "@storybook/addon-a11y";8import { withPerformance } from "storybook-addon-performance";9import { withScreenshot } from "storycap";10import { ThemeProvider } from "styled-components";11import { theme } from "../../style/themes";12import { BrowserRouter as Router } from "react-router-dom";13import { mount } from "enzyme";14import { Provider } from "react-redux";15import { createStore } from "redux";16import { rootReducer } from "../../redux/reducers";17import { createBrowserHistory } from "history";18import { createMemoryHistory } from "history";19const store = createStore(rootReducer);20const history = createBrowserHistory();21const mountWithTheme = (children) =>22 mount(23 <Provider store={store}>24 <ThemeProvider theme={theme}>25 <Router history={history}>{children}</Router>26 );27const mountWithThemeAndA11y = (children) =>28 mount(29 <Provider store={store}>30 <ThemeProvider theme={theme}>31 <Router history={history}>32 <div>{children}</div>33 );34const mountWithThemeAndA11yAndRouter = (children) =>35 mount(36 <Provider store={store}>37 <ThemeProvider theme={theme}>38 <Router history={history}>39 <div>{children}</div>40 );41storiesOf("Test", module)42 .addDecorator(withKnobs)43 .addDecorator(withInfo)44 .addDecorator(withTests({ results }))45 .addDecorator(withA11y)46 .addDecorator(withPerformance)47 .addDecorator(withScreenshot)48 .add("Test", () => {49 const textValue = text("Text", "Hello World");50 const wrapper = mountWithThemeAndA11yAndRouter(<div>{textValue}</div>);51 return wrapper;52 });53import { mountWithThemeAndA11yAndRouter }

Full Screen

Using AI Code Generation

copy

Full Screen

1import { withKnobs, text } from '@storybook/addon-knobs';2import { withA11y } from '@storybook/addon-a11y';3import { withTests } from '@storybook/addon-jest';4import { action } from '@storybook/addon-actions';5import { withInfo } from '@storybook/addon-info';6import { withNotes } from '@storybook/addon-notes';7import { withOptions } from '@storybook/addon-options';8import { withViewport } from '@storybook/addon-viewport';9import { withBackgrounds } from '@storybook/addon-backgrounds';10import { withConsole } from '@storybook/addon-console';11import { withLinks } from '@storybook/addon-links';12import { withContexts } from '@storybook/addon-contexts/react';13import { withSmartKnobs } from 'storybook-addon-smart-knobs';14import { withPropsTable } from 'storybook-addon-react-docgen';15import { withPropsCombinations } from 'react-storybook-addon-props-combinations';16import { withReadme } from 'storybook-readme/with-readme';17import { withDocs } from 'storybook-readme/with-docs';18import { withCode } from 'storybook-addon-code';19import { withCSSResources } from '@storybook/addon-cssresources';20import { withI18n } from 'storybook-addon-i18n';21import { withPerformance } from 'storybook-addon-performance';22import { withPercy } from '@percy-io/percy-storybook';23import { configure } from '@storybook/react';24import results from '../.jest-test-results.json';25import { withRoot } from './story-root';26import '../stories';27const req = require.context('../stories', true, /.stories.js$/);28function loadStories() {29 req.keys().forEach(filename => req(filename));30}31const options = {

Full Screen

Using AI Code Generation

copy

Full Screen

1import React from 'react';2import { storiesOf } from '@storybook/react';3import { action } from '@storybook/addon-actions';4import { withInfo } from '@storybook/addon-info';5import { StoryWrapper } from '../../../.storybook/decorators';6import { Button } from './Button';7storiesOf('Button', module)8 .addDecorator(StoryWrapper)9 .add(10 withInfo('A button')(() => (11 <Button onClick={action

Full Screen

Using AI Code Generation

copy

Full Screen

1import { done } from 'storybook-root';2import { done } from 'storybook-root';3import { done } from 'storybook-root';4import { done } from 'storybook-root';5import { done } from 'storybook-root';6import { done } from 'storybook-root';7import { done } from 'storybook-root';8import { done } from 'storybook-root';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { done } from 'storybook-root';2export function done() {3}4import { done } from 'storybook-root';5module.exports = {6 done: function() {7 }8}9import { done } from 'storybook-root';10describe('stories', () => {11 require('../stories/');12 it('should render all stories without errors', () => {13 done();14 });15});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { done } from 'storybook-root';2import { done } from 'storybook-root';3import { done } from 'storybook-root';4import { done } from 'storybook-root';5import { done } from 'storybook-root';6import { done } from 'storybook-root';7import { done } from 'storybook-root';8import { done } from 'storybook-root';9import { done } from 'storybook-root';10import { done } from 'storybook-root';11import { done } from 'storybook-root';12import { done } from 'storybook-root';13import { done } from 'storybook-root';14import { done } from 'storybook

Full Screen

Using AI Code Generation

copy

Full Screen

1import { storiesOf } from '@storybook/html';2import './test.css';3storiesOf('Test', module)4 .add('test', () => {5 return '<div class="test">test</div>';6 })7 .add('test2', () => {8 return '<div class="test">test2</div>';9 })10 .add('test3', () => {11 return '<div class="test">test3</div>';12 })13 .add('test4', () => {14 return '<div class="test">test4</div>';15 })16 .add('test5', () => {17 return '<div class="test">test5</div>';18 })19 .add('test6', () => {20 return '<div class="test">test6</div>';21 })22 .add('test7', () => {23 return '<div class="test">test7</div>';24 })25 .add('test8', () => {26 return '<div class="test">test8</div>';27 })28 .add('test9', () => {29 return '<div class="test">test9</div>';30 })31 .add('test10', () => {32 return '<div class="test">test10</div>';33 })34 .add('test11', () => {35 return '<div class="test">test11</div>';36 })37 .add('test12', () => {38 return '<div class="test">test12</div>';39 })40 .add('test13', () => {41 return '<div class="test">test13</div>';42 })43 .add('test14', () => {44 return '<div class="test">test14</div>';45 })46 .add('test15', () => {47 return '<div class="test">test15</div>';48 })49 .add('test16', () => {50 return '<div class="test">test16</div>';51 })52 .add('test17', () => {53 return '<div class="test">test17</div>';54 })55 .add('test18', () => {56 return '<div class="test">test18</div>';57 })58 .add('test19', () =>

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful