1
- const { expect } = require ( 'chai' ) ;
1
+ const chai = require ( 'chai' ) ;
2
2
const sinon = require ( 'sinon' ) ;
3
3
const proxyquire = require ( 'proxyquire' ) . noCallThru ( ) ;
4
4
const { Step } = require ( '../../src/proxy/actions' ) ;
5
5
6
- describe ( 'blockForAuth.exec' , ( ) => {
7
- let req ;
6
+ chai . should ( ) ;
7
+ const expect = chai . expect ;
8
+
9
+ describe ( 'blockForAuth' , ( ) => {
8
10
let action ;
9
- let getServiceUIURLStub ;
10
11
let exec ;
12
+ let getServiceUIURLStub ;
13
+ let req ;
11
14
let stepInstance ;
12
15
let StepSpy ;
13
16
@@ -24,65 +27,70 @@ describe('blockForAuth.exec', () => {
24
27
25
28
stepInstance = new Step ( 'temp' ) ;
26
29
sinon . stub ( stepInstance , 'setAsyncBlock' ) ;
27
-
30
+
28
31
StepSpy = sinon . stub ( ) . returns ( stepInstance ) ;
29
32
30
33
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' , {
33
36
'../../../service/urls' : { getServiceUIURL : getServiceUIURLStub } ,
34
37
'../../actions' : { Step : StepSpy }
35
- } ) ) ;
38
+ } ) ;
39
+
40
+ exec = blockForAuth . exec ;
36
41
} ) ;
37
42
38
43
afterEach ( ( ) => {
39
44
sinon . restore ( ) ;
40
45
} ) ;
41
46
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' , ( ) => {
47
48
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
+ } ) ;
61
54
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 ) ;
67
57
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 ;
72
61
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 ) ;
80
91
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
+ } ) ;
87
95
} ) ;
88
96
} ) ;
0 commit comments