forked from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.test.js
More file actions
92 lines (80 loc) · 2.64 KB
/
Copy pathmain.test.js
File metadata and controls
92 lines (80 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const {
getBaseFolder,
getDataCatererVersion,
getConfiguration
} = require('../src/main')
const core = require('@actions/core')
jest.mock('@actions/core')
describe('getBaseFolder', () => {
afterEach(() => {
jest.resetAllMocks()
})
it('returns the base folder from input if provided', () => {
core.getInput.mockReturnValueOnce('/input/folder')
expect(getBaseFolder('/default/folder')).toBe('/input/folder')
})
it('returns the default base folder if input is not provided', () => {
core.getInput.mockReturnValueOnce('')
expect(getBaseFolder('/default/folder')).toBe('/default/folder')
})
it('throws an error if base folder is not defined', () => {
core.getInput.mockReturnValueOnce('')
expect(() => getBaseFolder('')).toThrow(
'Base folder configuration is not defined'
)
})
it('uses actions input when default base folder is empty', () => {
core.getInput.mockReturnValueOnce('/from-actions-input')
expect(getBaseFolder('')).toBe('/from-actions-input')
})
it('throws an error when both input and default are empty', () => {
core.getInput.mockReturnValueOnce('')
expect(() => getBaseFolder('')).toThrow(
'Base folder configuration is not defined'
)
})
})
describe('getDataCatererVersion', () => {
it('returns the provided data caterer version', () => {
expect(getDataCatererVersion('1.0.0')).toBe('1.0.0')
})
it('returns the default data caterer version if not provided', () => {
expect(getDataCatererVersion('')).toBe('0.17.3')
})
})
describe('getConfiguration', () => {
beforeEach(() => {
jest.resetAllMocks()
process.env.CONFIGURATION_FILE = 'config.json'
process.env.INSTA_INFRA_FOLDER = '/infra'
process.env.BASE_FOLDER = '/base'
process.env.DATA_CATERER_VERSION = '1.0.0'
})
it('returns the configuration from environment variables', () => {
const config = getConfiguration()
expect(config).toEqual({
applicationConfig: 'config.json',
instaInfraFolder: '/infra',
baseFolder: '/base',
dataCatererVersion: '1.0.0'
})
})
it('overrides environment variables with GitHub Action inputs', () => {
core.getInput.mockImplementation(name => {
const inputs = {
configuration_file: 'input_config.json',
insta_infra_folder: '/input_infra',
base_folder: '/input_base',
data_caterer_version: '2.0.0'
}
return inputs[name] || ''
})
const config = getConfiguration()
expect(config).toEqual({
applicationConfig: 'input_config.json',
instaInfraFolder: '/input_infra',
baseFolder: '/input_base',
dataCatererVersion: '2.0.0'
})
})
})