@@ -1048,6 +1048,64 @@ func TestPutUserSuspend(t *testing.T) {
1048
1048
})
1049
1049
}
1050
1050
1051
+ func TestPutUserDormant (t * testing.T ) {
1052
+ t .Parallel ()
1053
+
1054
+ t .Run ("MarkOwnerAsDormant" , func (t * testing.T ) {
1055
+ t .Parallel ()
1056
+ client := coderdtest .New (t , nil )
1057
+ me := coderdtest .CreateFirstUser (t , client )
1058
+ _ , user := coderdtest .CreateAnotherUser (t , client , me .OrganizationID , rbac .RoleOwner ())
1059
+
1060
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
1061
+ defer cancel ()
1062
+
1063
+ _ , err := client .UpdateUserStatus (ctx , user .Username , codersdk .UserStatusDormant )
1064
+ require .Error (t , err , "cannot mark owners as dormant" )
1065
+ })
1066
+
1067
+ t .Run ("MarkAnotherUserDormant" , func (t * testing.T ) {
1068
+ t .Parallel ()
1069
+ auditor := audit .NewMock ()
1070
+ client := coderdtest .New (t , & coderdtest.Options {Auditor : auditor })
1071
+ numLogs := len (auditor .AuditLogs ())
1072
+
1073
+ me := coderdtest .CreateFirstUser (t , client )
1074
+ numLogs ++ // add an audit log for user create
1075
+ numLogs ++ // add an audit log for login
1076
+
1077
+ _ , user := coderdtest .CreateAnotherUser (t , client , me .OrganizationID )
1078
+ numLogs ++ // add an audit log for user create
1079
+
1080
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
1081
+ defer cancel ()
1082
+
1083
+ user , err := client .UpdateUserStatus (ctx , user .Username , codersdk .UserStatusDormant )
1084
+ require .NoError (t , err )
1085
+ require .Equal (t , user .Status , codersdk .UserStatusDormant )
1086
+ numLogs ++ // add an audit log for user update
1087
+
1088
+ require .Len (t , auditor .AuditLogs (), numLogs )
1089
+ require .Equal (t , database .AuditActionWrite , auditor .AuditLogs ()[numLogs - 1 ].Action )
1090
+ })
1091
+
1092
+ t .Run ("MarkOwnUserDormant" , func (t * testing.T ) {
1093
+ t .Parallel ()
1094
+ client := coderdtest .New (t , nil )
1095
+ coderdtest .CreateFirstUser (t , client )
1096
+
1097
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
1098
+ defer cancel ()
1099
+
1100
+ client .User (ctx , codersdk .Me )
1101
+ _ , err := client .UpdateUserStatus (ctx , codersdk .Me , codersdk .UserStatusDormant )
1102
+
1103
+ require .ErrorContains (t , err , "cannot mark own user as dormant" )
1104
+ })
1105
+ }
1106
+
1107
+ // FIXME Activate dormant account
1108
+
1051
1109
func TestGetUser (t * testing.T ) {
1052
1110
t .Parallel ()
1053
1111
0 commit comments