test: fix tests

This commit is contained in:
joseph-sentry 2024-07-29 11:33:50 -04:00
parent 0c23ec5ce3
commit f1d218aabf
No known key found for this signature in database
3 changed files with 35 additions and 3 deletions

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -5,6 +5,7 @@ import {
buildGeneralExec,
buildReportExec,
buildUploadExec,
getToken,
} from './buildExec';
const context = github.context;
@ -280,6 +281,12 @@ test('commit args using context', async () => {
if (context.eventName == 'pull_request') {
expectedArgs.push('-C', `${context.payload.pull_request?.head.sha}`);
}
if (
(context.eventName == 'pull_request' || context.eventName == 'pull_request_target') &&
context.payload.pull_request?.base.label.split(':')[0] != context.payload.pull_request?.head.label.split(':')[0]
) {
expectedArgs.push('-B', `${context.payload.pull_request?.head.label}`);
}
if (context.eventName == 'pull_request_target') {
expectedArgs.push('-P', `${context.payload.number}`);
}
@ -300,15 +307,20 @@ test('commit args using github server url', async () => {
if (context.eventName == 'pull_request') {
expectedArgs.push('-C', `${context.payload.pull_request?.head.sha}`);
}
if (
(context.eventName == 'pull_request' || context.eventName == 'pull_request_target') &&
context.payload.pull_request?.base.label.split(':')[0] != context.payload.pull_request?.head.label.split(':')[0]
) {
expectedArgs.push('-B', `${context.payload.pull_request?.head.label}`);
}
if (context.eventName == 'pull_request_target') {
expectedArgs.push('-P', `${context.payload.number}`);
}
expect(commitExecArgs).toEqual(expectedArgs);
expect(commitCommand).toEqual('create-commit');
});
test('get token when token arg is unset and from fork', async () => {
test('build commit args when token arg is unset and from fork', async () => {
context.eventName = 'pull_request';
context.payload.pull_request = {
'number': 1,
@ -335,3 +347,22 @@ test('get token when token arg is unset and from fork', async () => {
expect(commitExecArgs).toEqual(expectedArgs);
expect(commitCommand).toEqual('create-commit');
});
test('get token when token arg is unset and from fork', async () => {
context.eventName = 'pull_request';
context.payload.pull_request = {
'number': 1,
'base': {
'label': 'hello:main',
},
'head': {
'label': 'world:feat',
'sha': 'aaaaaa',
},
};
const token = await getToken();
expect(token).toEqual(null);
});

View file

@ -412,4 +412,5 @@ export {
buildGeneralExec,
buildReportExec,
buildUploadExec,
getToken,
};