@@ -54,6 +54,33 @@ public function test_index_endpoint_returns_list_of_all_projects_of_organization
5454 $ response ->assertJsonCount (4 , 'data ' );
5555 }
5656
57+ public function test_index_endpoint_returns_projects_ordered_by_created_at_descending (): void
58+ {
59+ // Arrange
60+ $ data = $ this ->createUserWithPermission ([
61+ 'projects:view ' ,
62+ 'projects:view:all ' ,
63+ ]);
64+ $ projectOldest = Project::factory ()->forOrganization ($ data ->organization )->create ([
65+ 'created_at ' => now ()->subDays (3 ),
66+ ]);
67+ $ projectNewest = Project::factory ()->forOrganization ($ data ->organization )->create ([
68+ 'created_at ' => now ()->subDay (),
69+ ]);
70+ $ projectMiddle = Project::factory ()->forOrganization ($ data ->organization )->create ([
71+ 'created_at ' => now ()->subDays (2 ),
72+ ]);
73+ Passport::actingAs ($ data ->user );
74+
75+ // Act
76+ $ response = $ this ->getJson (route ('api.v1.projects.index ' , [$ data ->organization ->getKey ()]));
77+
78+ // Assert
79+ $ response ->assertStatus (200 );
80+ $ ids = collect ($ response ->json ('data ' ))->pluck ('id ' )->values ()->toArray ();
81+ $ this ->assertSame ([$ projectNewest ->getKey (), $ projectMiddle ->getKey (), $ projectOldest ->getKey ()], $ ids );
82+ }
83+
5784 public function test_index_endpoint_without_filter_archived_returns_only_non_archived_projects (): void
5885 {
5986 // Arrange
@@ -211,10 +238,10 @@ public function test_index_endpoint_does_not_set_billable_rate_to_null_if_member
211238 ->has ('data ' )
212239 ->has ('links ' )
213240 ->has ('meta ' )
214- ->where ('data.0.billable_rate ' , 112 )
215- ->where ('data.1.billable_rate ' , 112 )
216- ->where ('data.2.billable_rate ' , 113 )
217- ->where ('data.3.billable_rate ' , 113 )
241+ ->where ('data.0.billable_rate ' , 113 )
242+ ->where ('data.1.billable_rate ' , 113 )
243+ ->where ('data.2.billable_rate ' , 112 )
244+ ->where ('data.3.billable_rate ' , 112 )
218245 );
219246 }
220247
0 commit comments