@@ -27,7 +27,7 @@ describe('POST /projects (e2e)', () => {
2727 } ) ;
2828
2929 test ( '201: creates project with all fields (e2e)' , async ( ) => {
30- const res = await fetch ( 'http://localhost:3000/projects' , {
30+ const res = await fetch ( ` ${ base } ` , {
3131 method : 'POST' ,
3232 headers : { 'Content-Type' : 'application/json' } ,
3333 body : JSON . stringify ( {
@@ -73,4 +73,34 @@ describe('POST /projects (e2e)', () => {
7373 } ) ;
7474 expect ( res . status ) . toBe ( 201 ) ;
7575 } ) ;
76+ } ) ;
77+
78+ describe ( 'GET /projects/{id}/expenditures (e2e)' , ( ) => {
79+ test ( "get expenditures for project 1 test 🌞" , async ( ) => {
80+ let res = await fetch ( `${ base } /1/expenditures` ) ;
81+ expect ( res . status ) . toBe ( 200 ) ;
82+ let body = await res . json ( ) ;
83+ expect ( Array . isArray ( body ) ) . toBe ( true ) ;
84+ } ) ;
85+
86+ test ( "expenditures 404 test 🌞" , async ( ) => {
87+ let res = await fetch ( `${ base } /99999/expenditures` ) ;
88+ expect ( res . status ) . toBe ( 404 ) ;
89+ let body = await res . json ( ) ;
90+ expect ( body . message ) . toBe ( 'Project not found' ) ;
91+ } ) ;
92+
93+ test ( "expenditures ordered by spent_on test 🌞" , async ( ) => {
94+ let res = await fetch ( `${ base } /1/expenditures` ) ;
95+ expect ( res . status ) . toBe ( 200 ) ;
96+ let body = await res . json ( ) ;
97+
98+ if ( body . length > 1 ) {
99+ for ( let i = 0 ; i < body . length - 1 ; i ++ ) {
100+ let current = new Date ( body [ i ] . spent_on ) ;
101+ let next = new Date ( body [ i + 1 ] . spent_on ) ;
102+ expect ( current >= next ) . toBe ( true ) ;
103+ }
104+ }
105+ } ) ;
76106} ) ;
0 commit comments