• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Freegle / iznik-server-go / f7a12ccd-31a0-4a5f-bd00-987b7256b963

09 Feb 2026 09:29PM UTC coverage: 79.527%. First build
f7a12ccd-31a0-4a5f-bd00-987b7256b963

Pull #17

circleci

edwh
fix: Add email_queue table creation to test setup

The emailqueue tests need the email_queue table to exist in the test
database. This was missing when all feature branches were merged
together, causing TestQueueEmail_Basic to fail with table not found.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Pull Request #17: feat: Add invitation endpoint (GET, PUT, PATCH)

2479 of 2939 new or added lines in 25 files covered. (84.35%)

9886 of 12431 relevant lines covered (79.53%)

13.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.62
/emailqueue/emailqueue.go
1
package emailqueue
2

3
import (
4
        "encoding/json"
5
        "github.com/freegle/iznik-server-go/database"
6
        "time"
7
)
8

9
// EmailType constants for the email_queue table.
10
const (
11
        TypeForgotPassword = "forgot_password"
12
        TypeVerifyEmail    = "verify_email"
13
        TypeWelcome        = "welcome"
14
        TypeUnsubscribe    = "unsubscribe"
15
        TypeMergeOffer     = "merge_offer"
16
        TypeModMail        = "modmail"
17
)
18

19
// EmailQueueItem represents a row in the email_queue table.
20
type EmailQueueItem struct {
21
        ID           uint64     `json:"id" gorm:"primaryKey;column:id"`
22
        EmailType    string     `json:"email_type" gorm:"column:email_type"`
23
        UserID       *uint64    `json:"user_id" gorm:"column:user_id"`
24
        GroupID      *uint64    `json:"group_id" gorm:"column:group_id"`
25
        MessageID    *uint64    `json:"message_id" gorm:"column:message_id"`
26
        ChatID       *uint64    `json:"chat_id" gorm:"column:chat_id"`
27
        ExtraData    *string    `json:"extra_data" gorm:"column:extra_data;type:json"`
28
        CreatedAt    time.Time  `json:"created_at" gorm:"column:created_at"`
29
        ProcessedAt  *time.Time `json:"processed_at" gorm:"column:processed_at"`
30
        FailedAt     *time.Time `json:"failed_at" gorm:"column:failed_at"`
31
        ErrorMessage *string    `json:"error_message" gorm:"column:error_message"`
32
}
33

34
func (EmailQueueItem) TableName() string {
1✔
35
        return "email_queue"
1✔
36
}
1✔
37

38
// marshalExtraData converts a map to a JSON string pointer, or nil if the map is nil.
39
func marshalExtraData(extraData map[string]interface{}) (*string, error) {
10✔
40
        if extraData == nil {
11✔
41
                return nil, nil
1✔
42
        }
1✔
43
        jsonBytes, err := json.Marshal(extraData)
9✔
44
        if err != nil {
9✔
NEW
45
                return nil, err
×
NEW
46
        }
×
47
        jsonStr := string(jsonBytes)
9✔
48
        return &jsonStr, nil
9✔
49
}
50

51
// QueueEmail inserts an email request into the queue for Laravel to process.
52
func QueueEmail(emailType string, userID *uint64, groupID *uint64, extraData map[string]interface{}) error {
8✔
53
        extra, err := marshalExtraData(extraData)
8✔
54
        if err != nil {
8✔
NEW
55
                return err
×
NEW
56
        }
×
57

58
        item := EmailQueueItem{
8✔
59
                EmailType: emailType,
8✔
60
                UserID:    userID,
8✔
61
                GroupID:   groupID,
8✔
62
                ExtraData: extra,
8✔
63
        }
8✔
64

8✔
65
        return database.DBConn.Create(&item).Error
8✔
66
}
67

68
// QueueEmailWithMessage inserts an email request with a message ID.
69
func QueueEmailWithMessage(emailType string, userID *uint64, messageID *uint64, extraData map[string]interface{}) error {
1✔
70
        extra, err := marshalExtraData(extraData)
1✔
71
        if err != nil {
1✔
NEW
72
                return err
×
NEW
73
        }
×
74

75
        item := EmailQueueItem{
1✔
76
                EmailType: emailType,
1✔
77
                UserID:    userID,
1✔
78
                MessageID: messageID,
1✔
79
                ExtraData: extra,
1✔
80
        }
1✔
81

1✔
82
        return database.DBConn.Create(&item).Error
1✔
83
}
84

85
// QueueEmailWithChat inserts an email request with a chat ID.
86
func QueueEmailWithChat(emailType string, userID *uint64, chatID *uint64, extraData map[string]interface{}) error {
1✔
87
        extra, err := marshalExtraData(extraData)
1✔
88
        if err != nil {
1✔
NEW
89
                return err
×
NEW
90
        }
×
91

92
        item := EmailQueueItem{
1✔
93
                EmailType: emailType,
1✔
94
                UserID:    userID,
1✔
95
                ChatID:    chatID,
1✔
96
                ExtraData: extra,
1✔
97
        }
1✔
98

1✔
99
        return database.DBConn.Create(&item).Error
1✔
100
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc