github.com/blend/go-sdk@v1.20220411.3/email/message_option_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package email
     9  
    10  import (
    11  	"testing"
    12  
    13  	"github.com/blend/go-sdk/assert"
    14  )
    15  
    16  func TestMessageOption(t *testing.T) {
    17  	assert := assert.New(t)
    18  
    19  	m := Message{}
    20  
    21  	assert.Empty(m.From)
    22  	OptFrom("foo@bar.com")(&m)
    23  	assert.Equal("foo@bar.com", m.From)
    24  
    25  	assert.Empty(m.To)
    26  	OptTo("buzz@bar.com", "fuzz@bar.com")(&m)
    27  	assert.Equal([]string{"buzz@bar.com", "fuzz@bar.com"}, m.To)
    28  
    29  	assert.Empty(m.CC)
    30  	OptCC("cc0@bar.com", "cc1@bar.com")(&m)
    31  	assert.Equal([]string{"cc0@bar.com", "cc1@bar.com"}, m.CC)
    32  
    33  	assert.Empty(m.BCC)
    34  	OptBCC("bcc0@bar.com", "bcc1@bar.com")(&m)
    35  	assert.Equal([]string{"bcc0@bar.com", "bcc1@bar.com"}, m.BCC)
    36  
    37  	assert.Empty(m.Subject)
    38  	OptSubject("subject0")(&m)
    39  	assert.Equal("subject0", m.Subject)
    40  
    41  	assert.Empty(m.TextBody)
    42  	OptTextBody("text body etc.")(&m)
    43  	assert.Equal("text body etc.", m.TextBody)
    44  
    45  	assert.Empty(m.HTMLBody)
    46  	OptHTMLBody("html body etc.")(&m)
    47  	assert.Equal("html body etc.", m.HTMLBody)
    48  
    49  	assert.Equal("foo@bar.com", m.From)
    50  	assert.Equal([]string{"buzz@bar.com", "fuzz@bar.com"}, m.To)
    51  	assert.Equal([]string{"cc0@bar.com", "cc1@bar.com"}, m.CC)
    52  	assert.Equal([]string{"bcc0@bar.com", "bcc1@bar.com"}, m.BCC)
    53  	assert.Equal("text body etc.", m.TextBody)
    54  	assert.Equal("html body etc.", m.HTMLBody)
    55  }
    56  
    57  func TestApplyMessageOptions(t *testing.T) {
    58  	assert := assert.New(t)
    59  
    60  	m := ApplyMessageOptions(Message{}, OptFrom("foo@bar.com"),
    61  		OptTo("buzz@bar.com", "fuzz@bar.com"),
    62  		OptCC("cc0@bar.com", "cc1@bar.com"),
    63  		OptBCC("bcc0@bar.com", "bcc1@bar.com"),
    64  		OptTextBody("text body etc."),
    65  		OptHTMLBody("html body etc."))
    66  
    67  	assert.Equal("foo@bar.com", m.From)
    68  	assert.Equal([]string{"buzz@bar.com", "fuzz@bar.com"}, m.To)
    69  	assert.Equal([]string{"cc0@bar.com", "cc1@bar.com"}, m.CC)
    70  	assert.Equal([]string{"bcc0@bar.com", "bcc1@bar.com"}, m.BCC)
    71  	assert.Equal("text body etc.", m.TextBody)
    72  	assert.Equal("html body etc.", m.HTMLBody)
    73  }