Advertisement
leticiaf

test SearchResource v2

Oct 5th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. declare var require, describe, it, global, before;
  2. import DbContext        = require("../../../src/core/database/dbContext");
  3. import HttpRequest      = require("../../../src/core/httpRequest");
  4. import Router           = require("../../../src/core/router");
  5. import Config           = require("../../../src/config");
  6. import Analytics        = require("../../../src/common/analytics");
  7. import Bus              = require("../../../src/domain/entity/bus")
  8. import ICollection       = require("../../../src/core/database/iCollection");
  9. import BusModelMap       = require("../../../src/domain/modelMap/busModelMap");
  10. var Assert = require("assert");
  11.  
  12.  
  13.  
  14. class MockAnalytics extends Analytics{
  15.     public trackEvent(): void {}
  16.     public trackPage():  void {}
  17. }
  18.  
  19. declare var globalAnalytics: Analytics;
  20. describe("SearchResource", () => {
  21.    
  22.     if(global.database == undefined) global.database = new DbContext(Config.environment.database);
  23.    
  24.     before(() =>{
  25.             var db: DbContext = new DbContext(Config.environment.database);
  26.             var busColletion: ICollection<Bus> = db.collection<Bus>(new BusModelMap());
  27.    
  28.             var busOne: Bus = new Bus("565", "111", 0, 0, 0, 0, (new Date()).toISOString(), "0");
  29.             var busTwo: Bus = new Bus("1", "111", 0, 0, 0, 0, (new Date()).toISOString(), "0");
  30.             var busThree: Bus = new Bus("10", "111", 0, 0, 0, 0, (new Date()).toISOString(), "0");
  31.        
  32.             busColletion.save(busOne);
  33.             busColletion.save(busTwo);
  34.             busColletion.save(busThree);
  35.     });
  36.      
  37.     var platformId: string = "1";
  38.     var data: string = "1,10,565";
  39.     var ip : string = "mongo";//0.0.0.0";
  40.     var port: string = "27017";// "8080";
  41.     var route : string ="/v2/search/:platformId/:data";
  42.     var resources : Object = {"resources/v2/searchResource":route};
  43.     var address: string = "http://"+ip+":"+port+"/v2/search/platformId/data";
  44.    
  45.  
  46.  
  47.     globalAnalytics = new MockAnalytics();
  48.     global.Config = Config;
  49.     global.analytics = globalAnalytics;
  50.  
  51.  
  52.     var router : Router = new Router();
  53.     router.registerResources(resources);
  54.     var httpRequest : HttpRequest = new HttpRequest();
  55.    
  56.    
  57.     it("should get a bus list", (done) =>{
  58.         var notExpected: number = 0;
  59.         var current: number;
  60.  
  61.         var output: any = httpRequest.get(address).body;
  62.         current = output.length;
  63.         Assert.notEqual(current, notExpected);
  64.         done();
  65.     });
  66.  
  67. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement