Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

Sync: a guest copy holding only custom exercises moves into a newly created profile at once

Duarte Santos6b30f4182450
diff --git a/frontend/src/store/useStore.adopt.test.jsx b/frontend/src/store/useStore.adopt.test.jsx
index 7efa015c3..1f7c535f0 100644
--- a/frontend/src/store/useStore.adopt.test.jsx
+++ b/frontend/src/store/useStore.adopt.test.jsx
@@ -10,7 +10,7 @@ const { toast } = vi.hoisted(() => ({ toast: vi.fn() }))
vi.mock('./useUI.js', () => ({ useUI: { getState: () => ({ toast }) } }))
import { api } from '../lib/api.js'
-import { DEF, useStore } from './useStore.js'
+import { DEF, hasData, useStore } from './useStore.js'
const clone = value => JSON.parse(JSON.stringify(value))
const routine = id => ({ id, name: id, ex: [] })
@@ -100,6 +100,31 @@ describe('adoptProfile — sign-in takes the server profile', () => {
expect(r).toEqual({ adopted: true, added: false })
})
+ // QA, v1.3.9: a guest whose only data was a custom exercise (with its photo) created a profile;
+ // the files went up, but the state stayed empty on the server for the next poll to find while
+ // Settings said "All synced" — and the server counted the uploaded files as unreferenced.
+ it('moves a copy holding only custom exercises into a profile that has no state yet', async () => {
+ const onlyCustom = { ...clone(DEF), _ts: 900, customEx: [{ id: 'c1', n: 'sandbag carry', bp: 'back', custom: true, media: { kind: 'image', hash: 'a'.repeat(64), mime: 'image/webp', size: 3, width: 8, height: 6, at: 1 } }] }
+ expect(hasData(onlyCustom)).toBe(true) // what the register sheets check before pushing
+ signedIn(clone(onlyCustom))
+ api.mockResolvedValueOnce({ state: null, rev: 0 })
+ api.mockResolvedValueOnce({ ok: true, rev: 1 })
+ await useStore.getState().adoptProfile(vi.fn())
+ expect(puts()).toHaveLength(1)
+ expect(puts()[0].state.customEx.map(c => c.id)).toEqual(['c1'])
+ expect(puts()[0].state.customEx[0].media.hash).toBe('a'.repeat(64))
+ expect(sync().rev).toBe(1)
+ })
+
+ it('the first pull after a profile was created pushes a copy holding only custom exercises', async () => {
+ signedIn({ ...clone(DEF), _ts: 900, customEx: [{ id: 'c1', n: 'sandbag carry', bp: 'back', custom: true }] })
+ api.mockResolvedValueOnce({ state: null, rev: 0 })
+ api.mockResolvedValueOnce({ ok: true, rev: 1 })
+ await useStore.getState().pullState()
+ expect(puts()).toHaveLength(1)
+ expect(puts()[0].state.customEx.map(c => c.id)).toEqual(['c1'])
+ })
+
it('alwaysAsk: moves the device data into an empty profile once the user says so', async () => {
signedIn(clone(guest))
api.mockResolvedValueOnce({ state: null, rev: 0 })
diff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.js
index c5473208c..eb2d12189 100644
--- a/frontend/src/store/useStore.js
+++ b/frontend/src/store/useStore.js
@@ -190,7 +190,11 @@ function loadState() {
return s
}
-const hasData = st => !!((st.workouts || []).length || (st.routines || []).length || (st.bodyweight || []).length)
+// Whether a copy holds anything of its own worth keeping over another: workouts, routines,
+// weigh-ins and custom exercises. A custom exercise is all a new guest may have made — with its
+// photo or video, which the server counts as unreferenced until the state that names it lands —
+// so a profile created from such a copy takes it at once, like one holding a workout.
+const hasData = st => !!((st.workouts || []).length || (st.routines || []).length || (st.bodyweight || []).length || (st.customEx || []).length)
// Decide whether a pulled account state may replace the local saved state. A local active workout
// is deliberately carried forward: the server stores completed/saved state, while the in-progress