|
| 1 | +/* |
| 2 | + eslint-disable global-require |
| 3 | +*/ |
| 4 | + |
| 5 | +Object.defineProperty(window, 'location', { |
| 6 | + value: { |
| 7 | + origin: 'http://localhost' |
| 8 | + }, |
| 9 | + writable: true |
| 10 | +}) |
| 11 | + |
| 12 | +describe('getOriginUrl', () => { |
| 13 | + const OLD_ENV = process.env |
| 14 | + |
| 15 | + beforeEach(() => { |
| 16 | + jest.resetModules() |
| 17 | + process.env = { ...OLD_ENV } |
| 18 | + }) |
| 19 | + afterAll(() => { |
| 20 | + process.env = OLD_ENV |
| 21 | + }) |
| 22 | + |
| 23 | + test('shoud return url with absolute path', () => { |
| 24 | + const { getOriginUrl } = require('../resourcesService') |
| 25 | + |
| 26 | + expect(getOriginUrl()).toEqual('http://localhost:5001/') |
| 27 | + }) |
| 28 | + |
| 29 | + test('shoud return origin with not absolute path', () => { |
| 30 | + process.env.RI_APP_TYPE = 'web' |
| 31 | + process.env.NODE_ENV = 'production' |
| 32 | + |
| 33 | + const { getOriginUrl } = require('../resourcesService') |
| 34 | + expect(getOriginUrl()).toEqual('http://localhost') |
| 35 | + }) |
| 36 | +}) |
| 37 | + |
| 38 | +describe('getPathToResource', () => { |
| 39 | + const OLD_ENV = process.env |
| 40 | + |
| 41 | + beforeEach(() => { |
| 42 | + jest.resetModules() |
| 43 | + process.env = { ...OLD_ENV } |
| 44 | + }) |
| 45 | + afterAll(() => { |
| 46 | + process.env = OLD_ENV |
| 47 | + }) |
| 48 | + |
| 49 | + test('shoud return url with absolute path', () => { |
| 50 | + const { getPathToResource } = require('../resourcesService') |
| 51 | + |
| 52 | + expect(getPathToResource('data/file.txt')).toEqual('http://localhost:5001/data/file.txt') |
| 53 | + }) |
| 54 | + |
| 55 | + test('shoud return origin with not absolute path', () => { |
| 56 | + process.env.RI_APP_TYPE = 'web' |
| 57 | + process.env.NODE_ENV = 'production' |
| 58 | + |
| 59 | + const { getPathToResource } = require('../resourcesService') |
| 60 | + expect(getPathToResource('data/file.txt')).toEqual('http://localhost/data/file.txt') |
| 61 | + }) |
| 62 | +}) |
0 commit comments