package parse

import (
	"testing"
)

func TestParseOrgIDFromPath(t *testing.T) {
	caseList := []struct {
		URL   string
		OrgID uint64
		Found bool
	}{
		{"/orgs/1234567", 1234567, true},
		{"/api/v1/orgs/1234567", 1234567, true},
		{"/api/v1/orgs/1234567/projects/2345678", 1234567, true},
		{"/api/v1/projecs/1234567", 0, false},
	}

	for _, c := range caseList {
		got, found := ParseOrgIDFromPath(c.URL)
		if got != c.OrgID || found != c.Found {
			t.Errorf("ParseOrgIDFromPath(%s) = %v, %v, want %v, %v", c.URL, got, found, c.OrgID, c.Found)
		}
	}
}

func TestParseProjectIDFromPath(t *testing.T) {
	caseList := []struct {
		URL   string
		OrgID uint64
		Found bool
	}{
		{"/orgs/1234567", 0, false},
		{"/api/v1/orgs/1234567", 0, false},
		{"/api/v1/orgs/1234567/projects/2345678", 2345678, true},
		{"/api/v1/projecs/1234567", 0, false},
		{"/api/v1/projects/1234567", 1234567, true},
	}

	for _, c := range caseList {
		got, found := ParseProjectIDFromPath(c.URL)
		if got != c.OrgID || found != c.Found {
			t.Errorf("ParseProjectIDFromPath(%s) = %v, %v, want %v, %v", c.URL, got, found, c.OrgID, c.Found)
		}
	}
}
