Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added UTs for GetAllTribes, GetTotalTribes & GetListedTribes #1555

Closed
wants to merge 10 commits into from
1 change: 1 addition & 0 deletions db/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func InitDB() {
fmt.Println("db connected")

// migrate table changes
db.AutoMigrate(&Tribe{})
db.AutoMigrate(&Person{})
db.AutoMigrate(&Channel{})
db.AutoMigrate(&LeaderBoard{})
Expand Down
6 changes: 3 additions & 3 deletions db/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"strconv"
"time"
Expand Down Expand Up @@ -175,7 +175,7 @@ func Verify(w http.ResponseWriter, r *http.Request) {
}

payload := VerifyPayload{}
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
r.Body.Close()
err = json.Unmarshal(body, &payload)
if err != nil {
Expand Down Expand Up @@ -263,7 +263,7 @@ type Save struct {
func PostSave(w http.ResponseWriter, r *http.Request) {

save := Save{}
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
r.Body.Close()
err = json.Unmarshal(body, &save)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions db/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Tribe struct {
Deleted bool `json:"deleted"`
AppURL string `json:"app_url"`
FeedURL string `json:"feed_url"`
SecondBrainUrl string `json:"second_brain_url"`
FeedType uint64 `json:"feed_type"`
LastActive int64 `json:"last_active"`
Bots string `json:"bots"`
Expand Down
4 changes: 2 additions & 2 deletions feeds/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package feeds

import (
"encoding/json"
"io/ioutil"
"io"
"net/http"
"strings"
)
Expand Down Expand Up @@ -161,6 +161,6 @@ func httpget(url string) ([]byte, error) {
}
defer response.Body.Close()

body, _ := ioutil.ReadAll(response.Body)
body, _ := io.ReadAll(response.Body)
return body, nil
}
8 changes: 4 additions & 4 deletions feeds/podcastindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"strconv"
Expand Down Expand Up @@ -122,7 +122,7 @@ func PodcastFeed(url string, fulltext bool) (*Podcast, error) {
defer resp.Body.Close()

var r PodcastResponse
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
err = json.Unmarshal(body, &r)
if err != nil {
fmt.Println("=> json unmarshall error", err)
Expand Down Expand Up @@ -158,7 +158,7 @@ func PodcastEpisodes(url string, fulltext bool) ([]Episode, error) {
defer resp.Body.Close()

var r EpisodeResponse
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
err = json.Unmarshal(body, &r)
if err != nil {
fmt.Println("json unmarshall error", err)
Expand Down Expand Up @@ -234,7 +234,7 @@ func PodcastEpisodesByPerson(query string, fulltext bool) ([]Episode, error) {
defer resp.Body.Close()

var r EpisodeResponse
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
err = json.Unmarshal(body, &r)
if err != nil {
fmt.Println("json unmarshall error", err)
Expand Down
4 changes: 2 additions & 2 deletions handlers/bots.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package handlers
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"regexp"
"strconv"
Expand All @@ -20,7 +20,7 @@ func CreateOrEditBot(w http.ResponseWriter, r *http.Request) {
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)

bot := db.Bot{}
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
r.Body.Close()
err = json.Unmarshal(body, &bot)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions handlers/bounties.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package handlers
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"reflect"
Expand Down Expand Up @@ -46,7 +46,7 @@ func GetBountiesLeaderboard(w http.ResponseWriter, _ *http.Request) {

func DeleteBountyAssignee(w http.ResponseWriter, r *http.Request) {
invoice := db.DeleteBountyAssignee{}
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
var deletedAssignee bool

r.Body.Close()
Expand Down
12 changes: 6 additions & 6 deletions handlers/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,25 @@ func GetBountyCount(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(bountyCount)
}

func GetPersonCreatedBounties(w http.ResponseWriter, r *http.Request) {
bounties, err := db.DB.GetCreatedBounties(r)
func (h *bountyHandler) GetPersonCreatedBounties(w http.ResponseWriter, r *http.Request) {
bounties, err := h.db.GetCreatedBounties(r)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Println("Error", err)
} else {
var bountyResponse []db.BountyResponse = GenerateBountyResponse(bounties)
var bountyResponse []db.BountyResponse = h.generateBountyResponse(bounties)
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bountyResponse)
}
}

func GetPersonAssignedBounties(w http.ResponseWriter, r *http.Request) {
bounties, err := db.DB.GetAssignedBounties(r)
func (h *bountyHandler) GetPersonAssignedBounties(w http.ResponseWriter, r *http.Request) {
bounties, err := h.db.GetAssignedBounties(r)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Println("Error", err)
} else {
var bountyResponse []db.BountyResponse = GenerateBountyResponse(bounties)
var bountyResponse []db.BountyResponse = h.generateBountyResponse(bounties)
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bountyResponse)
}
Expand Down
Loading