@@ -66,7 +66,6 @@ func TestCreateOrganization(t *testing.T) {
6666 org_payload := map [string ]string {
6767 "name" : "Test Organization" ,
6868 }
69- fmt .Println (org_payload )
7069 //
7170 body , _ := utils .MakeRequest ("POST" , t , app , "/orgs" , org_payload , map [string ]string {
7271 "Authorization" : "Bearer " + auth_token ,
@@ -77,21 +76,68 @@ func TestCreateOrganization(t *testing.T) {
7776 }
7877
7978 // cleanup
80- id , err := strconv .ParseInt (body ["id" ], 10 , 32 )
79+ DeleteOrganization (t , body ["id" ])
80+ DeleteAuthUser (t , auth_token )
81+ })
82+
83+ }
84+
85+ func DeleteOrganization (t * testing.T , org_id string ) {
86+ id , err := strconv .ParseInt (org_id , 10 , 32 )
87+
88+ if err != nil {
89+ t .Errorf ("Failed to parse organization ID: %v" , err )
90+ }
91+
92+ org := organizations.OrganizationSQL {
93+ ID : sql.NullInt32 {
94+ Int32 : int32 (id ),
95+ Valid : true ,
96+ },
97+ }
98+ if err = org .Delete (); err != nil {
99+ t .Errorf ("Failed to delete organization: %v" , err )
100+ return
101+ }
102+
103+ }
104+
105+ func TestDeleteOrganization (t * testing.T ) {
106+ t .Run ("Delete organization" , func (t * testing.T ) {
107+ app := InitServerOrgs ()
108+ if app == nil {
109+ t .Fatal ("Failed to initialize the application" )
110+ }
111+
112+ auth_token := GetAuthToken (t , app )
81113
82- if err != nil {
83- t . Errorf ( "Failed to parse organization ID: %v" , err )
114+ org_payload := map [ string ] string {
115+ "name" : "Test Organization" ,
84116 }
85117
86- org := organizations.OrganizationSQL {
118+ body , _ := utils .MakeRequest ("POST" , t , app , "/orgs" , org_payload , map [string ]string {
119+ "Authorization" : "Bearer " + auth_token ,
120+ }) //before previous test tests the creation, we should be pretty sure that the creation works
121+
122+ id , _ := strconv .ParseInt (body ["id" ], 10 , 32 )
123+
124+ body , _ = utils .MakeRequest ("DELETE" , t , app , fmt .Sprintf ("/orgs/%d" , id ), nil , map [string ]string {
125+ "Authorization" : "Bearer " + auth_token ,
126+ })
127+
128+ org_dto := organizations.OrganizationSQL {
87129 ID : sql.NullInt32 {
88130 Int32 : int32 (id ),
89131 Valid : true ,
90132 },
91133 }
92- if err = org .Delete (); err != nil {
93- t .Errorf ("Failed to delete organization: %v" , err )
134+
135+ _ , err := org_dto .Get ()
136+
137+ if err == nil {
138+ t .Fatal ("Organization was not deleted" )
94139 }
140+
95141 DeleteAuthUser (t , auth_token )
96142 })
97143}
0 commit comments