]> khamidou — GitHub mirrors - kite.git/commitdiff
WIP - loading resources from backend
authorkarim hamidou <khamidou@gmail.com>
Sat, 19 Oct 2013 19:06:12 +0000 (21:06 +0200)
committerkarim hamidou <khamidou@gmail.com>
Sat, 19 Oct 2013 19:06:12 +0000 (21:06 +0200)
src/front/app/js/controllers.js
src/front/app/js/services.js
src/front/test/unit/services.spec.js

index 2d82c7b07c417865c09fe0495644a7b029ada424..06ba834871ba21db2e632e03077332ad98b76490 100644 (file)
@@ -10,27 +10,7 @@ angular.module('KiteMail.controllers', []).
             {"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) {
     
     
index b5709301a8ff4ac84e83a19d7dc3108ba7948c36..b9ba8e607d999612b6bf79d9c86e68f2ae5a00b9 100644 (file)
@@ -5,9 +5,16 @@
 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;
     }
 ]);
 
index f339dd663b09d14f381e50f9752a11b287cabf45..728d90500e92f9c962248e8633b2119a2bcfe8cb 100644 (file)
@@ -6,7 +6,10 @@ describe('service', function() {
     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()
         
     }))});
 });