|
16 | 16 |
|
17 | 17 | import { describe, it, beforeEach, afterEach, expect, vi } from 'vitest'; |
18 | 18 | import { PluginLoader } from '../src/plugin'; |
19 | | -import { Action } from '../src/proxy/actions'; |
| 19 | +import { Action, ActionType, RequestType } from '../src/proxy/actions'; |
20 | 20 |
|
21 | 21 | const mockLoader = { |
22 | 22 | pushPlugins: [ |
@@ -113,14 +113,14 @@ describe('proxy chain', function () { |
113 | 113 | it('getChain should set pluginLoaded if loader is undefined', async () => { |
114 | 114 | chain.chainPluginLoader = undefined; |
115 | 115 | const actual = await chain.getChain({ type: 'push' }); |
116 | | - expect(actual).toEqual(chain.pushActionChain); |
| 116 | + expect(actual).toEqual(chain.branchPushChain); |
117 | 117 | expect(chain.chainPluginLoader).toBeUndefined(); |
118 | 118 | expect(chain.pluginsInserted).toBe(true); |
119 | 119 | }); |
120 | 120 |
|
121 | 121 | it('getChain should load plugins from an initialized PluginLoader', async () => { |
122 | 122 | chain.chainPluginLoader = mockLoader; |
123 | | - const initialChain = [...chain.pushActionChain]; |
| 123 | + const initialChain = [...chain.branchPushChain]; |
124 | 124 | const actual = await chain.getChain({ type: 'push' }); |
125 | 125 | expect(actual.length).toBeGreaterThan(initialChain.length); |
126 | 126 | expect(chain.pluginsInserted).toBe(true); |
@@ -444,4 +444,58 @@ describe('proxy chain', function () { |
444 | 444 |
|
445 | 445 | expect(consoleErrorSpy).toHaveBeenCalledWith('Error during auto-rejection:', error.message); |
446 | 446 | }); |
| 447 | + |
| 448 | + it('returns pullActionChain for pull actions', async () => { |
| 449 | + const action = new Action( |
| 450 | + '1', |
| 451 | + RequestType.PULL, |
| 452 | + 'GET', |
| 453 | + Date.now(), |
| 454 | + 'http://github.com/owner/repo.git', |
| 455 | + ); |
| 456 | + const pullChain = await chain.getChain(action); |
| 457 | + expect(pullChain).toEqual(chain.pullActionChain); |
| 458 | + }); |
| 459 | + |
| 460 | + it('returns tagPushChain when action.type is push and action.actionType is TAG', async () => { |
| 461 | + const action = new Action( |
| 462 | + '2', |
| 463 | + RequestType.PUSH, |
| 464 | + 'POST', |
| 465 | + Date.now(), |
| 466 | + 'http://github.com/owner/repo.git', |
| 467 | + ); |
| 468 | + action.actionType = ActionType.TAG; |
| 469 | + const tagChain = await chain.getChain(action); |
| 470 | + expect(tagChain).toEqual(chain.tagPushChain); |
| 471 | + }); |
| 472 | + |
| 473 | + it('returns branchPushChain when action.type is push and actionType is BRANCH', async () => { |
| 474 | + const action = new Action( |
| 475 | + '3', |
| 476 | + RequestType.PUSH, |
| 477 | + 'POST', |
| 478 | + Date.now(), |
| 479 | + 'http://github.com/owner/repo.git', |
| 480 | + ); |
| 481 | + action.actionType = ActionType.BRANCH; |
| 482 | + const branchChain = await chain.getChain(action); |
| 483 | + expect(branchChain).toEqual(chain.branchPushChain); |
| 484 | + }); |
| 485 | + |
| 486 | + it('getChain should return tagPushChain if loader is undefined for tag pushes', async () => { |
| 487 | + chain.chainPluginLoader = undefined; |
| 488 | + const actual = await chain.getChain({ type: RequestType.PUSH, actionType: ActionType.TAG }); |
| 489 | + expect(actual).toEqual(chain.tagPushChain); |
| 490 | + expect(chain.chainPluginLoader).toBeUndefined(); |
| 491 | + expect(chain.pluginsInserted).toBe(true); |
| 492 | + }); |
| 493 | + |
| 494 | + it('getChain should load tag plugins from an initialized PluginLoader', async () => { |
| 495 | + chain.chainPluginLoader = mockLoader; |
| 496 | + const initialChain = [...chain.tagPushChain]; |
| 497 | + const actual = await chain.getChain({ type: RequestType.PUSH, actionType: ActionType.TAG }); |
| 498 | + expect(actual.length).toBeGreaterThan(initialChain.length); |
| 499 | + expect(chain.pluginsInserted).toBe(true); |
| 500 | + }); |
447 | 501 | }); |
0 commit comments