@@ -66,7 +66,6 @@ func TestCreateOrganization(t *testing.T) {
66
66
org_payload := map [string ]string {
67
67
"name" : "Test Organization" ,
68
68
}
69
- fmt .Println (org_payload )
70
69
//
71
70
body , _ := utils .MakeRequest ("POST" , t , app , "/orgs" , org_payload , map [string ]string {
72
71
"Authorization" : "Bearer " + auth_token ,
@@ -77,21 +76,68 @@ func TestCreateOrganization(t *testing.T) {
77
76
}
78
77
79
78
// 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 )
81
113
82
- if err != nil {
83
- t . Errorf ( "Failed to parse organization ID: %v" , err )
114
+ org_payload := map [ string ] string {
115
+ "name" : "Test Organization" ,
84
116
}
85
117
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 {
87
129
ID : sql.NullInt32 {
88
130
Int32 : int32 (id ),
89
131
Valid : true ,
90
132
},
91
133
}
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" )
94
139
}
140
+
95
141
DeleteAuthUser (t , auth_token )
96
142
})
97
143
}
0 commit comments