LP1816475: Booking module refresh
[working/Evergreen.git] / Open-ILS / src / eg2 / src / app / share / validators / patron_barcode_validator.directive.spec.ts
1 import {PatronBarcodeValidator} from './patron_barcode_validator.directive';
2 import {of} from 'rxjs';
3 import {NetService} from '@eg/core/net.service';
4 import {AuthService} from '@eg/core/auth.service';
5 import {EventService} from '@eg/core/event.service';
6 import {StoreService} from '@eg/core/store.service';
7
8 let netService: NetService;
9 let authService: AuthService;
10 let evtService: EventService;
11 let storeService: StoreService;
12
13 beforeEach(() => {
14     evtService = new EventService();
15     storeService = new StoreService(null /* CookieService */);
16     netService = new NetService(evtService);
17     authService = new AuthService(evtService, netService, storeService);
18 });
19
20 describe('PatronBarcodeValidator', () => {
21     it('should not throw an error if there is exactly 1 match', () => {
22         const pbv = new PatronBarcodeValidator(authService, netService);
23         pbv['parseActorCall'](of(1))
24         .subscribe((val) => {
25             expect(val).toBeNull();
26         });
27     });
28     it('should throw an error if there is more than 1 match', () => {
29         const pbv = new PatronBarcodeValidator(authService, netService);
30         pbv['parseActorCall'](of(1, 2, 3))
31         .subscribe((val) => {
32             expect(val).not.toBeNull();
33         });
34     });
35     it('should throw an error if there is no match', () => {
36         const pbv = new PatronBarcodeValidator(authService, netService);
37         pbv['parseActorCall'](of())
38         .subscribe((val) => {
39             expect(val).not.toBeNull();
40         });
41     });
42 });
43