title: AngularJS - Testing service method that uses $http service
body: <p>I have a function on my service that looks like something this:</p>
  
  <pre><code>addStatement: function(user, action, object) {
              var statement = {
                      user: user,
                      action: action,
                      object: object
              };
              $http({
                  method: 'POST', 
                  url: '/foo/bar', 
                  data: statement, 
                  headers: {Authorization: 'Basic YWxhZGRpbjpvcGVuIHNlc2FtZQ=='}
              }).success(function(data) {
                  alert("success: " + data);
              });
          }
  </code></pre>
  
  <p>I want to write a unit test for this method, but I'm not sure how to make it work. Basically, I want to test that the data sent up was correctly constructed from the function parameters and that the correct Authorization header was sent up.</p>
  
  <p>I've been reading over how to use <a href="http://docs.angularjs.org/api/ngMock.%24httpBackend">$httpBackend</a>, but the example there is testing a controller, and just stuff that changes on the $scope when the requests are made and returned. Is there a way to achieve the tests I want? Or am I going about something wrong?</p>