/*
 * This program is part of the OpenLMIS logistics management information system platform software.
 * Copyright © 2013 VillageReach
 *
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
 * You should have received a copy of the GNU Affero General Public License along with this program.  If not, see http://www.gnu.org/licenses.  For additional information contact info@OpenLMIS.org. 
 */

describe('ManagePODController', function () {
  var scope, controller, messageService, $httpBackend, location;

  beforeEach(module('openlmis'));
  beforeEach(inject(function ($rootScope, $controller, _messageService_, _$httpBackend_, $location) {
    scope = $rootScope.$new();
    location = $location;
    spyOn(location, 'url');

    controller = $controller;
    messageService = _messageService_;
    $httpBackend = _$httpBackend_;
    spyOn(messageService, 'get');

    data = {ordersForPOD: [
      {id: 1}
    ]};

    $httpBackend.expect('GET', '/manage-pod-orders').respond(200, data);
    controller(ManagePODController, {$scope: scope});
    $httpBackend.flush();

  }));

  it('should set orders for manage pod in scope', function () {
    expect(scope.orders).toEqual(data.ordersForPOD);
  });

  it('should get order status message based on status', function () {
    scope.getStatus('STATUS');

    expect(messageService.get).toHaveBeenCalledWith('label.order.STATUS');
  });

  it('should get orderPOD from order id', function () {
    var orderId = 1;
    data = {
      orderPOD: {id: 1},
      order: {emergency: true}
    };

    $httpBackend.expectPOST('/pods.json?orderId=1').respond(200, data);

    scope.createPOD(orderId);
    $httpBackend.flush();

    expect(location.url).toHaveBeenCalledWith('/pods/1?page=1');
  });
});
@@ -1113,16 +1113,83 @@
 $new();%0A
+    scope.option = %7Ball : true%7D;%0A    scope.filter = %7Bprogram : 1%7D;%0A
     loca
@@ -1429,35 +1429,182 @@
 %7D;%0A%0A    
-$httpBackend.expect
+var programs = %7BprogramList: %5B%7Bid: 1, name: 'ARV'%7D%5D%7D;%0A%0A    $httpBackend.when('GET', '/create/requisition/programs.json').respond(200, programs);%0A    $httpBackend.when
 ('GET', 
@@ -1794,24 +1794,269 @@
 nction () %7B%0A
+    //%0A    $httpBackend.when('GET', '/create/requisition/supervised/1/facilities.json').respond(200, data);%0A    $httpBackend.when('GET', '/manage-pod-orders?program=1').respond(200, data);%0A    scope.onProgramChanged();%0A    $httpBackend.flush();%0A
     expect(s

test manage pod - make manage pod permission aware.