package store_test

import (
	"testing"

	"bit.admedia.com/scm/ad/adpilot-indexing-commit-intel.com/internal/store"
)

func TestParseMongoURI(t *testing.T) {
	tests := []struct {
		name       string
		uri        string
		collection string
		id         string
		wantErr    bool
	}{
		{
			name:       "graph delta",
			uri:        "mongo://graph_deltas/delta_target456_a1b2",
			collection: "graph_deltas",
			id:         "delta_target456_a1b2",
		},
		{
			name:    "unsupported scheme",
			uri:     "file:///tmp/delta.json",
			wantErr: true,
		},
		{
			name:    "missing id",
			uri:     "mongo://graph_deltas/",
			wantErr: true,
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			collection, id, err := store.ParseMongoURI(tt.uri)
			if tt.wantErr {
				if err == nil {
					t.Fatal("expected error")
				}
				return
			}
			if err != nil {
				t.Fatalf("unexpected error: %v", err)
			}
			if collection != tt.collection || id != tt.id {
				t.Fatalf("got collection=%q id=%q", collection, id)
			}
		})
	}
}
