@@ -479,11 +479,14 @@ func TestAdminViewAllWorkspaces(t *testing.T) {
479
479
func TestWorkspacesSortOrder (t * testing.T ) {
480
480
t .Parallel ()
481
481
482
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
483
+ defer cancel ()
484
+
482
485
client , db := coderdtest .NewWithDatabase (t , nil )
483
486
firstUser := coderdtest .CreateFirstUser (t , client , func (r * codersdk.CreateFirstUserRequest ) {
484
487
r .Username = "aaa"
485
488
})
486
- _ , secondUser := coderdtest .CreateAnotherUserMutators (t , client , firstUser .OrganizationID , []string {"owner" }, func (r * codersdk.CreateUserRequest ) {
489
+ secondUserClient , secondUser := coderdtest .CreateAnotherUserMutators (t , client , firstUser .OrganizationID , []string {"owner" }, func (r * codersdk.CreateUserRequest ) {
487
490
r .Username = "zzz"
488
491
})
489
492
@@ -502,41 +505,61 @@ func TestWorkspacesSortOrder(t *testing.T) {
502
505
// e-workspace should also be stopped
503
506
wsbE := dbfake .WorkspaceBuild (t , db , database.Workspace {Name : "e-workspace" , OwnerID : secondUser .ID , OrganizationID : firstUser .OrganizationID }).Seed (database.WorkspaceBuild {Transition : database .WorkspaceTransitionStop }).Do ()
504
507
505
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
506
- defer cancel ()
508
+ // f-workspace is also stopped, but is marked as favorite
509
+ wsbF := dbfake .WorkspaceBuild (t , db , database.Workspace {Name : "f-workspace" , OwnerID : firstUser .UserID , OrganizationID : firstUser .OrganizationID }).Seed (database.WorkspaceBuild {Transition : database .WorkspaceTransitionStop }).Do ()
510
+ require .NoError (t , client .FavoriteWorkspace (ctx , wsbF .Workspace .ID )) // need to do this via API call for now
511
+
507
512
workspacesResponse , err := client .Workspaces (ctx , codersdk.WorkspaceFilter {})
508
513
require .NoError (t , err , "(first) fetch workspaces" )
509
514
workspaces := workspacesResponse .Workspaces
510
515
511
516
expectedNames := []string {
517
+ wsbF .Workspace .Name , // favorite
512
518
wsbA .Workspace .Name , // running
513
519
wsbC .Workspace .Name , // running
514
520
wsbB .Workspace .Name , // stopped, aaa < zzz
515
521
wsbD .Workspace .Name , // stopped, zzz > aaa
516
522
wsbE .Workspace .Name , // stopped, zzz > aaa
517
523
}
518
524
519
- expectedStatus := []codersdk.WorkspaceStatus {
520
- codersdk .WorkspaceStatusRunning ,
521
- codersdk .WorkspaceStatusRunning ,
522
- codersdk .WorkspaceStatusStopped ,
523
- codersdk .WorkspaceStatusStopped ,
524
- codersdk .WorkspaceStatusStopped ,
525
+ actualNames := make ([]string , 0 , len (expectedNames ))
526
+ for _ , w := range workspaces {
527
+ actualNames = append (actualNames , w .Name )
528
+ }
529
+
530
+ // the correct sorting order is:
531
+ // 1. Favorite workspaces (we have one, workspace-f)
532
+ // 2. Running workspaces
533
+ // 3. Sort by usernames
534
+ // 4. Sort by workspace names
535
+ require .Equal (t , expectedNames , actualNames )
536
+
537
+ // Once again but this time as a different user. This time we do not expect to see another
538
+ // user's favorites first.
539
+ workspacesResponse , err = secondUserClient .Workspaces (ctx , codersdk.WorkspaceFilter {})
540
+ require .NoError (t , err , "(second) fetch workspaces" )
541
+ workspaces = workspacesResponse .Workspaces
542
+
543
+ expectedNames = []string {
544
+ wsbA .Workspace .Name , // running
545
+ wsbC .Workspace .Name , // running
546
+ wsbB .Workspace .Name , // stopped, aaa < zzz
547
+ wsbF .Workspace .Name , // stopped, aaa < zzz
548
+ wsbD .Workspace .Name , // stopped, zzz > aaa
549
+ wsbE .Workspace .Name , // stopped, zzz > aaa
525
550
}
526
551
527
- var actualNames []string
528
- var actualStatus []codersdk.WorkspaceStatus
552
+ actualNames = make ([]string , 0 , len (expectedNames ))
529
553
for _ , w := range workspaces {
530
554
actualNames = append (actualNames , w .Name )
531
- actualStatus = append (actualStatus , w .LatestBuild .Status )
532
555
}
533
556
534
557
// the correct sorting order is:
535
- // 1. Running workspaces
536
- // 2. Sort by usernames
537
- // 3. Sort by workspace names
538
- assert . Equal ( t , expectedNames , actualNames )
539
- assert .Equal (t , expectedStatus , actualStatus )
558
+ // 1. Favorite workspaces (we have none this time)
559
+ // 2. Running workspaces
560
+ // 3. Sort by usernames
561
+ // 4. Sort by workspace names
562
+ require .Equal (t , expectedNames , actualNames )
540
563
}
541
564
542
565
func TestPostWorkspacesByOrganization (t * testing.T ) {
0 commit comments