fix shared-db tenant runtime gaps

This commit is contained in:
richjohnrambo
2026-09-22 19:28:33 +08:00
parent 49e43aa3cf
commit 9ddf6ec5ee
12 changed files with 346 additions and 58 deletions
+24
View File
@@ -265,6 +265,7 @@ type testProfilesStore struct {
type testAppReleaseStore struct {
release *types.AppRelease
err error
}
type testDevicePushTokenStore struct {
@@ -756,6 +757,9 @@ func (s *testProfilesStore) UpdatePrivacy(_ types.TenantID, uid types.Uid, patch
}
func (s *testAppReleaseStore) Latest(platform, channel string) (*types.AppRelease, error) {
if s.err != nil {
return nil, s.err
}
if s.release == nil {
now := time.Now().UTC().Round(time.Millisecond)
s.release = &types.AppRelease{
@@ -2742,6 +2746,26 @@ func TestServeIMAppReleaseLatestSupportsWeb(t *testing.T) {
}
}
func TestServeIMAppReleaseLatestFallsBackForWebConfigError(t *testing.T) {
oldReleases := store.AppReleases
store.AppReleases = &testAppReleaseStore{err: types.ErrUnsupported}
defer func() {
store.AppReleases = oldReleases
}()
req := httptest.NewRequest(http.MethodGet, "/v1/im/app/releases/latest?platform=web&current_version=1.0.0", nil)
rec := httptest.NewRecorder()
serveIMAppReleaseLatest(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status: got %d, want %d; body=%s", rec.Code, http.StatusOK, rec.Body.String())
}
data := decodeIMHTTPResponse(t, rec).Data.(map[string]any)
if data["platform"] != "web" || data["latest_version"] != "1.0.0" || data["update_type"] != "none" || data["has_update"] != false {
t.Fatalf("unexpected fallback release payload: %#v", data)
}
}
func TestServeIMAppReleaseLatestForcesUnsupportedVersion(t *testing.T) {
oldReleases := store.AppReleases
store.AppReleases = &testAppReleaseStore{release: &types.AppRelease{