1- const { expect } = require ( 'chai' ) ;
1+ const chai = require ( 'chai' ) ;
22const sinon = require ( 'sinon' ) ;
33const proxyquire = require ( 'proxyquire' ) . noCallThru ( ) ;
44const { Step } = require ( '../../src/proxy/actions' ) ;
55
6- describe ( 'blockForAuth.exec' , ( ) => {
7- let req ;
6+ chai . should ( ) ;
7+ const expect = chai . expect ;
8+
9+ describe ( 'blockForAuth' , ( ) => {
810 let action ;
9- let getServiceUIURLStub ;
1011 let exec ;
12+ let getServiceUIURLStub ;
13+ let req ;
1114 let stepInstance ;
1215 let StepSpy ;
1316
@@ -24,65 +27,70 @@ describe('blockForAuth.exec', () => {
2427
2528 stepInstance = new Step ( 'temp' ) ;
2629 sinon . stub ( stepInstance , 'setAsyncBlock' ) ;
27-
30+
2831 StepSpy = sinon . stub ( ) . returns ( stepInstance ) ;
2932
3033 getServiceUIURLStub = sinon . stub ( ) . returns ( 'http://localhost:8080' ) ;
31-
32- ( { exec } = proxyquire ( '../../src/proxy/processors/push-action/blockForAuth' , {
34+
35+ const blockForAuth = proxyquire ( '../../src/proxy/processors/push-action/blockForAuth' , {
3336 '../../../service/urls' : { getServiceUIURL : getServiceUIURLStub } ,
3437 '../../actions' : { Step : StepSpy }
35- } ) ) ;
38+ } ) ;
39+
40+ exec = blockForAuth . exec ;
3641 } ) ;
3742
3843 afterEach ( ( ) => {
3944 sinon . restore ( ) ;
4045 } ) ;
4146
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+ describe ( 'exec' , ( ) => {
4748
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- } ) ;
49+ it ( 'should generate a correct shareable URL' , async ( ) => {
50+ await exec ( req , action ) ;
51+ expect ( getServiceUIURLStub . calledOnce ) . to . be . true ;
52+ expect ( getServiceUIURLStub . calledWithExactly ( req ) ) . to . be . true ;
53+ } ) ;
6154
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- } ) ;
55+ it ( 'should create step with correct parameters' , async ( ) => {
56+ await exec ( req , action ) ;
6757
68- it ( 'should return action instance' , async ( ) => {
69- const result = await exec ( req , action ) ;
70- expect ( result ) . to . equal ( action ) ;
71- } ) ;
58+ expect ( StepSpy . calledOnce ) . to . be . true ;
59+ expect ( StepSpy . calledWithExactly ( 'authBlock' ) ) . to . be . true ;
60+ expect ( stepInstance . setAsyncBlock . calledOnce ) . to . be . true ;
7261
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- } ) ;
62+ const message = stepInstance . setAsyncBlock . firstCall . args [ 0 ] ;
63+ expect ( message ) . to . include ( 'http://localhost:8080/dashboard/push/push_123' ) ;
64+ expect ( message ) . to . include ( '\x1B[32mGitProxy has received your push ✅\x1B[0m' ) ;
65+ expect ( message ) . to . include ( '\x1B[34mhttp://localhost:8080/dashboard/push/push_123\x1B[0m' ) ;
66+ expect ( message ) . to . include ( '🔗 Shareable Link' ) ;
67+ } ) ;
68+
69+ it ( 'should add step to action exactly once' , async ( ) => {
70+ await exec ( req , action ) ;
71+ expect ( action . addStep . calledOnce ) . to . be . true ;
72+ expect ( action . addStep . calledWithExactly ( stepInstance ) ) . to . be . true ;
73+ } ) ;
74+
75+ it ( 'should return action instance' , async ( ) => {
76+ const result = await exec ( req , action ) ;
77+ expect ( result ) . to . equal ( action ) ;
78+ } ) ;
79+
80+ it ( 'should handle https URL format' , async ( ) => {
81+ getServiceUIURLStub . returns ( 'https://git-proxy-hosted-ui.com' ) ;
82+ await exec ( req , action ) ;
83+
84+ const message = stepInstance . setAsyncBlock . firstCall . args [ 0 ] ;
85+ expect ( message ) . to . include ( 'https://git-proxy-hosted-ui.com/dashboard/push/push_123' ) ;
86+ } ) ;
87+
88+ it ( 'should handle special characters in action ID' , async ( ) => {
89+ action . id = 'push@special#chars!' ;
90+ await exec ( req , action ) ;
8091
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!' ) ;
92+ const message = stepInstance . setAsyncBlock . firstCall . args [ 0 ] ;
93+ expect ( message ) . to . include ( '/push/push@special#chars!' ) ;
94+ } ) ;
8795 } ) ;
8896} ) ;
0 commit comments