package web

import (
	"os"
	"path/filepath"
	"runtime"
	"strings"
	"testing"
)

func TestSocialIdentityMigrationDefinesNullablePasswordAndProviderIdentity(t *testing.T) {
	_, filename, _, ok := runtime.Caller(0)
	if !ok {
		t.Fatal("runtime.Caller failed")
	}
	path := filepath.Join(filepath.Dir(filename), "..", "..", "migrations", "0006_social_identities.sql")
	body, err := os.ReadFile(path)
	if err != nil {
		t.Fatalf("read migration: %v", err)
	}

	text := string(body)
	required := []string{
		"ALTER TABLE users ALTER COLUMN password_hash DROP NOT NULL",
		"CREATE TABLE user_identities",
		"provider IN ('google', 'apple')",
		"UNIQUE (provider, provider_subject)",
	}
	for _, needle := range required {
		if !strings.Contains(text, needle) {
			t.Fatalf("migration missing %q", needle)
		}
	}
}
