package main

import (
	"testing"

	"src.opensuse.org/autogits/common/gitea-generated/models"
)

func TestPRtoObsProjectMapping(t *testing.T) {
	pr := models.PullRequest{
		Base: &models.PRBranchInfo {
			Repo: &models.Repository {
				Name: "Repo",
				Owner: &models.User {
					UserName: "foobar",
				},
			},
		},
		Index: 10,
	}
    p := getObsProjectAssociatedWithPr("home:foo", &pr) 
	if p != "home:foo:foobar:Repo:PR:10" {
		t.Errorf("invalid project: %s", p)
	}

	pr.Base.Repo.Name = "_FooBar"
    p = getObsProjectAssociatedWithPr("home:foo", &pr) 
	if p != "home:foo:foobar:XFooBar:PR:10" {
		t.Errorf("invalid project: %s", p)
	}

	pr.Base.Repo.Owner.UserName = "_some_thing"
    p = getObsProjectAssociatedWithPr("home:foo", &pr) 
	if p != "home:foo:Xsome_thing:XFooBar:PR:10" {
		t.Errorf("invalid project: %s", p)
	}
}