1
1
/* eslint-disable no-unused-expressions */
2
- // import chai from 'chai';
2
+ import chai from 'chai' ;
3
3
import request from 'supertest' ;
4
4
import sinon from 'sinon' ;
5
5
@@ -8,7 +8,24 @@ import server from '../../app';
8
8
import testUtil from '../../tests/util' ;
9
9
import SalesforceService from '../../services/salesforceService' ;
10
10
11
- // const should = chai.should();
11
+ chai . should ( ) ;
12
+
13
+ // demo data which might be returned by the `SalesforceService.query`
14
+ const billingAccountsData = [
15
+ {
16
+ sfBillingAccountId : 123 ,
17
+ tcBillingAccountId : 123123 ,
18
+ name : 'Billing Account 1' ,
19
+ startDate : '2021-02-10T18:51:27Z' ,
20
+ endDate : '2021-03-10T18:51:27Z' ,
21
+ } , {
22
+ sfBillingAccountId : 456 ,
23
+ tcBillingAccountId : 456456 ,
24
+ name : 'Billing Account 2' ,
25
+ startDate : '2011-02-10T18:51:27Z' ,
26
+ endDate : '2011-03-10T18:51:27Z' ,
27
+ } ,
28
+ ] ;
12
29
13
30
describe ( 'Project Billing Accounts list' , ( ) => {
14
31
let project1 ;
@@ -54,10 +71,7 @@ describe('Project Billing Accounts list', () => {
54
71
accessToken : 'mock' ,
55
72
instanceUrl : 'mock_url' ,
56
73
} ) ) ;
57
- salesforceQuery = sinon . stub ( SalesforceService , 'query' , ( ) => Promise . resolve ( [ {
58
- accessToken : 'mock' ,
59
- instanceUrl : 'mock_url' ,
60
- } ] ) ) ;
74
+ salesforceQuery = sinon . stub ( SalesforceService , 'query' , ( ) => Promise . resolve ( billingAccountsData ) ) ;
61
75
done ( ) ;
62
76
} ) ;
63
77
} ) ;
@@ -80,17 +94,48 @@ describe('Project Billing Accounts list', () => {
80
94
. expect ( 403 , done ) ;
81
95
} ) ;
82
96
83
- it ( 'should return 403 for a regular user who is not a member of the project' , ( done ) => {
97
+ it ( 'should return 403 for a customer user who is a member of the project' , ( done ) => {
84
98
request ( server )
85
99
. get ( `/v5/projects/${ project1 . id } /billingAccounts` )
86
100
. set ( {
87
- Authorization : `Bearer ${ testUtil . jwts . member2 } ` ,
101
+ Authorization : `Bearer ${ testUtil . jwts . member } ` ,
88
102
} )
89
103
. send ( )
90
104
. expect ( 403 , done ) ;
91
105
} ) ;
92
106
93
- it ( 'should return all attachments to admin' , ( done ) => {
107
+ it ( 'should return 403 for a topcoder user who is not a member of the project' , ( done ) => {
108
+ request ( server )
109
+ . get ( `/v5/projects/${ project1 . id } /billingAccounts` )
110
+ . set ( {
111
+ Authorization : `Bearer ${ testUtil . jwts . copilotManager } ` ,
112
+ } )
113
+ . send ( )
114
+ . expect ( 403 , done ) ;
115
+ } ) ;
116
+
117
+ it ( 'should return all billing accounts for a topcoder user who is a member of the project' , ( done ) => {
118
+ request ( server )
119
+ . get ( `/v5/projects/${ project1 . id } /billingAccounts` )
120
+ . set ( {
121
+ Authorization : `Bearer ${ testUtil . jwts . copilot } ` ,
122
+ } )
123
+ . send ( )
124
+ . expect ( 200 )
125
+ . end ( ( err , res ) => {
126
+ if ( err ) {
127
+ done ( err ) ;
128
+ } else {
129
+ const resJson = res . body ;
130
+ resJson . should . have . length ( 2 ) ;
131
+ resJson . should . include ( billingAccountsData [ 0 ] ) ;
132
+ resJson . should . include ( billingAccountsData [ 1 ] ) ;
133
+ done ( ) ;
134
+ }
135
+ } ) ;
136
+ } ) ;
137
+
138
+ it ( 'should return all billing accounts to admin' , ( done ) => {
94
139
request ( server )
95
140
. get ( `/v5/projects/${ project1 . id } /billingAccounts` )
96
141
. set ( {
@@ -104,13 +149,15 @@ describe('Project Billing Accounts list', () => {
104
149
} else {
105
150
const resJson = res . body ;
106
151
resJson . should . have . length ( 2 ) ;
107
- // TODO verify BA fields
152
+ resJson . should . have . length ( 2 ) ;
153
+ resJson . should . include ( billingAccountsData [ 0 ] ) ;
154
+ resJson . should . include ( billingAccountsData [ 1 ] ) ;
108
155
done ( ) ;
109
156
}
110
157
} ) ;
111
158
} ) ;
112
159
113
- xit ( 'should return all attachments using M2M token with "read:user-billing-accounts" scope' , ( done ) => {
160
+ it ( 'should return all billing accounts using M2M token with "read:user-billing-accounts" scope' , ( done ) => {
114
161
request ( server )
115
162
. get ( `/v5/projects/${ project1 . id } /billingAccounts` )
116
163
. set ( {
@@ -124,7 +171,9 @@ describe('Project Billing Accounts list', () => {
124
171
} else {
125
172
const resJson = res . body ;
126
173
resJson . should . have . length ( 2 ) ;
127
- // TODO verify BA fields
174
+ resJson . should . have . length ( 2 ) ;
175
+ resJson . should . include ( billingAccountsData [ 0 ] ) ;
176
+ resJson . should . include ( billingAccountsData [ 1 ] ) ;
128
177
done ( ) ;
129
178
}
130
179
} ) ;
0 commit comments