Commits
Giuseppe Digilio authored deb752c06ed
1 1 | import { TestBed } from '@angular/core/testing'; |
2 2 | |
3 3 | import { environment } from '../../../environments/environment.test'; |
4 4 | import { ServerHardRedirectService } from './server-hard-redirect.service'; |
5 5 | |
6 6 | describe('ServerHardRedirectService', () => { |
7 7 | |
8 8 | const mockRequest = jasmine.createSpyObj(['get']); |
9 9 | const mockResponse = jasmine.createSpyObj(['redirect', 'end']); |
10 10 | |
11 - | const service: ServerHardRedirectService = new ServerHardRedirectService(environment, mockRequest, mockResponse); |
11 + | let service: ServerHardRedirectService = new ServerHardRedirectService(environment, mockRequest, mockResponse); |
12 12 | const origin = 'https://test-host.com:4000'; |
13 13 | |
14 14 | beforeEach(() => { |
15 15 | mockRequest.protocol = 'https'; |
16 16 | mockRequest.headers = { |
17 17 | host: 'test-host.com:4000', |
18 18 | }; |
19 19 | |
20 20 | TestBed.configureTestingModule({}); |
21 21 | }); |
62 62 | }); |
63 63 | }); |
64 64 | |
65 65 | describe('when requesting the origin', () => { |
66 66 | |
67 67 | it('should return the location origin', () => { |
68 68 | expect(service.getCurrentOrigin()).toEqual(origin); |
69 69 | }); |
70 70 | }); |
71 71 | |
72 + | describe('when SSR base url is set', () => { |
73 + | const redirect = 'https://private-url:4000/server/api/bitstreams/uuid'; |
74 + | const replacedUrl = 'https://public-url/server/api/bitstreams/uuid'; |
75 + | const environmentWithSSRUrl: any = { environment, { environment.rest, rest: { |
76 + | ssrBaseUrl: 'https://private-url:4000/server', |
77 + | baseUrl: 'https://public-url/server', |
78 + | } } }; |
79 + | service = new ServerHardRedirectService(environmentWithSSRUrl, mockRequest, mockResponse); |
80 + | |
81 + | beforeEach(() => { |
82 + | service.redirect(redirect); |
83 + | }); |
84 + | |
85 + | it('should perform a 302 redirect', () => { |
86 + | expect(mockResponse.redirect).toHaveBeenCalledWith(302, replacedUrl); |
87 + | expect(mockResponse.end).toHaveBeenCalled(); |
88 + | }); |
89 + | }); |
90 + | |
72 91 | }); |