Skip to content

Commit 8423fd0

Browse files
committed
test: blockForAuth action
1 parent 25dbd56 commit 8423fd0

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

test/processors/blockForAuth.test.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
const { expect } = require('chai');
2+
const sinon = require('sinon');
3+
const proxyquire = require('proxyquire').noCallThru();
4+
const { Step } = require('../../src/proxy/actions');
5+
6+
describe('blockForAuth.exec', () => {
7+
let req;
8+
let action;
9+
let getServiceUIURLStub;
10+
let exec;
11+
let stepInstance;
12+
let StepSpy;
13+
14+
beforeEach(() => {
15+
req = {
16+
protocol: 'https',
17+
headers: { host: 'example.com' }
18+
};
19+
20+
action = {
21+
id: 'push_123',
22+
addStep: sinon.stub()
23+
};
24+
25+
stepInstance = new Step('temp');
26+
sinon.stub(stepInstance, 'setAsyncBlock');
27+
28+
StepSpy = sinon.stub().returns(stepInstance);
29+
30+
getServiceUIURLStub = sinon.stub().returns('http://localhost:8080');
31+
32+
({ exec } = proxyquire('../../src/proxy/processors/push-action/blockForAuth', {
33+
'../../../service/urls': { getServiceUIURL: getServiceUIURLStub },
34+
'../../actions': { Step: StepSpy }
35+
}));
36+
});
37+
38+
afterEach(() => {
39+
sinon.restore();
40+
});
41+
42+
it('should generate a correct shareable URL', async () => {
43+
await exec(req, action);
44+
expect(getServiceUIURLStub.calledOnce).to.be.true;
45+
expect(getServiceUIURLStub.calledWithExactly(req)).to.be.true;
46+
});
47+
48+
it('should create step with correct parameters', async () => {
49+
await exec(req, action);
50+
51+
expect(StepSpy.calledOnce).to.be.true;
52+
expect(StepSpy.calledWithExactly('authBlock')).to.be.true;
53+
expect(stepInstance.setAsyncBlock.calledOnce).to.be.true;
54+
55+
const message = stepInstance.setAsyncBlock.firstCall.args[0];
56+
expect(message).to.include('http://localhost:8080/dashboard/push/push_123');
57+
expect(message).to.include('\x1B[32mGitProxy has received your push ✅\x1B[0m');
58+
expect(message).to.include('\x1B[34mhttp://localhost:8080/dashboard/push/push_123\x1B[0m');
59+
expect(message).to.include('🔗 Shareable Link');
60+
});
61+
62+
it('should add step to action exactly once', async () => {
63+
await exec(req, action);
64+
expect(action.addStep.calledOnce).to.be.true;
65+
expect(action.addStep.calledWithExactly(stepInstance)).to.be.true;
66+
});
67+
68+
it('should return action instance', async () => {
69+
const result = await exec(req, action);
70+
expect(result).to.equal(action);
71+
});
72+
73+
it('should handle https URL format', async () => {
74+
getServiceUIURLStub.returns('https://git-proxy-hosted-ui.com');
75+
await exec(req, action);
76+
77+
const message = stepInstance.setAsyncBlock.firstCall.args[0];
78+
expect(message).to.include('https://git-proxy-hosted-ui.com/dashboard/push/push_123');
79+
});
80+
81+
it('should handle special characters in action ID', async () => {
82+
action.id = 'push@special#chars!';
83+
await exec(req, action);
84+
85+
const message = stepInstance.setAsyncBlock.firstCall.args[0];
86+
expect(message).to.include('/push/push@special#chars!');
87+
});
88+
});

0 commit comments

Comments
 (0)