From fdb5665c59456161463811a3a1d0568f307ad1cf Mon Sep 17 00:00:00 2001 From: Sam Starling <42478+samstarling@users.noreply.github.com> Date: Sat, 7 Dec 2024 18:44:36 +0000 Subject: [PATCH] Update unit tests to assert on ID() --- block_action_test.go | 6 +++--- block_call_test.go | 4 ++++ block_context_test.go | 7 +++---- block_divider_test.go | 6 ++++-- block_element_test.go | 14 -------------- block_file_test.go | 3 +++ block_header_test.go | 5 +++-- block_image_test.go | 4 ++-- block_input_test.go | 3 +++ block_object_test.go | 12 ------------ block_rich_text_test.go | 10 ++++++++++ block_section_test.go | 6 +++--- block_video_test.go | 4 ++-- 13 files changed, 40 insertions(+), 44 deletions(-) diff --git a/block_action_test.go b/block_action_test.go index 32bd0c2c8..bb22f45e0 100644 --- a/block_action_test.go +++ b/block_action_test.go @@ -7,13 +7,13 @@ import ( ) func TestNewActionBlock(t *testing.T) { - approveBtnTxt := NewTextBlockObject("plain_text", "Approve", false, false) approveBtn := NewButtonBlockElement("", "click_me_123", approveBtnTxt) - actionBlock := NewActionBlock("test", approveBtn) + + assert.Equal(t, actionBlock.BlockType(), MBTAction) assert.Equal(t, string(actionBlock.Type), "actions") assert.Equal(t, actionBlock.BlockID, "test") + assert.Equal(t, actionBlock.ID(), "test") assert.Equal(t, len(actionBlock.Elements.ElementSet), 1) - } diff --git a/block_call_test.go b/block_call_test.go index c118542a5..4966e3dc1 100644 --- a/block_call_test.go +++ b/block_call_test.go @@ -8,6 +8,10 @@ import ( func TestNewCallBlock(t *testing.T) { callBlock := NewCallBlock("ACallID") + + assert.Equal(t, callBlock.BlockType(), MBTCall) assert.Equal(t, string(callBlock.Type), "call") assert.Equal(t, callBlock.CallID, "ACallID") + assert.Equal(t, callBlock.BlockID, "") + assert.Equal(t, callBlock.ID(), "") } diff --git a/block_context_test.go b/block_context_test.go index 20fb39631..0ecfb8089 100644 --- a/block_context_test.go +++ b/block_context_test.go @@ -7,15 +7,14 @@ import ( ) func TestNewContextBlock(t *testing.T) { - locationPinImage := NewImageBlockElement("https://api.slack.com/img/blocks/bkb_template_images/tripAgentLocationMarker.png", "Location Pin Icon") textExample := NewTextBlockObject("plain_text", "Location: Central Business District", true, false) - elements := []MixedElement{locationPinImage, textExample} - contextBlock := NewContextBlock("test", elements...) + + assert.Equal(t, contextBlock.BlockType(), MBTContext) assert.Equal(t, string(contextBlock.Type), "context") assert.Equal(t, contextBlock.BlockID, "test") + assert.Equal(t, contextBlock.ID(), "test") assert.Equal(t, len(contextBlock.ContextElements.Elements), 2) - } diff --git a/block_divider_test.go b/block_divider_test.go index 35e3d48d5..27b81aad6 100644 --- a/block_divider_test.go +++ b/block_divider_test.go @@ -7,8 +7,10 @@ import ( ) func TestNewDividerBlock(t *testing.T) { - dividerBlock := NewDividerBlock() - assert.Equal(t, string(dividerBlock.Type), "divider") + assert.Equal(t, dividerBlock.BlockType(), MBTDivider) + assert.Equal(t, string(dividerBlock.Type), "divider") + assert.Equal(t, dividerBlock.BlockID, "") + assert.Equal(t, dividerBlock.ID(), "") } diff --git a/block_element_test.go b/block_element_test.go index d532fb7ef..fead400c7 100644 --- a/block_element_test.go +++ b/block_element_test.go @@ -7,17 +7,14 @@ import ( ) func TestNewImageBlockElement(t *testing.T) { - imageElement := NewImageBlockElement("https://api.slack.com/img/blocks/bkb_template_images/tripAgentLocationMarker.png", "Location Pin Icon") assert.Equal(t, string(imageElement.Type), "image") assert.Contains(t, imageElement.ImageURL, "tripAgentLocationMarker") assert.Equal(t, imageElement.AltText, "Location Pin Icon") - } func TestNewButtonBlockElement(t *testing.T) { - btnTxt := NewTextBlockObject("plain_text", "Next 2 Results", false, false) btnElement := NewButtonBlockElement("test", "click_me_123", btnTxt) @@ -25,11 +22,9 @@ func TestNewButtonBlockElement(t *testing.T) { assert.Equal(t, btnElement.ActionID, "test") assert.Equal(t, btnElement.Value, "click_me_123") assert.Equal(t, btnElement.Text.Text, "Next 2 Results") - } func TestWithStyleForButtonElement(t *testing.T) { - // these values are irrelevant in this test btnTxt := NewTextBlockObject("plain_text", "Next 2 Results", false, false) btnElement := NewButtonBlockElement("test", "click_me_123", btnTxt) @@ -40,21 +35,17 @@ func TestWithStyleForButtonElement(t *testing.T) { assert.Equal(t, btnElement.Style, Style("primary")) btnElement.WithStyle(StyleDanger) assert.Equal(t, btnElement.Style, Style("danger")) - } func TestWithURLForButtonElement(t *testing.T) { - btnTxt := NewTextBlockObject("plain_text", "Next 2 Results", false, false) btnElement := NewButtonBlockElement("test", "click_me_123", btnTxt) btnElement.WithURL("https://foo.bar") assert.Equal(t, btnElement.URL, "https://foo.bar") - } func TestNewOptionsSelectBlockElement(t *testing.T) { - testOptionText := NewTextBlockObject("plain_text", "Option One", false, false) testOption := NewOptionBlockObject("test", testOptionText, nil) @@ -62,11 +53,9 @@ func TestNewOptionsSelectBlockElement(t *testing.T) { assert.Equal(t, option.Type, "static_select") assert.Equal(t, len(option.Options), 1) assert.Nil(t, option.OptionGroups) - } func TestNewOptionsGroupSelectBlockElement(t *testing.T) { - testOptionText := NewTextBlockObject("plain_text", "Option One", false, false) testOption := NewOptionBlockObject("test", testOptionText, nil) testLabel := NewTextBlockObject("plain_text", "Test Label", false, false) @@ -77,11 +66,9 @@ func TestNewOptionsGroupSelectBlockElement(t *testing.T) { assert.Equal(t, optGroup.Type, "static_select") assert.Equal(t, optGroup.ActionID, "test") assert.Equal(t, len(optGroup.OptionGroups), 1) - } func TestNewOptionsMultiSelectBlockElement(t *testing.T) { - testOptionText := NewTextBlockObject("plain_text", "Option One", false, false) testDescriptionText := NewTextBlockObject("plain_text", "Description One", false, false) testOption := NewOptionBlockObject("test", testOptionText, testDescriptionText) @@ -90,7 +77,6 @@ func TestNewOptionsMultiSelectBlockElement(t *testing.T) { assert.Equal(t, option.Type, "static_select") assert.Equal(t, len(option.Options), 1) assert.Nil(t, option.OptionGroups) - } func TestNewOptionsGroupMultiSelectBlockElement(t *testing.T) { diff --git a/block_file_test.go b/block_file_test.go index c51a93ebe..f52270acb 100644 --- a/block_file_test.go +++ b/block_file_test.go @@ -8,8 +8,11 @@ import ( func TestNewFileBlock(t *testing.T) { fileBlock := NewFileBlock("test", "external_id", "source") + + assert.Equal(t, fileBlock.BlockType(), MBTFile) assert.Equal(t, string(fileBlock.Type), "file") assert.Equal(t, fileBlock.BlockID, "test") + assert.Equal(t, fileBlock.ID(), "test") assert.Equal(t, fileBlock.ExternalID, "external_id") assert.Equal(t, fileBlock.Source, "source") } diff --git a/block_header_test.go b/block_header_test.go index d8ed332cf..6e6df8adf 100644 --- a/block_header_test.go +++ b/block_header_test.go @@ -7,11 +7,12 @@ import ( ) func TestNewHeaderBlock(t *testing.T) { - textInfo := NewTextBlockObject("plain_text", "This is quite the header", false, false) - headerBlock := NewHeaderBlock(textInfo, HeaderBlockOptionBlockID("test_block")) + + assert.Equal(t, headerBlock.BlockType(), MBTHeader) assert.Equal(t, string(headerBlock.Type), "header") + assert.Equal(t, headerBlock.ID(), "test_block") assert.Equal(t, headerBlock.BlockID, "test_block") assert.Equal(t, headerBlock.Text.Type, "plain_text") assert.Contains(t, headerBlock.Text.Text, "quite the header") diff --git a/block_image_test.go b/block_image_test.go index 3cdd203c4..801a14217 100644 --- a/block_image_test.go +++ b/block_image_test.go @@ -7,14 +7,14 @@ import ( ) func TestNewImageBlock(t *testing.T) { - imageText := NewTextBlockObject("plain_text", "Location", false, false) imageBlock := NewImageBlock("https://api.slack.com/img/blocks/bkb_template_images/tripAgentLocationMarker.png", "Marker", "test", imageText) + assert.Equal(t, imageBlock.BlockType(), MBTImage) assert.Equal(t, string(imageBlock.Type), "image") assert.Equal(t, imageBlock.Title.Type, "plain_text") + assert.Equal(t, imageBlock.ID(), "test") assert.Equal(t, imageBlock.BlockID, "test") assert.Contains(t, imageBlock.Title.Text, "Location") assert.Contains(t, imageBlock.ImageURL, "tripAgentLocationMarker.png") - } diff --git a/block_input_test.go b/block_input_test.go index 694e57580..fa25f48ee 100644 --- a/block_input_test.go +++ b/block_input_test.go @@ -11,7 +11,10 @@ func TestNewInputBlock(t *testing.T) { element := NewDatePickerBlockElement("action_id") hint := NewTextBlockObject("plain_text", "hint", false, false) inputBlock := NewInputBlock("test", label, hint, element) + + assert.Equal(t, inputBlock.BlockType(), MBTInput) assert.Equal(t, string(inputBlock.Type), "input") + assert.Equal(t, inputBlock.ID(), "test") assert.Equal(t, inputBlock.BlockID, "test") assert.Equal(t, inputBlock.Label, label) assert.Equal(t, inputBlock.Element, element) diff --git a/block_object_test.go b/block_object_test.go index 1f4874a02..b8f55a4c1 100644 --- a/block_object_test.go +++ b/block_object_test.go @@ -9,28 +9,23 @@ import ( ) func TestNewImageBlockObject(t *testing.T) { - imageObject := NewImageBlockElement("https://api.slack.com/img/blocks/bkb_template_images/beagle.png", "Beagle") assert.Equal(t, string(imageObject.Type), "image") assert.Equal(t, imageObject.AltText, "Beagle") assert.Contains(t, imageObject.ImageURL, "beagle.png") - } func TestNewTextBlockObject(t *testing.T) { - textObject := NewTextBlockObject("plain_text", "test", true, false) assert.Equal(t, textObject.Type, "plain_text") assert.Equal(t, textObject.Text, "test") assert.True(t, textObject.Emoji, "Emoji property should be true") assert.False(t, textObject.Verbatim, "Verbatim should be false") - } func TestNewConfirmationBlockObject(t *testing.T) { - titleObj := NewTextBlockObject("plain_text", "testTitle", false, false) textObj := NewTextBlockObject("plain_text", "testText", false, false) confirmObj := NewTextBlockObject("plain_text", "testConfirm", false, false) @@ -41,11 +36,9 @@ func TestNewConfirmationBlockObject(t *testing.T) { assert.Equal(t, confirmation.Text.Text, "testText") assert.Equal(t, confirmation.Confirm.Text, "testConfirm") assert.Nil(t, confirmation.Deny, "Deny should be nil") - } func TestWithStyleForConfirmation(t *testing.T) { - // these values are irrelevant in this test titleObj := NewTextBlockObject("plain_text", "testTitle", false, false) textObj := NewTextBlockObject("plain_text", "testText", false, false) @@ -58,11 +51,9 @@ func TestWithStyleForConfirmation(t *testing.T) { assert.Equal(t, confirmation.Style, Style("primary")) confirmation.WithStyle(StyleDanger) assert.Equal(t, confirmation.Style, Style("danger")) - } func TestNewOptionBlockObject(t *testing.T) { - valTextObj := NewTextBlockObject("plain_text", "testText", false, false) valDescriptionObj := NewTextBlockObject("plain_text", "testDescription", false, false) optObj := NewOptionBlockObject("testOpt", valTextObj, valDescriptionObj) @@ -70,11 +61,9 @@ func TestNewOptionBlockObject(t *testing.T) { assert.Equal(t, optObj.Text.Text, "testText") assert.Equal(t, optObj.Description.Text, "testDescription") assert.Equal(t, optObj.Value, "testOpt") - } func TestNewOptionGroupBlockElement(t *testing.T) { - labelObj := NewTextBlockObject("plain_text", "testLabel", false, false) valTextObj := NewTextBlockObject("plain_text", "testText", false, false) optObj := NewOptionBlockObject("testOpt", valTextObj, nil) @@ -83,7 +72,6 @@ func TestNewOptionGroupBlockElement(t *testing.T) { assert.Equal(t, optGroup.Label.Text, "testLabel") assert.Len(t, optGroup.Options, 1, "Options should contain one element") - } func TestValidateTextBlockObject(t *testing.T) { diff --git a/block_rich_text_test.go b/block_rich_text_test.go index 903f14389..ce8019735 100644 --- a/block_rich_text_test.go +++ b/block_rich_text_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/go-test/deep" + "github.com/stretchr/testify/assert" ) const ( @@ -83,6 +84,15 @@ const ( }` ) +func TestNewRichTextBlock(t *testing.T) { + richTextBlock := NewRichTextBlock("test_block") + + assert.Equal(t, richTextBlock.BlockType(), MBTRichText) + assert.Equal(t, string(richTextBlock.Type), "rich_text") + assert.Equal(t, string(richTextBlock.BlockID), "test_block") + assert.Equal(t, string(richTextBlock.ID()), "test_block") +} + func TestRichTextBlock_UnmarshalJSON(t *testing.T) { cases := []struct { raw []byte diff --git a/block_section_test.go b/block_section_test.go index 68329679b..8f8374e04 100644 --- a/block_section_test.go +++ b/block_section_test.go @@ -7,17 +7,17 @@ import ( ) func TestNewSectionBlock(t *testing.T) { - textInfo := NewTextBlockObject("mrkdwn", "**\n★★★★★\n$340 per night\nRated: 9.1 - Excellent", false, false) - sectionBlock := NewSectionBlock(textInfo, nil, nil, SectionBlockOptionBlockID("test_block")) + + assert.Equal(t, sectionBlock.BlockType(), MBTSection) assert.Equal(t, string(sectionBlock.Type), "section") assert.Equal(t, sectionBlock.BlockID, "test_block") + assert.Equal(t, sectionBlock.ID(), "test_block") assert.Equal(t, len(sectionBlock.Fields), 0) assert.Nil(t, sectionBlock.Accessory) assert.Equal(t, sectionBlock.Text.Type, "mrkdwn") assert.Contains(t, sectionBlock.Text.Text, "New Orleans") - } func TestNewBlockSectionContainsAddedTextBlockAndAccessory(t *testing.T) { diff --git a/block_video_test.go b/block_video_test.go index d4b791fab..1ccece7f7 100644 --- a/block_video_test.go +++ b/block_video_test.go @@ -7,17 +7,17 @@ import ( ) func TestNewVideoBlock(t *testing.T) { - videoTitle := NewTextBlockObject("plain_text", "VideoTitle", false, false) videoBlock := NewVideoBlock( "https://example.com/example.mp4", "https://example.com/thumbnail.png", "alternative text", "blockID", videoTitle) + assert.Equal(t, videoBlock.Type, MBTVideo) assert.Equal(t, string(videoBlock.Type), "video") assert.Equal(t, videoBlock.Title.Type, "plain_text") assert.Equal(t, videoBlock.BlockID, "blockID") + assert.Equal(t, videoBlock.ID(), "blockID") assert.Contains(t, videoBlock.Title.Text, "VideoTitle") assert.Contains(t, videoBlock.VideoURL, "example.mp4") - }