diff --git a/src/gitlab_service.ts b/src/gitlab_service.ts index 17c97196ff549e52ec03f75aed87339ffd60d415..71b29848b7ac53ea4dc4b76185376b8db6c4813d 100644 --- a/src/gitlab_service.ts +++ b/src/gitlab_service.ts @@ -444,7 +444,7 @@ export async function handlePipelineAction(action: string, repositoryRoot: strin } try { - const { response } = await fetch(endpoint, 'POST'); + const { response } = await fetch(repositoryRoot, endpoint, 'POST'); return response; } catch (e) { throw new UserFriendlyError(`Failed to ${action} pipeline.`, e); diff --git a/test/integration/pipeline_actions.test.js b/test/integration/pipeline_actions.test.js new file mode 100644 index 0000000000000000000000000000000000000000..3bfc2b7fd9d24a254b9ee122f9d38d141b7cf4b9 --- /dev/null +++ b/test/integration/pipeline_actions.test.js @@ -0,0 +1,56 @@ +const assert = require('assert'); +const sinon = require('sinon'); +const { tokenService } = require('../../src/services/token_service'); +const pipelinesResponse = require('./fixtures/rest/pipelines.json'); +const { + getServer, + createTextEndpoint, + createQueryJsonEndpoint, + createPostEndpoint, +} = require('./test_infrastructure/mock_server'); +const { GITLAB_URL } = require('./test_infrastructure/constants'); +const { simulateQuickPickChoice } = require('./test_infrastructure/helpers'); +const { showPicker } = require('../../src/pipeline_actions_picker'); +const { instance: statusbar } = require('../../src/status_bar'); + +describe('Pipeline actions', async () => { + let server; + let statusBarRefreshSpy; + const sandbox = sinon.createSandbox(); + + before(async () => { + server = getServer([ + createQueryJsonEndpoint('/projects/278964/pipelines', { '?ref=master': pipelinesResponse }), + createTextEndpoint( + '/projects/278964/snippets/222/files/master/test2.js/raw', + 'second blob content', + ), + createPostEndpoint('/projects/278964/pipeline', pipelinesResponse[0]), // simulating returning a newly created pipeline + ]); + await tokenService.setToken(GITLAB_URL, 'abcd-secret'); + }); + + beforeEach(async () => { + server.resetHandlers(); + statusBarRefreshSpy = sandbox.spy(statusbar, 'refresh'); + }); + + afterEach(async () => { + sandbox.restore(); + }); + + after(async () => { + server.close(); + await tokenService.setToken(GITLAB_URL, undefined); + }); + + it('creates a new pipeline', async () => { + simulateQuickPickChoice(sandbox, 1); // Create a new pipeline from current branch + await showPicker(); + + assert( + statusBarRefreshSpy.calledOnce, + 'status bar is refreshed after successful pipeline creation', + ); + }); +});