package console import ( "context" "encoding/json" "net/http" "testing" "github.com/carlosframework/platform/internal/objstore" ) // An app whose storage is entirely per-environment has NO store of its own. // Asked about the app store, the door used to answer 404 "no store is // declared for this app" — hiding every bucket the app actually owns, in the // one shape where the listing matters most. A managed product is always this // shape: every tenant is a bundle, and the app itself never declares a store. // // Found against a live deployment, not here, which is why this test exists. func TestAPIStoreStatusListsEnvironmentsWithNoAppStore(t *testing.T) { ctx := context.Background() fx, token := storeFixture(t, "code-store-env-only") // Only an environment store. The app's own is never declared. if status, body := postRaw(t, storeEnvURL(fx, "titogo", "acme"), map[string]any{}, token); status != http.StatusOK { t.Fatalf("declare in acme = %d %s", status, body) } if rec, _, err := objstore.Get(ctx, fx.rel, fx.sqid, "titogo"); err != nil || rec != nil { t.Fatalf("fixture drift: the app's own store exists (%+v, %v)", rec, err) } status, body := getRaw(t, storeURL(fx, "titogo"), token) if status != http.StatusOK { t.Fatalf("app-store status with only an environment store = %d %s, want 200", status, body) } var reply map[string]any if err := json.Unmarshal([]byte(body), &reply); err != nil { t.Fatalf("decode %q: %v", body, err) } envs, _ := reply["environments"].([]any) if len(envs) != 1 || envs[0] != "acme" { t.Errorf("environments = %v, want [acme]", envs) } // Every block reads as absent, which is true: the APP has no store. for _, key := range []string{"declared", "grant", "provisioned"} { if reply[key] != nil { t.Errorf("%s = %v, want null — the app itself declared nothing", key, reply[key]) } } if reply["environment"] != "" { t.Errorf("environment = %v, want \"\" — this reply is about the app's own store", reply["environment"]) } }