package store

import (
	"encoding/json"
	"reflect"
	"strings"
	"testing"
)

func TestDefaultFileStorageScenesIncludeCrossNodeRequestAssets(t *testing.T) {
	want := []string{
		FileStorageSceneUpload,
		FileStorageSceneImageResult,
		FileStorageSceneRequestAsset,
	}
	if got := defaultFileStorageScenes(); !reflect.DeepEqual(got, want) {
		t.Fatalf("default file storage scenes = %#v, want %#v", got, want)
	}
}

func TestFileStorageChannelJSONNeverIncludesCredentials(t *testing.T) {
	channel := FileStorageChannel{
		Provider: "s3", APIKey: "api-key-secret", AccessKeyID: "access-key-id",
		AccessKeySecret: "access-key-secret", SessionToken: "session-token",
		CredentialsPreview: map[string]any{"accessKeyId": "acce…-id", "accessKeySecret": "acce…cret"},
	}
	payload, err := json.Marshal(channel)
	if err != nil {
		t.Fatal(err)
	}
	encoded := string(payload)
	for _, secret := range []string{"api-key-secret", "access-key-id", "access-key-secret", "session-token"} {
		if strings.Contains(encoded, secret) {
			t.Fatalf("channel JSON leaked credential %q: %s", secret, encoded)
		}
	}
	if !strings.Contains(encoded, "credentialsPreview") {
		t.Fatalf("channel JSON omitted masked preview: %s", encoded)
	}
}

func TestLegacyUploadNoneNormalizesToObjectStorageDefault(t *testing.T) {
	for _, value := range []string{"upload_none", "none", "never", "skip_all"} {
		if got := NormalizeFileStorageResultUploadPolicy(value); got != FileStorageResultUploadPolicyDefault {
			t.Fatalf("policy %q normalized to %q", value, got)
		}
	}
}
