package bootstrapimpl

import "testing"

// TestSystemTableFlowInterviewHasKeyPrefix guards against a regression where
// FlowInterview lacks a keyPrefix declaration in system_tables.json. Without
// this prefix the record-trigger listener errors with "no metadata key prefix
// for object FlowInterview" on any standard action that creates a FlowInterview
// row (e.g. convertLead), blocking the entire path on a fresh DB install
// (issue #464).
//
// The expected value "0Fo" is the Salesforce-standard keyPrefix for
// FlowInterview as returned by Schema.DescribeSObjectResult.getKeyPrefix().
// A local mnemonic would silently break ID resolution for any Salesforce-style
// FlowInterview ID supplied by external callers.
const wantFlowInterviewKeyPrefix = "0Fo"

func TestSystemTableFlowInterviewHasKeyPrefix(t *testing.T) {
	defs := GetSystemTableDefinitions()
	for _, def := range defs {
		if def.TableName == "FlowInterview" {
			if def.KeyPrefix != wantFlowInterviewKeyPrefix {
				t.Fatalf("FlowInterview keyPrefix = %q, want %q (Salesforce-standard; see issue #464)", def.KeyPrefix, wantFlowInterviewKeyPrefix)
			}
			return
		}
	}
	t.Fatal("FlowInterview not found in system_tables.json")
}
