| 1 | package console |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "encoding/json" |
| 6 | "net/http" |
| 7 | "testing" |
| 8 | |
| 9 | "github.com/carlosframework/platform/internal/objstore" |
| 10 | ) |
| 11 | |
| 12 | // An app whose storage is entirely per-environment has NO store of its own. |
| 13 | // Asked about the app store, the door used to answer 404 "no store is |
| 14 | // declared for this app" — hiding every bucket the app actually owns, in the |
| 15 | // one shape where the listing matters most. A managed product is always this |
| 16 | // shape: every tenant is a bundle, and the app itself never declares a store. |
| 17 | // |
| 18 | // Found against a live deployment, not here, which is why this test exists. |
| 19 | func TestAPIStoreStatusListsEnvironmentsWithNoAppStore(t *testing.T) { |
| 20 | ctx := context.Background() |
| 21 | fx, token := storeFixture(t, "code-store-env-only") |
| 22 | |
| 23 | // Only an environment store. The app's own is never declared. |
| 24 | if status, body := postRaw(t, storeEnvURL(fx, "titogo", "acme"), map[string]any{}, token); status != http.StatusOK { |
| 25 | t.Fatalf("declare in acme = %d %s", status, body) |
| 26 | } |
| 27 | if rec, _, err := objstore.Get(ctx, fx.rel, fx.sqid, "titogo"); err != nil || rec != nil { |
| 28 | t.Fatalf("fixture drift: the app's own store exists (%+v, %v)", rec, err) |
| 29 | } |
| 30 | |
| 31 | status, body := getRaw(t, storeURL(fx, "titogo"), token) |
| 32 | if status != http.StatusOK { |
| 33 | t.Fatalf("app-store status with only an environment store = %d %s, want 200", status, body) |
| 34 | } |
| 35 | var reply map[string]any |
| 36 | if err := json.Unmarshal([]byte(body), &reply); err != nil { |
| 37 | t.Fatalf("decode %q: %v", body, err) |
| 38 | } |
| 39 | envs, _ := reply["environments"].([]any) |
| 40 | if len(envs) != 1 || envs[0] != "acme" { |
| 41 | t.Errorf("environments = %v, want [acme]", envs) |
| 42 | } |
| 43 | // Every block reads as absent, which is true: the APP has no store. |
| 44 | for _, key := range []string{"declared", "grant", "provisioned"} { |
| 45 | if reply[key] != nil { |
| 46 | t.Errorf("%s = %v, want null — the app itself declared nothing", key, reply[key]) |
| 47 | } |
| 48 | } |
| 49 | if reply["environment"] != "" { |
| 50 | t.Errorf("environment = %v, want \"\" — this reply is about the app's own store", reply["environment"]) |
| 51 | } |
| 52 | } |
| 53 | |