Skip to content

Commit

Permalink
re: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elraphty committed Dec 11, 2024
1 parent 6ea6642 commit e774da9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 27 deletions.
6 changes: 4 additions & 2 deletions db/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,15 +460,17 @@ func (db database) UserHasManageBountyRoles(pubKeyFromAuth string, uuid string)

func (db database) ProcessUpdateTicketsWithoutGroup() {
// get all tickets without group
tickets, err := DB.GetTicketsWithoutGroup()
tickets, err := db.GetTicketsWithoutGroup()

if err != nil {
log.Printf("Error getting tickets without group: %v", err)
return
}

// update each ticket with group uuid
for _, ticket := range tickets {
err := DB.UpdateTicketsWithoutGroup(ticket)
fmt.Println("ticket from process", ticket)
err := db.UpdateTicketsWithoutGroup(ticket)
if err != nil {
log.Printf("Error updating ticket: %v", err)
}
Expand Down
25 changes: 10 additions & 15 deletions db/config_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package db

import (
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -225,31 +226,25 @@ func TestProcessUpdateTicketsWithoutGroup(t *testing.T) {
// create ticket
TestDB.CreateOrEditTicket(&ticket)

// get tickets without group and assert that there is 1
tickets, err := TestDB.GetTicketsWithoutGroup()
assert.NoError(t, err)
assert.Equal(t, 1, len(tickets))

// process update tickets without group
TestDB.ProcessUpdateTicketsWithoutGroup()

// get tickets without group and assert that there is 0
tickets, err = TestDB.GetTicketsWithoutGroup()
tickets, err := TestDB.GetTicketsWithoutGroup()
assert.NoError(t, err)
assert.Equal(t, 0, len(tickets))

// get ticket and assert that the ticket group is the same as the ticket uuid
ticket, err = TestDB.GetTicket(ticket.UUID.String())
assert.NoError(t, err)
assert.Equal(t, ticket.TicketGroup, ticket.UUID)

// get ticket and assert that the author id is 12345
ticket, err = TestDB.GetTicket(ticket.UUID.String())
assert.NoError(t, err)
assert.Equal(t, ticket.AuthorID, "12345")
fmt.Println("tickets", tickets)

ticketUuid := ticket.UUID
ticketAuthorID := "12345"
ticketAuthor := Author("HUMAN")

// get ticket and assert that the author is HUMAN
ticket, err = TestDB.GetTicket(ticket.UUID.String())
assert.NoError(t, err)
assert.Equal(t, ticket.Author, "HUMAN")
assert.Equal(t, ticket.TicketGroup, &ticketUuid)
assert.Equal(t, ticket.AuthorID, &ticketAuthorID)
assert.Equal(t, ticket.Author, &ticketAuthor)
}
16 changes: 6 additions & 10 deletions db/tickets.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,24 +169,20 @@ func (db database) GetTicketsWithoutGroup() ([]Tickets, error) {
}

func (db database) UpdateTicketsWithoutGroup(ticket Tickets) error {
data := []map[string]interface{}{}
data := map[string]interface{}{}

data = append(data, map[string]interface{}{
"ticket_group": ticket.UUID,
})
data["ticket_group"] = ticket.UUID

if ticket.AuthorID == nil {
data = append(data, map[string]interface{}{
"author_id": "12345",
})
data["author_id"] = "12345"
}

if ticket.Author == nil {
data = append(data, map[string]interface{}{
"author": "HUMAN",
})
data["author"] = "HUMAN"
}

fmt.Println("data ===", data)

result := db.db.Model(&Tickets{}).Where("uuid = ?", ticket.UUID).Updates(data)

if result.Error != nil {
Expand Down

0 comments on commit e774da9

Please sign in to comment.