@@ -5532,3 +5532,63 @@ func (s *MethodTestSuite) TestChat() {
5532
5532
}).Asserts (c , policy .ActionUpdate )
5533
5533
}))
5534
5534
}
5535
+
5536
+ func (s * MethodTestSuite ) TestAuthorizePrebuiltWorkspace () {
5537
+ s .Run ("PrebuildDelete/InsertWorkspaceBuild" , s .Subtest (func (db database.Store , check * expects ) {
5538
+ u := dbgen .User (s .T (), db , database.User {})
5539
+ o := dbgen .Organization (s .T (), db , database.Organization {})
5540
+ tpl := dbgen .Template (s .T (), db , database.Template {
5541
+ OrganizationID : o .ID ,
5542
+ CreatedBy : u .ID ,
5543
+ })
5544
+ w := dbgen .Workspace (s .T (), db , database.WorkspaceTable {
5545
+ TemplateID : tpl .ID ,
5546
+ OrganizationID : o .ID ,
5547
+ OwnerID : database .PrebuildsSystemUserID ,
5548
+ })
5549
+ pj := dbgen .ProvisionerJob (s .T (), db , nil , database.ProvisionerJob {
5550
+ OrganizationID : o .ID ,
5551
+ })
5552
+ tv := dbgen .TemplateVersion (s .T (), db , database.TemplateVersion {
5553
+ TemplateID : uuid.NullUUID {UUID : tpl .ID , Valid : true },
5554
+ OrganizationID : o .ID ,
5555
+ CreatedBy : u .ID ,
5556
+ })
5557
+ check .Args (database.InsertWorkspaceBuildParams {
5558
+ WorkspaceID : w .ID ,
5559
+ Transition : database .WorkspaceTransitionDelete ,
5560
+ Reason : database .BuildReasonInitiator ,
5561
+ TemplateVersionID : tv .ID ,
5562
+ JobID : pj .ID ,
5563
+ }).Asserts (w .AsPrebuild (), policy .ActionDelete )
5564
+ }))
5565
+ s .Run ("PrebuildUpdate/InsertWorkspaceBuildParameters" , s .Subtest (func (db database.Store , check * expects ) {
5566
+ u := dbgen .User (s .T (), db , database.User {})
5567
+ o := dbgen .Organization (s .T (), db , database.Organization {})
5568
+ tpl := dbgen .Template (s .T (), db , database.Template {
5569
+ OrganizationID : o .ID ,
5570
+ CreatedBy : u .ID ,
5571
+ })
5572
+ w := dbgen .Workspace (s .T (), db , database.WorkspaceTable {
5573
+ TemplateID : tpl .ID ,
5574
+ OrganizationID : o .ID ,
5575
+ OwnerID : database .PrebuildsSystemUserID ,
5576
+ })
5577
+ pj := dbgen .ProvisionerJob (s .T (), db , nil , database.ProvisionerJob {
5578
+ OrganizationID : o .ID ,
5579
+ })
5580
+ tv := dbgen .TemplateVersion (s .T (), db , database.TemplateVersion {
5581
+ TemplateID : uuid.NullUUID {UUID : tpl .ID , Valid : true },
5582
+ OrganizationID : o .ID ,
5583
+ CreatedBy : u .ID ,
5584
+ })
5585
+ wb := dbgen .WorkspaceBuild (s .T (), db , database.WorkspaceBuild {
5586
+ JobID : pj .ID ,
5587
+ WorkspaceID : w .ID ,
5588
+ TemplateVersionID : tv .ID ,
5589
+ })
5590
+ check .Args (database.InsertWorkspaceBuildParametersParams {
5591
+ WorkspaceBuildID : wb .ID ,
5592
+ }).Asserts (w .AsPrebuild (), policy .ActionUpdate )
5593
+ }))
5594
+ }
0 commit comments