Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / docs-shared / lib / Bridge / BridgeOriginProvider.spec.ts
blob5e881e16ade7b09fa06cd920b7fd4d31b70d815e
1 import { BridgeOriginProvider } from './BridgeOriginProvider'
3 describe('BridgeOriginProvider', () => {
4   const setLocation = (hostname: string) => {
5     Object.defineProperty(window, 'location', {
6       value: {
7         origin: `https://${hostname}`,
8         hostname: hostname,
9         protocol: 'https:',
10         port: '',
11       },
12       writable: true,
13     })
14   }
16   describe('GetSafeOrigin', () => {
17     it('should return root origin', () => {
18       setLocation('docs.proton.local')
20       expect(BridgeOriginProvider.GetEditorOrigin()).toEqual('https://docs-editor.proton.local')
21       expect(BridgeOriginProvider.GetClientOrigin()).toEqual('https://docs.proton.local')
22     })
24     it('should return safe origin with remote domain', () => {
25       setLocation('docs.proton.me')
27       expect(BridgeOriginProvider.GetEditorOrigin()).toEqual('https://docs-editor.proton.me')
28       expect(BridgeOriginProvider.GetClientOrigin()).toEqual('https://docs.proton.me')
29     })
31     it('should return safe origin with nested domain', () => {
32       setLocation('docs.darwin.proton.black')
34       expect(BridgeOriginProvider.GetEditorOrigin()).toEqual('https://docs-editor.darwin.proton.black')
35       expect(BridgeOriginProvider.GetClientOrigin()).toEqual('https://docs.darwin.proton.black')
36     })
37   })