package ical

import (
	"htwkalender/ical/model"
	"testing"
)

func Test_replaceNameIfUserDefined(t *testing.T) {
	type args struct {
		event   *model.Event
		mapping model.FeedCollection
	}
	tests := []struct {
		name string
		args args
		want string
	}{
		{
			name: "Custom Name Test",
			args: args{
				event: &model.Event{
					Name: "Test",
				},
				mapping: model.FeedCollection{
					Name:            "Test",
					UserDefinedName: "CustomTest",
				},
			},
			want: "CustomTest",
		},
		{
			name: "Empty Custom Name Test",
			args: args{
				event: &model.Event{
					Name: "Test",
				},
				mapping: model.FeedCollection{
					Name:            "Test",
					UserDefinedName: "",
				},
			},
			want: "Test",
		},
		{
			name: "Empty Name Test",
			args: args{
				event: &model.Event{
					Name: "",
				},
				mapping: model.FeedCollection{
					Name:            "",
					UserDefinedName: "CustomTest",
				},
			},
			want: "CustomTest",
		},
		{
			name: "Names dont match but check is done before",
			args: args{
				event: &model.Event{
					Name: "Test",
				},
				mapping: model.FeedCollection{
					Name:            "Test2",
					UserDefinedName: "CustomTest",
				},
			},
			want: "CustomTest",
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := replaceNameIfUserDefined(tt.args.event, tt.args.mapping); got != tt.want {
				t.Errorf("replaceNameIfUserDefined() = %v, want %v", got, tt.want)
			}
		})
	}
}
