package models import ( "fmt" "github.com/dmarushkin/go-qrcode/v2" check "gopkg.in/check.v1" ) type mockTemplateContext struct { URL string FromAddress string } func (m mockTemplateContext) getFromAddress() string { return m.FromAddress } func (m mockTemplateContext) getBaseURL() string { return m.URL } func (s *ModelsSuite) TestNewTemplateContext(c *check.C) { r := Result{ BaseRecipient: BaseRecipient{ FirstName: "Foo", LastName: "Bar", Email: "foo@bar.com", }, RId: "1234567", } ctx := mockTemplateContext{ URL: "http://example.com", FromAddress: "From Address ", } qrc, _ := qrcode.New(fmt.Sprintf("%s?rid=%s", ctx.URL, r.RId)) url_qr := qrc.GetHtmlStr() expected := PhishingTemplateContext{ URL: fmt.Sprintf("%s?rid=%s", ctx.URL, r.RId), URL_QR: url_qr, BaseURL: ctx.URL, BaseRecipient: r.BaseRecipient, TrackingURL: fmt.Sprintf("%s/track?rid=%s", ctx.URL, r.RId), From: "From Address", RId: r.RId, } expected.Tracker = "" got, err := NewPhishingTemplateContext(ctx, r.BaseRecipient, r.RId) c.Assert(err, check.Equals, nil) c.Assert(got, check.DeepEquals, expected) }