Skip to content

Commit 06db45a

Browse files
committed
improve unit tests
1 parent 1efe2cd commit 06db45a

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

__tests__/functions/params.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ test('with empty param object', async () => {
1313
})
1414

1515
test('it parses positional parameters', async () => {
16-
expect(parseParams('foo')).toHaveProperty('_', ['foo'])
16+
expect(parseParams('foo bar baz')).toHaveProperty('_', ['foo', 'bar', 'baz'])
1717
})
1818

1919
test('it parses arguments using the default settings of library', async () => {
20-
const parsed = parseParams('--foo bar --env.foo=bar')
20+
const parsed = parseParams('--foo bar --env.foo=bar baz')
2121
expect(parsed).toHaveProperty('foo', 'bar')
2222
expect(parsed).toHaveProperty('env', {foo: 'bar'})
23-
expect(parsed).toHaveProperty('_', [])
23+
expect(parsed).toHaveProperty('_', ['baz'])
2424
})
2525

2626
test('it works with empty string', async () => {

__tests__/main.test.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,9 +1069,51 @@ test('stores params and parsed params into context', async () => {
10691069
}
10701070
const data = expect.objectContaining({
10711071
auto_merge: true,
1072+
ref: 'test-ref',
1073+
environment: 'production',
1074+
owner: 'corp',
1075+
repo: 'test',
1076+
production_environment: true,
1077+
required_contexts: [],
10721078
payload: expect.objectContaining({
10731079
params,
1074-
parsed_params
1080+
parsed_params,
1081+
sha: null,
1082+
type: 'branch-deploy'
1083+
})
1084+
})
1085+
expect(await run()).toBe('success')
1086+
expect(createDeploymentMock).toHaveBeenCalledWith(data)
1087+
expect(setOutputMock).toHaveBeenCalledWith('params', params)
1088+
expect(setOutputMock).toHaveBeenCalledWith('parsed_params', parsed_params)
1089+
})
1090+
1091+
test('stores params and parsed params into context with complex params', async () => {
1092+
github.context.payload.comment.body =
1093+
'.deploy | something1 --foo=bar --env.development=false --env.production=true'
1094+
const params =
1095+
'something1 --foo=bar --env.development=false --env.production=true'
1096+
const parsed_params = {
1097+
_: ['something1'],
1098+
foo: 'bar',
1099+
env: {
1100+
development: 'false',
1101+
production: 'true'
1102+
}
1103+
}
1104+
const data = expect.objectContaining({
1105+
auto_merge: true,
1106+
ref: 'test-ref',
1107+
environment: 'production',
1108+
owner: 'corp',
1109+
repo: 'test',
1110+
production_environment: true,
1111+
required_contexts: [],
1112+
payload: expect.objectContaining({
1113+
params,
1114+
parsed_params,
1115+
sha: null,
1116+
type: 'branch-deploy'
10751117
})
10761118
})
10771119
expect(await run()).toBe('success')

0 commit comments

Comments
 (0)