@@ -1573,3 +1573,88 @@ func TestConnectHandler_DisableGroup(t *testing.T) {
15731573 })
15741574 }
15751575}
1576+
1577+ func TestConnectHandler_DeleteGroup (t * testing.T ) {
1578+ randomID := utils .NewString ()
1579+ tests := []struct {
1580+ name string
1581+ setup func (gs * mocks.GroupService , os * mocks.OrganizationService )
1582+ request * connect.Request [frontierv1beta1.DeleteGroupRequest ]
1583+ want * connect.Response [frontierv1beta1.DeleteGroupResponse ]
1584+ wantErr error
1585+ }{
1586+ {
1587+ name : "should return error if organization does not exist" ,
1588+ setup : func (gs * mocks.GroupService , os * mocks.OrganizationService ) {
1589+ os .EXPECT ().Get (mock .Anything , testOrgID ).Return (organization.Organization {}, organization .ErrNotExist )
1590+ },
1591+ request : connect .NewRequest (& frontierv1beta1.DeleteGroupRequest {
1592+ Id : randomID ,
1593+ OrgId : testOrgID ,
1594+ }),
1595+ want : nil ,
1596+ wantErr : connect .NewError (connect .CodeNotFound , ErrOrgNotFound ),
1597+ },
1598+ {
1599+ name : "should return error if organization is disabled" ,
1600+ setup : func (gs * mocks.GroupService , os * mocks.OrganizationService ) {
1601+ os .EXPECT ().Get (mock .Anything , testOrgID ).Return (organization.Organization {}, organization .ErrDisabled )
1602+ },
1603+ request : connect .NewRequest (& frontierv1beta1.DeleteGroupRequest {
1604+ Id : randomID ,
1605+ OrgId : testOrgID ,
1606+ }),
1607+ want : nil ,
1608+ wantErr : connect .NewError (connect .CodeNotFound , ErrOrgDisabled ),
1609+ },
1610+ {
1611+ name : "should return error if group does not exist" ,
1612+ setup : func (gs * mocks.GroupService , os * mocks.OrganizationService ) {
1613+ os .EXPECT ().Get (mock .Anything , testOrgID ).Return (organization.Organization {ID : testOrgID }, nil )
1614+ gs .EXPECT ().Delete (mock .Anything , randomID ).Return (group .ErrNotExist )
1615+ },
1616+ request : connect .NewRequest (& frontierv1beta1.DeleteGroupRequest {
1617+ Id : randomID ,
1618+ OrgId : testOrgID ,
1619+ }),
1620+ want : nil ,
1621+ wantErr : connect .NewError (connect .CodeNotFound , ErrGroupNotFound ),
1622+ },
1623+ {
1624+ name : "should delete group successfully" ,
1625+ setup : func (gs * mocks.GroupService , os * mocks.OrganizationService ) {
1626+ os .EXPECT ().Get (mock .Anything , testOrgID ).Return (organization.Organization {ID : testOrgID }, nil )
1627+ gs .EXPECT ().Delete (mock .Anything , randomID ).Return (nil )
1628+ },
1629+ request : connect .NewRequest (& frontierv1beta1.DeleteGroupRequest {
1630+ Id : randomID ,
1631+ OrgId : testOrgID ,
1632+ }),
1633+ want : connect .NewResponse (& frontierv1beta1.DeleteGroupResponse {}),
1634+ wantErr : nil ,
1635+ },
1636+ }
1637+
1638+ for _ , tt := range tests {
1639+ t .Run (tt .name , func (t * testing.T ) {
1640+ mockGroupSvc := new (mocks.GroupService )
1641+ mockOrgSvc := new (mocks.OrganizationService )
1642+ if tt .setup != nil {
1643+ tt .setup (mockGroupSvc , mockOrgSvc )
1644+ }
1645+ h := ConnectHandler {
1646+ groupService : mockGroupSvc ,
1647+ orgService : mockOrgSvc ,
1648+ }
1649+ got , err := h .DeleteGroup (context .Background (), tt .request )
1650+ if tt .wantErr != nil {
1651+ assert .Error (t , err )
1652+ assert .Equal (t , tt .wantErr .(* connect.Error ).Code (), err .(* connect.Error ).Code ())
1653+ assert .Equal (t , tt .wantErr .(* connect.Error ).Message (), err .(* connect.Error ).Message ())
1654+ } else {
1655+ assert .NoError (t , err )
1656+ assert .EqualValues (t , tt .want , got )
1657+ }
1658+ })
1659+ }
1660+ }
0 commit comments