|
| 1 | +import { getVariables } from './httpYacApi'; |
| 2 | + |
| 3 | +import { initFileProvider, parseHttp } from './test/testUtils'; |
| 4 | + |
| 5 | +describe('httpYacApi', () => { |
| 6 | + describe('getVariables', () => { |
| 7 | + it('should return secret provided by environment', async () => { |
| 8 | + initFileProvider({ |
| 9 | + '.env': 'secret=from .env', |
| 10 | + }); |
| 11 | + const httpFile = await parseHttp(` |
| 12 | + # @name test |
| 13 | +`); |
| 14 | + |
| 15 | + const variables = await getVariables({ |
| 16 | + httpFile, |
| 17 | + }); |
| 18 | + |
| 19 | + expect(variables).toEqual( |
| 20 | + expect.objectContaining({ |
| 21 | + secret: 'from .env', |
| 22 | + }) |
| 23 | + ); |
| 24 | + }); |
| 25 | + it('should return secret provided by context variables', async () => { |
| 26 | + initFileProvider({ |
| 27 | + '.env': 'secret=from.env', |
| 28 | + }); |
| 29 | + const httpFile = await parseHttp(` |
| 30 | + # @name test |
| 31 | +`); |
| 32 | + |
| 33 | + const variables = await getVariables({ |
| 34 | + httpFile, |
| 35 | + variables: { |
| 36 | + secret: 'cli args', |
| 37 | + }, |
| 38 | + }); |
| 39 | + |
| 40 | + expect(variables).toEqual( |
| 41 | + expect.objectContaining({ |
| 42 | + secret: 'cli args', |
| 43 | + }) |
| 44 | + ); |
| 45 | + }); |
| 46 | + it('should return secret provided by intellij', async () => { |
| 47 | + initFileProvider({ |
| 48 | + '.env': 'secret=from.env', |
| 49 | + 'http-client.env.json': JSON.stringify({ |
| 50 | + dev: { |
| 51 | + secret: 'intellij variable', |
| 52 | + }, |
| 53 | + }), |
| 54 | + }); |
| 55 | + const httpFile = await parseHttp(` |
| 56 | + # @name test |
| 57 | +`); |
| 58 | + |
| 59 | + const variables = await getVariables({ |
| 60 | + httpFile, |
| 61 | + activeEnvironment: ['dev'], |
| 62 | + }); |
| 63 | + |
| 64 | + expect(variables).toEqual( |
| 65 | + expect.objectContaining({ |
| 66 | + secret: 'intellij variable', |
| 67 | + }) |
| 68 | + ); |
| 69 | + }); |
| 70 | + }); |
| 71 | +}); |
0 commit comments