11/* eslint-disable no-unused-expressions */
2- // import chai from 'chai';
2+ import chai from 'chai' ;
33import request from 'supertest' ;
44import sinon from 'sinon' ;
55
@@ -8,7 +8,24 @@ import server from '../../app';
88import testUtil from '../../tests/util' ;
99import SalesforceService from '../../services/salesforceService' ;
1010
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+ ] ;
1229
1330describe ( 'Project Billing Accounts list' , ( ) => {
1431 let project1 ;
@@ -54,10 +71,7 @@ describe('Project Billing Accounts list', () => {
5471 accessToken : 'mock' ,
5572 instanceUrl : 'mock_url' ,
5673 } ) ) ;
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 ) ) ;
6175 done ( ) ;
6276 } ) ;
6377 } ) ;
@@ -80,17 +94,48 @@ describe('Project Billing Accounts list', () => {
8094 . expect ( 403 , done ) ;
8195 } ) ;
8296
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 ) => {
8498 request ( server )
8599 . get ( `/v5/projects/${ project1 . id } /billingAccounts` )
86100 . set ( {
87- Authorization : `Bearer ${ testUtil . jwts . member2 } ` ,
101+ Authorization : `Bearer ${ testUtil . jwts . member } ` ,
88102 } )
89103 . send ( )
90104 . expect ( 403 , done ) ;
91105 } ) ;
92106
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 ) => {
94139 request ( server )
95140 . get ( `/v5/projects/${ project1 . id } /billingAccounts` )
96141 . set ( {
@@ -104,13 +149,15 @@ describe('Project Billing Accounts list', () => {
104149 } else {
105150 const resJson = res . body ;
106151 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 ] ) ;
108155 done ( ) ;
109156 }
110157 } ) ;
111158 } ) ;
112159
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 ) => {
114161 request ( server )
115162 . get ( `/v5/projects/${ project1 . id } /billingAccounts` )
116163 . set ( {
@@ -124,7 +171,9 @@ describe('Project Billing Accounts list', () => {
124171 } else {
125172 const resJson = res . body ;
126173 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 ] ) ;
128177 done ( ) ;
129178 }
130179 } ) ;
0 commit comments