Advertisement
leticiaf

test SearchResource v3

Oct 5th, 2015
57
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.     var db: DbContext = new DbContext(Config.environment.database);
  23.     if(global.database == undefined) global.database = db;
  24.    
  25.     before(() =>{
  26.             //
  27.             var busColletion: ICollection<Bus> = db.collection<Bus>(new BusModelMap());
  28.    
  29.             var busOne: Bus = new Bus("565", "111", 0, 0, 0, 0, (new Date()).toISOString(), "0");
  30.             var busTwo: Bus = new Bus("1", "111", 0, 0, 0, 0, (new Date()).toISOString(), "0");
  31.             var busThree: Bus = new Bus("10", "111", 0, 0, 0, 0, (new Date()).toISOString(), "0");
  32.        
  33.             busColletion.save(busOne);
  34.             busColletion.save(busTwo);
  35.             busColletion.save(busThree);
  36.     });
  37.      
  38.     var platformId: number = 1;
  39.     var data: string = "1,10,565";
  40.     var ip : string = "0.0.0.0";
  41.     var port: string = "8080";
  42.     var route : string ="/v2/search/:platformId/:data";
  43.     var resources : Object = {"resources/v2/searchResource":route};
  44.     var address: string = "http://"+ip+":"+port+"/v2/search/"+platformId+"/"+data;
  45.    
  46.  
  47.  
  48.     globalAnalytics = new MockAnalytics();
  49.     global.Config = Config;
  50.     global.analytics = globalAnalytics;
  51.  
  52.  
  53.     var router : Router = new Router();
  54.     router.registerResources(resources);
  55.     var httpRequest : HttpRequest = new HttpRequest();
  56.    
  57.    
  58.     it("should get a bus list", (done) =>{
  59.         var notExpected: number = 0;
  60.         var current: number;
  61.  
  62.         var output: any = httpRequest.get(address).body;
  63.         current = output.length;
  64.         Assert.notEqual(current, notExpected);
  65.         done();
  66.     });
  67.  
  68. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement