{"name": "Spam", },];
}).controller('MailsListController', ['$scope', 'Emails', function($scope, Emails) {
- $scope.mails = Emails.query(); /*[
- {"from": "random.spam@spam.com",
- "to": "you",
- "subject": "-50% promo on everything !",
- "contents": "Everything must go !",
- "date": new Date(),
- },
-
- {"from": "nigerian.prince@spam.com",
- "to": "user@mail.com",
- "subject": "I need your urgent help",
- "contents": "Hi my dear friend. I need your help urgently in a matter of financial problems.",
- "date": new Date(1992, 4, 24),
- },
- {"from": "team@kitemail",
- "name": "Kite team",
- "to": "user@mail.com",
- "subject": "Welcome to Kite !",
- "contents": "This is the basic inbox page. As you can see, it looks a lot like a famous email service.",
- "date": new Date(),
- }]; */
+ $scope.mails = Emails.query(); /*; */
}]).controller('LoginController', function($scope) {
angular.module('KiteMail.services', ['ngResource']).
factory('Emails', ['$resource',
function($resource) {
- return $resource(':user/mail/', {}, {
+ var data = $resource('/kite/:user/mail/', {}, {
query: {method:'GET', params:{user: "karim"}, isArray:true}
});
+
+ // convert date string to js date objects
+ for(var i = 0; i < data.length; i++) {
+ data[i]["date"] = new Date(data[i]["date"]);
+ }
+
+ return data;
}
]);
beforeEach(module('KiteMail.services'));
describe('EmailsService', function() {
- it('should do an ajax request to get the list of services', inject(function() {
+ it('should do an ajax request to get the list of services', inject(function($service) {
+ var resourceMock = jasmine.createSpy('$resource').andReturn([{"subject": "mock", "date": "2013-04-23"}]);
+ var service = $service("EmailsService", resourceMock);
+ expect(resourceMock).toHaveBeenCalled()
}))});
});