|
1 | | -//'use strict'; |
| 1 | +'use strict'; |
2 | 2 |
|
3 | | -//describe('Profile', function() { |
4 | | - |
5 | | - //var $rootScope, $location, $httpBackend, $http, AccessToken, Profile; |
6 | | - //var result, date, callback; |
7 | | - |
8 | | - //var fragment = 'access_token=token&token_type=bearer&expires_in=7200&state=/path'; |
9 | | - //var headers = { 'Accept': 'application/json, text/plain, */*', 'Authorization': 'Bearer token' } |
10 | | - //var params = { site: 'http://example.com', client: 'client-id', redirect: 'http://example.com/redirect', scope: 'scope', profileUri: 'http://example.com/me' }; |
11 | | - //var resource = { id: '1', name: 'Alice' }; |
12 | | - |
13 | | - //beforeEach(module('oauth')); |
14 | | - |
15 | | - //beforeEach(inject(function($injector) { $rootScope = $injector.get('$rootScope') })); |
16 | | - //beforeEach(inject(function($injector) { $location = $injector.get('$location') })); |
17 | | - //beforeEach(inject(function($injector) { $httpBackend = $injector.get('$httpBackend') })); |
18 | | - //beforeEach(inject(function($injector) { $http = $injector.get('$http') })); |
19 | | - //beforeEach(inject(function($injector) { AccessToken = $injector.get('AccessToken') })); |
20 | | - //beforeEach(inject(function($injector) { Profile = $injector.get('Profile') })); |
21 | | - |
22 | | - //beforeEach(function() { callback = jasmine.createSpy('callback') }); |
23 | | - |
24 | | - |
25 | | - //describe('.get', function() { |
26 | | - |
27 | | - //describe('when authenticated', function() { |
28 | | - |
29 | | - //beforeEach(function() { |
30 | | - //$location.hash(fragment); |
31 | | - //AccessToken.set(params); |
32 | | - //}); |
33 | | - |
34 | | - //beforeEach(function() { |
35 | | - //$httpBackend.whenGET('http://example.com/me', headers).respond(resource); |
36 | | - //}); |
37 | | - |
38 | | - //describe('when gets the profile', function() { |
39 | | - |
40 | | - //it('makes the request', function() { |
41 | | - //$httpBackend.expect('GET', 'http://example.com/me'); |
42 | | - //Profile.find(params.profileUri); |
43 | | - //$rootScope.$apply(); |
44 | | - //$httpBackend.flush(); |
45 | | - //}); |
46 | | - |
47 | | - //it('gets the resource', inject(function(Profile) { |
48 | | - //Profile.find(params.profileUri).success(function(response) { result = response }); |
49 | | - //$rootScope.$apply(); |
50 | | - //$httpBackend.flush(); |
51 | | - //expect(result.name).toEqual('Alice'); |
52 | | - //})); |
53 | | - |
54 | | - //it('caches the profile', function() { |
55 | | - //Profile.find(params.profileUri); |
56 | | - //$rootScope.$apply(); |
57 | | - //$httpBackend.flush(); |
58 | | - //expect(Profile.get().name).toEqual('Alice'); |
59 | | - //}); |
60 | | - |
61 | | - //describe('when expired', function() { |
62 | | - |
63 | | - //beforeEach(function() { |
64 | | - //$rootScope.$on('oauth:expired', callback); |
65 | | - //}); |
66 | | - |
67 | | - //beforeEach(function() { |
68 | | - //date = new Date(); |
69 | | - //date.setTime(date.getTime() + 86400000); |
70 | | - //}); |
71 | | - |
72 | | - //beforeEach(function() { |
73 | | - //Timecop.install(); |
74 | | - //Timecop.travel(date); // go one day in the future |
75 | | - //}); |
76 | | - |
77 | | - //afterEach(function() { |
78 | | - //Timecop.uninstall(); |
79 | | - //}); |
80 | | - |
81 | | - //it('fires the oauth:expired event', inject(function(Profile) { |
82 | | - //Profile.find(params.profileUri); |
83 | | - //$rootScope.$apply(); |
84 | | - //$httpBackend.flush(); |
85 | | - //var event = jasmine.any(Object); |
86 | | - //var token = jasmine.any(Object); |
87 | | - //expect(callback).toHaveBeenCalledWith(event, token); |
88 | | - //})); |
89 | | - //}); |
90 | | - //}); |
91 | | - |
92 | | - |
93 | | - //describe('when sets the profile', function() { |
94 | | - |
95 | | - //beforeEach(function() { |
96 | | - //Profile.set(resource); |
97 | | - //}); |
98 | | - |
99 | | - //it('caches the profile', function() { |
100 | | - //expect(Profile.get().name).toEqual('Alice'); |
101 | | - //}); |
102 | | - //}); |
103 | | - //}); |
104 | | - //}); |
105 | | -//}); |
| 3 | +describe('Profile', function() { |
| 4 | + |
| 5 | + var $rootScope, $location, $httpBackend, $http, AccessToken, Profile; |
| 6 | + var result, date, callback; |
| 7 | + |
| 8 | + var fragment = 'access_token=token&token_type=bearer&expires_in=7200&state=/path'; |
| 9 | + var headers = { 'Accept': 'application/json, text/plain, */*', 'Authorization': 'Bearer token' } |
| 10 | + var params = { site: 'http://example.com', client: 'client-id', redirect: 'http://example.com/redirect', scope: 'scope', profileUri: 'http://example.com/me' }; |
| 11 | + var resource = { id: '1', name: 'Alice' }; |
| 12 | + |
| 13 | + beforeEach(module('oauth')); |
| 14 | + |
| 15 | + beforeEach(inject(function($injector) { $rootScope = $injector.get('$rootScope') })); |
| 16 | + beforeEach(inject(function($injector) { $location = $injector.get('$location') })); |
| 17 | + beforeEach(inject(function($injector) { $httpBackend = $injector.get('$httpBackend') })); |
| 18 | + beforeEach(inject(function($injector) { $http = $injector.get('$http') })); |
| 19 | + beforeEach(inject(function($injector) { AccessToken = $injector.get('AccessToken') })); |
| 20 | + beforeEach(inject(function($injector) { Profile = $injector.get('Profile') })); |
| 21 | + |
| 22 | + beforeEach(function() { callback = jasmine.createSpy('callback') }); |
| 23 | + |
| 24 | + |
| 25 | + describe('.get', function() { |
| 26 | + |
| 27 | + describe('when authenticated', function() { |
| 28 | + |
| 29 | + beforeEach(function() { |
| 30 | + $location.hash(fragment); |
| 31 | + AccessToken.set(params); |
| 32 | + }); |
| 33 | + |
| 34 | + beforeEach(function() { |
| 35 | + $httpBackend.whenGET('http://example.com/me', headers).respond(resource); |
| 36 | + }); |
| 37 | + |
| 38 | + describe('when gets the profile', function() { |
| 39 | + |
| 40 | + it('makes the request', function() { |
| 41 | + $httpBackend.expect('GET', 'http://example.com/me'); |
| 42 | + Profile.find(params.profileUri); |
| 43 | + $rootScope.$apply(); |
| 44 | + $httpBackend.flush(); |
| 45 | + }); |
| 46 | + |
| 47 | + it('gets the resource', inject(function(Profile) { |
| 48 | + Profile.find(params.profileUri).success(function(response) { result = response }); |
| 49 | + $rootScope.$apply(); |
| 50 | + $httpBackend.flush(); |
| 51 | + expect(result.name).toEqual('Alice'); |
| 52 | + })); |
| 53 | + |
| 54 | + it('caches the profile', function() { |
| 55 | + Profile.find(params.profileUri); |
| 56 | + $rootScope.$apply(); |
| 57 | + $httpBackend.flush(); |
| 58 | + expect(Profile.get().name).toEqual('Alice'); |
| 59 | + }); |
| 60 | + |
| 61 | + it('fires oauth:profile event', function(done) { |
| 62 | + |
| 63 | + $rootScope.$on('oauth:profile', function (event, profile) { |
| 64 | + expect(typeof profile).toBe('object'); |
| 65 | + done(); |
| 66 | + }); |
| 67 | + |
| 68 | + Profile.find(params.profileUri); |
| 69 | + $rootScope.$apply(); |
| 70 | + $httpBackend.flush(); |
| 71 | + |
| 72 | + }); |
| 73 | + |
| 74 | + |
| 75 | + describe('when expired', function() { |
| 76 | + |
| 77 | + beforeEach(function() { |
| 78 | + $rootScope.$on('oauth:expired', callback); |
| 79 | + }); |
| 80 | + |
| 81 | + beforeEach(function() { |
| 82 | + date = new Date(); |
| 83 | + date.setTime(date.getTime() + 86400000); |
| 84 | + }); |
| 85 | + |
| 86 | + beforeEach(function() { |
| 87 | + Timecop.install(); |
| 88 | + Timecop.travel(date); // go one day in the future |
| 89 | + }); |
| 90 | + |
| 91 | + afterEach(function() { |
| 92 | + Timecop.uninstall(); |
| 93 | + }); |
| 94 | + |
| 95 | + it('fires the oauth:expired event', inject(function(Profile) { |
| 96 | + Profile.find(params.profileUri); |
| 97 | + $rootScope.$apply(); |
| 98 | + $httpBackend.flush(); |
| 99 | + var event = jasmine.any(Object); |
| 100 | + var token = jasmine.any(Object); |
| 101 | + expect(callback).toHaveBeenCalledWith(event, token); |
| 102 | + })); |
| 103 | + }); |
| 104 | + }); |
| 105 | + |
| 106 | + |
| 107 | + describe('when sets the profile', function() { |
| 108 | + |
| 109 | + beforeEach(function() { |
| 110 | + Profile.set(resource); |
| 111 | + }); |
| 112 | + |
| 113 | + it('caches the profile', function() { |
| 114 | + expect(Profile.get().name).toEqual('Alice'); |
| 115 | + }); |
| 116 | + |
| 117 | + }); |
| 118 | + }); |
| 119 | + }); |
| 120 | +}); |
0 commit comments