Skip to content

Commit ddfae87

Browse files
committed
test: add unit and integration tests for tag push
1 parent c84142c commit ddfae87

5 files changed

Lines changed: 847 additions & 9 deletions

File tree

test/chain.test.ts

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { describe, it, beforeEach, afterEach, expect, vi } from 'vitest';
1818
import { PluginLoader } from '../src/plugin';
19-
import { Action } from '../src/proxy/actions';
19+
import { Action, ActionType, RequestType } from '../src/proxy/actions';
2020

2121
const mockLoader = {
2222
pushPlugins: [
@@ -113,14 +113,14 @@ describe('proxy chain', function () {
113113
it('getChain should set pluginLoaded if loader is undefined', async () => {
114114
chain.chainPluginLoader = undefined;
115115
const actual = await chain.getChain({ type: 'push' });
116-
expect(actual).toEqual(chain.pushActionChain);
116+
expect(actual).toEqual(chain.branchPushChain);
117117
expect(chain.chainPluginLoader).toBeUndefined();
118118
expect(chain.pluginsInserted).toBe(true);
119119
});
120120

121121
it('getChain should load plugins from an initialized PluginLoader', async () => {
122122
chain.chainPluginLoader = mockLoader;
123-
const initialChain = [...chain.pushActionChain];
123+
const initialChain = [...chain.branchPushChain];
124124
const actual = await chain.getChain({ type: 'push' });
125125
expect(actual.length).toBeGreaterThan(initialChain.length);
126126
expect(chain.pluginsInserted).toBe(true);
@@ -444,4 +444,58 @@ describe('proxy chain', function () {
444444

445445
expect(consoleErrorSpy).toHaveBeenCalledWith('Error during auto-rejection:', error.message);
446446
});
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+
});
447501
});

test/db/mongo/push.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,12 @@ describe('MongoDB Push Handler', async () => {
113113
rejected: 1,
114114
repo: 1,
115115
repoName: 1,
116+
tag: 1,
117+
tagData: 1,
116118
timestamp: 1,
117119
type: 1,
118120
url: 1,
121+
user: 1,
119122
},
120123
sort: {
121124
timestamp: -1,

0 commit comments

Comments
 (0)