Нет описания

oauth.spec.ts 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import OAuth from '../src/oauth';
  2. import OAuth1 from '../src/oauth1';
  3. import OAuth2 from '../src/oauth2';
  4. import Config from '../src/config';
  5. import Shared from '../src/shared';
  6. import Storage from '../src/storage';
  7. import Popup from '../src/popup';
  8. let httpBackend;
  9. let config;
  10. let storage;
  11. let shared;
  12. let popup;
  13. let oauth;
  14. let oauth1;
  15. let oauth2;
  16. describe('OAuth', () => {
  17. beforeEach(angular.mock.inject(($q, $http, $window, $interval, $log, $httpBackend, $timeout) => {
  18. httpBackend = $httpBackend;
  19. config = new Config();
  20. storage = new Storage($window, config);
  21. shared = new Shared($q, $window, $log, config, storage);
  22. popup = new Popup($interval, $window, $q);
  23. oauth1 = new OAuth1($http, $window, config, popup);
  24. oauth2 = new OAuth2($http, $window, $timeout, $q, config, popup, storage);
  25. oauth = new OAuth($http, $window, $timeout, $q, config, popup, storage, shared, oauth1, oauth2);
  26. }));
  27. afterEach(() => {
  28. httpBackend.verifyNoOutstandingExpectation();
  29. httpBackend.verifyNoOutstandingRequest();
  30. });
  31. describe('unlink()', () => {
  32. it('should be defined', () => {
  33. expect(oauth.unlink).toBeDefined();
  34. });
  35. it('should unlink a provider successfully', () => {
  36. let result = null;
  37. httpBackend.expectPOST(config.unlinkUrl).respond(200);
  38. oauth.unlink('google').then((response) => {
  39. result = response.status;
  40. });
  41. httpBackend.flush();
  42. expect(result).toBe(200);
  43. });
  44. it('should unlink a provider and get an error', () => {
  45. let result = null;
  46. httpBackend.expectPOST(config.unlinkUrl).respond(400);
  47. oauth.unlink('facebook').catch((response) => {
  48. result = response.status;
  49. });
  50. httpBackend.flush();
  51. expect(result).toEqual(400);
  52. });
  53. });
  54. });