|
| 1 | +import { expect } from 'chai'; |
| 2 | +import { describe, it, before, after } from 'mocha'; |
| 3 | + |
| 4 | +import { addServerUrlToIndex } from '../../../../../app/livechat/lib/Assets'; |
| 5 | + |
| 6 | +describe('addServerUrlToIndex', () => { |
| 7 | + before(() => { |
| 8 | + (global as any).__meteor_runtime_config__ = { ROOT_URL: 'http://localhost:3000' }; |
| 9 | + }); |
| 10 | + after(() => { |
| 11 | + delete (global as any).__meteor_runtime_config__; |
| 12 | + }); |
| 13 | + |
| 14 | + it('should do nothing if "file" has no <body> tag', () => { |
| 15 | + const file = addServerUrlToIndex('file'); |
| 16 | + expect(file).to.equal('file'); |
| 17 | + }); |
| 18 | + it('should replace <body> with an script tag containing the SERVER_URL inside', () => { |
| 19 | + const file = addServerUrlToIndex('<html><body></body></html>'); |
| 20 | + expect(file).to.equal("<html><body><script> SERVER_URL = 'http://localhost:3000'; </script></body></html>"); |
| 21 | + }); |
| 22 | + it('should remove any trailing / from the SERVER_URL', () => { |
| 23 | + (global as any).__meteor_runtime_config__ = { ROOT_URL: 'http://localhost:3000/' }; |
| 24 | + const file = addServerUrlToIndex('<html><body></body></html>'); |
| 25 | + expect(file).to.equal("<html><body><script> SERVER_URL = 'http://localhost:3000'; </script></body></html>"); |
| 26 | + }); |
| 27 | + it('should use the value from the global variable always', () => { |
| 28 | + const file = addServerUrlToIndex('<html><body></body></html>'); |
| 29 | + expect(file).to.equal("<html><body><script> SERVER_URL = 'http://localhost:3000'; </script></body></html>"); |
| 30 | + |
| 31 | + (global as any).__meteor_runtime_config__ = { ROOT_URL: 'http://kodiak.rocket.chat/' }; |
| 32 | + const file2 = addServerUrlToIndex('<html><body></body></html>'); |
| 33 | + expect(file2).to.equal("<html><body><script> SERVER_URL = 'http://kodiak.rocket.chat'; </script></body></html>"); |
| 34 | + }); |
| 35 | +}); |
0 commit comments