I have a function on my service that looks like something this:
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);
});
}
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.
I've been reading over how to use $httpBackend, 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?