helpdesk-config.service.test.ts 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Password Management Servlets (PWM)
  3. * http://www.pwm-project.org
  4. *
  5. * Copyright (c) 2006-2009 Novell, Inc.
  6. * Copyright (c) 2009-2021 The PWM Project
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. import {IHttpBackendService, IHttpService, ILogService, IQService, IWindowService, module} from 'angular';
  21. import ObjectService from './object.service';
  22. import {default as PwmService, IPwmService} from './pwm.service';
  23. import LocalStorageService from './local-storage.service';
  24. import HelpDeskConfigService, {IVerificationMap} from './helpdesk-config.service';
  25. import {helpdeskProcessAction_clientData} from './helpdesk-config.service.test-data';
  26. describe('In helpdesk-config.service.test.ts', () => {
  27. beforeEach(() => {
  28. module('app', []);
  29. });
  30. let localStorageService: LocalStorageService;
  31. let objectService: ObjectService;
  32. let pwmService: IPwmService;
  33. let helpDeskConfigService: HelpDeskConfigService;
  34. let $httpBackend: IHttpBackendService;
  35. beforeEach(inject((
  36. $http: IHttpService,
  37. $log: ILogService,
  38. $q: IQService,
  39. $window: IWindowService,
  40. _$httpBackend_: IHttpBackendService
  41. ) => {
  42. localStorageService = new LocalStorageService($log, $window);
  43. objectService = new ObjectService();
  44. pwmService = new PwmService($http, $log, $q, $window);
  45. $httpBackend = _$httpBackend_;
  46. helpDeskConfigService = new HelpDeskConfigService($http, $log, $q, pwmService as PwmService);
  47. }));
  48. it('getVerificationMethods returns only the required verification methods', (done: DoneFn) => {
  49. $httpBackend.whenGET( '/context.html?processAction=clientData').respond(helpdeskProcessAction_clientData);
  50. helpDeskConfigService.getVerificationMethods()
  51. .then((verifications: IVerificationMap) => {
  52. expect(verifications.length).toBe(2);
  53. expect(verifications).toContain({name: 'ATTRIBUTES', label: 'Button_Attributes'});
  54. expect(verifications).toContain({name: 'OTP', label: 'Button_OTP'});
  55. done();
  56. })
  57. .catch((error: Error) => {
  58. done.fail(error);
  59. });
  60. // This causes the $http service to finally resolve the response:
  61. $httpBackend.flush();
  62. });
  63. // helpDeskConfigService should return both required and optional, because we passed in: {includeOptional: true}
  64. it('getVerificationMethods returns both required and optional verification methods', (done: DoneFn) => {
  65. $httpBackend.whenGET( '/context.html?processAction=clientData').respond(helpdeskProcessAction_clientData);
  66. helpDeskConfigService.getVerificationMethods({includeOptional: true})
  67. .then((verifications: IVerificationMap) => {
  68. expect(verifications.length).toBe(3);
  69. expect(verifications).toContain({name: 'ATTRIBUTES', label: 'Button_Attributes'});
  70. expect(verifications).toContain({name: 'EMAIL', label: 'Button_Email'});
  71. expect(verifications).toContain({name: 'OTP', label: 'Button_OTP'});
  72. done();
  73. })
  74. .catch((error: Error) => {
  75. done.fail(error);
  76. });
  77. // This causes the $http service to finally resolve the response:
  78. $httpBackend.flush();
  79. });
  80. });