Skip to content

Commit

Permalink
🧪 add test for delete geopoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Alban Rahier committed Nov 6, 2022
1 parent 7b59a61 commit e40b27b
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controller

import (
"bytes"
"database/sql"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -410,6 +411,38 @@ func TestGetRestrictedGeoPoint(t *testing.T) {
}
}

func TestDeleteGeoPoint(t *testing.T) {
tests := []struct {
IdToDelete int
JWT string
StatusCode int
}{
{geoIdEnabled, "", http.StatusUnauthorized},
{12000, validTokens[0], http.StatusNotFound},
{geoIdEnabled, validTokens[0], http.StatusOK},
}

for _, test := range tests {
w := httptest.NewRecorder()

req, _ := http.NewRequest(http.MethodDelete, fmt.Sprintf("/api/v1/restricted/geopoint/%d", test.IdToDelete), nil)

if test.JWT != "" {
// Write authorization token in header
req.Header.Set("Authorization", fmt.Sprintf("Bearer %v", test.JWT))
}

r.ServeHTTP(w, req)
assert.Equal(t, test.StatusCode, w.Code)

if test.StatusCode == http.StatusOK {
var geoPoint geopoint.DbGeoPoint
err := c.Db.Get(&geoPoint, "SELECT * FROM geopoints WHERE id = $1", test.IdToDelete)
assert.Equal(t, err, sql.ErrNoRows)
}
}
}

func TestMakeAdmin(t *testing.T) {
tests := []struct {
Id int
Expand Down

0 comments on commit e40b27b

Please sign in to comment.