コード例 #1
0
func TestConvertJSONAPIToWorkItemWithDescriptionContentAndMarkup(t *testing.T) {
	appl := new(application.Application)
	attributes := map[string]interface{}{
		workitem.SystemTitle:       "title",
		workitem.SystemDescription: rendering.NewMarkupContent("description", rendering.SystemMarkupMarkdown),
	}
	source := app.WorkItem2{Type: workitem.SystemBug, Attributes: attributes}
	target := &app.WorkItem{Fields: map[string]interface{}{}}
	err := ConvertJSONAPIToWorkItem(*appl, source, target)
	require.Nil(t, err)
	require.NotNil(t, target)
	require.NotNil(t, target.Fields)
	expectedDescription := rendering.NewMarkupContent("description", rendering.SystemMarkupMarkdown)
	assert.Equal(t, expectedDescription, target.Fields[workitem.SystemDescription])
}
コード例 #2
0
func (s *workItemRepoBlackBoxTest) TestCreateWorkItemWithDescriptionMarkup() {
	defer cleaner.DeleteCreatedEntities(s.DB)()
	wi, err := s.repo.Create(
		context.Background(), workitem.SystemBug,
		map[string]interface{}{
			workitem.SystemTitle:       "Title",
			workitem.SystemDescription: rendering.NewMarkupContent("Description", rendering.SystemMarkupMarkdown),
			workitem.SystemState:       workitem.SystemStateNew,
		}, "xx")
	require.Nil(s.T(), err, "Could not create workitem")
	wi, err = s.repo.Load(context.Background(), wi.ID)
	require.Nil(s.T(), err)
	// app.WorkItem does not contain the markup associated with the description (yet)
	assert.Equal(s.T(), rendering.NewMarkupContent("Description", rendering.SystemMarkupMarkdown), wi.Fields[workitem.SystemDescription])
}
コード例 #3
0
// Convert returns the given `value` if the `item` is not nil`, otherwise returns `nil`
func (converter MarkupConverter) Convert(value interface{}, item AttributeAccessor) (interface{}, error) {
	// return a 'nil' result if the supplied 'value' was nil
	if value == nil {
		return nil, nil
	}
	switch value.(type) {
	case string:
		return rendering.NewMarkupContent(value.(string), converter.markup), nil
	default:
		return nil, errors.Errorf("Unexpected type of value to convert: %T", value)
	}
}
コード例 #4
0
func TestSimpleTypeConversion(t *testing.T) {
	t.Parallel()
	resource.Require(t, resource.UnitTest)
	markupContent1 := make(map[string]interface{})
	markupContent1["content"] = "## description"
	markupContent1["markup"] = rendering.SystemMarkupDefault
	markupContent2 := make(map[string]interface{})
	markupContent2["content"] = "## description"
	markupContent2["markup"] = rendering.SystemMarkupMarkdown

	test_data := []input{
		{stString, "hello world", "hello world", false},
		{stString, "", "", false},
		{stString, 100, nil, true},
		{stString, 1.90, nil, true},

		{stIteration, "3434", "3434", false},
		{stIteration, "", "", false},
		{stIteration, 1, nil, true},
		{stIteration, 1.9, nil, true},
		{stIteration, true, nil, true},

		{stArea, "1233-2333", "1233-2333", false},
		{stArea, "", "", false},
		{stArea, 1, nil, true},
		{stArea, 1.9, nil, true},
		{stArea, true, nil, true},

		{stInt, 100.0, nil, true},
		{stInt, 100, 100, false},
		{stInt, "100", nil, true},
		{stInt, true, nil, true},

		{stFloat, 1.1, 1.1, false},
		{stFloat, 1, nil, true},
		{stFloat, "a", nil, true},

		{stDuration, 0, 0, false},
		{stDuration, 1.1, nil, true},
		{stDuration, "duration", nil, true},

		{stURL, "http://www.google.com", "http://www.google.com", false},
		{stURL, "", nil, true},
		{stURL, "google", nil, true},
		{stURL, "http://google.com", "http://google.com", false},

		{stList, [4]int{1, 2, 3, 4}, [4]int{1, 2, 3, 4}, false},
		{stList, [2]string{"1", "2"}, [2]string{"1", "2"}, false},
		{stList, "", nil, true},
		// {stList, []int{}, []int{}, false}, need to find out the way for empty array.
		// because slices do not have equality operator.

		{stMarkup, rendering.NewMarkupContent("## description", rendering.SystemMarkupDefault), markupContent1, false},
		{stMarkup, rendering.NewMarkupContent("## description", rendering.SystemMarkupMarkdown), markupContent2, false},
		{stMarkup, nil, nil, false},
		{stMarkup, 1, nil, true},
	}
	for _, inp := range test_data {
		retVal, err := inp.t.ConvertToModel(inp.value)
		matchContent := reflect.DeepEqual(retVal, inp.expectedValue)
		matchError := (err != nil) == inp.errorExpected
		if matchContent && matchError {
			t.Log("test pass for input: ", inp)
		} else if !matchContent {
			t.Error("Expected ", inp.expectedValue, "but got", retVal)
			t.Fail()
		} else {
			t.Error("Expected error to be ", inp.errorExpected, "but got", (err != nil))
			t.Fail()
		}
	}
}