increment and decrement were mutating current_quantity locally then firing a debounced updateStock (PUT /stock), bypassing the dedicated delta endpoint entirely and risking overwriting concurrent edits with stale local state.
Changes
Bug fix — useStockManager.ts
Destructure adjustStockQuantity from useStocks()
Replace local mutation + queueDebouncedSave with adjustStockQuantity(stock.id, ±1) → POST /stock/:id/delta
Add proper saving → saved/error save-state transitions with feedback timers (consistent with save())
// Before
stock.current_quantity=normalizeQuantity(stock.current_quantity+1);queueDebouncedSave(stock);// PUT /stock — wrong endpoint, stale data
// After
awaitadjustStockQuantity(stock.id,1);// POST /stock/:id/delta
Remove now-dead queueDebouncedSave and saveDebounceMs
Test infrastructure
Add vitest + jsdom + @vue/test-utils; wire npm test / npm run test:watch
backend.test.ts — all stock HTTP functions (getStocks, createStock, editStock, deleteStock, adjustStockByDelta), including error paths
useStockManager.test.ts — useStockManager: increment, decrement, save, createNewStock, remove, state labels/classes, toggle view — 44 tests total
Original prompt
in the mobile part fix stock delta addition and save, verify each one of the endpoint and function of the app. You should probably add front test for this.
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.
`increment` and `decrement` were mutating `current_quantity` locally then firing a debounced `updateStock` (PUT `/stock`), bypassing the dedicated delta endpoint entirely and risking overwriting concurrent edits with stale local state.
## Changes
### Bug fix — `useStockManager.ts`
- Destructure `adjustStockQuantity` from `useStocks()`
- Replace local mutation + `queueDebouncedSave` with `adjustStockQuantity(stock.id, ±1)` → POST `/stock/:id/delta`
- Add proper `saving` → `saved`/`error` save-state transitions with feedback timers (consistent with `save()`)
```ts
// Before
stock.current_quantity = normalizeQuantity(stock.current_quantity + 1);
queueDebouncedSave(stock); // PUT /stock — wrong endpoint, stale data
// After
await adjustStockQuantity(stock.id, 1); // POST /stock/:id/delta
```
- Remove now-dead `queueDebouncedSave` and `saveDebounceMs`
### Test infrastructure
- Add `vitest` + `jsdom` + `@vue/test-utils`; wire `npm test` / `npm run test:watch`
- **`backend.test.ts`** — all stock HTTP functions (`getStocks`, `createStock`, `editStock`, `deleteStock`, `adjustStockByDelta`), including error paths
- **`stocks.test.ts`** — `useStocks` composable: load, add, update (with/without refresh), remove, adjust-by-delta
- **`useStockManager.test.ts`** — `useStockManager`: increment, decrement, save, createNewStock, remove, state labels/classes, toggle view — 44 tests total
<!-- START COPILOT CODING AGENT SUFFIX -->
<!-- START COPILOT ORIGINAL PROMPT -->
<details>
<summary>Original prompt</summary>
> in the mobile part fix stock delta addition and save, verify each one of the endpoint and function of the app. You should probably add front test for this.
</details>
<!-- START COPILOT CODING AGENT TIPS -->
---
📱 Kick off Copilot coding agent tasks wherever you are with [GitHub Mobile](https://gh.io/cca-mobile-docs), available on iOS and Android.
changed title from {-[WIP] Fix stock delta addition and save functionality-} to {+fix: increment/decrement use delta endpoint instead of full stock update+}
changed title from **{-[WIP] Fix stock delta addition and save functionality-}** to **{+fix: increment/decrement use delta endpoint instead of full stock update+}**
pendingSaves is now dead state: the debounce queue was removed, but the map is still allocated and save() still tries to cancel a non-existent pending timeout. Please remove pendingSaves (and the related cancel logic) or reintroduce the place where timeouts are added so the state is consistent.
`pendingSaves` is now dead state: the debounce queue was removed, but the map is still allocated and `save()` still tries to cancel a non-existent pending timeout. Please remove `pendingSaves` (and the related cancel logic) or reintroduce the place where timeouts are added so the state is consistent.
These tests call useStockManager() directly, but the composable registers onMounted/onBeforeUnmount hooks. Calling it outside a component setup produces Vue warnings and means the mount/unmount behavior (like loadStocks() on mount and timer cleanup) is never exercised. Consider mounting a minimal test component (via @vue/test-utils) that invokes the composable in setup(), and assert the lifecycle behavior there.
These tests call `useStockManager()` directly, but the composable registers `onMounted`/`onBeforeUnmount` hooks. Calling it outside a component setup produces Vue warnings and means the mount/unmount behavior (like `loadStocks()` on mount and timer cleanup) is never exercised. Consider mounting a minimal test component (via `@vue/test-utils`) that invokes the composable in `setup()`, and assert the lifecycle behavior there.
This suite overwrites globalThis.fetch with vi.fn() but never restores the original implementation. That can leak into other test files and cause unexpected failures. Save the original fetch before mocking and restore it in afterEach/afterAll.
This suite overwrites `globalThis.fetch` with `vi.fn()` but never restores the original implementation. That can leak into other test files and cause unexpected failures. Save the original `fetch` before mocking and restore it in `afterEach`/`afterAll`.
useStocks keeps stocks/loading/error as module-level refs, so state persists across tests. This file only clears mock calls, not the composable state, which can make tests order-dependent. Reset the module (e.g. vi.resetModules() + re-import) or explicitly reset stocks.value, loading.value, and error.value in beforeEach.
`useStocks` keeps `stocks/loading/error` as module-level refs, so state persists across tests. This file only clears mock calls, not the composable state, which can make tests order-dependent. Reset the module (e.g. `vi.resetModules()` + re-import) or explicitly reset `stocks.value`, `loading.value`, and `error.value` in `beforeEach`.
This repo uses Bun in CI (bun install), and already has mobile/bun.lock. Adding package-lock.json introduces a second lockfile that can drift from bun.lock (and bun.lock in this PR doesn’t include the new devDependencies). Please standardize on a single lockfile: either update/commit bun.lock and remove package-lock.json, or switch CI/package manager to npm and keep package-lock.json.
This repo uses Bun in CI (`bun install`), and already has `mobile/bun.lock`. Adding `package-lock.json` introduces a second lockfile that can drift from `bun.lock` (and `bun.lock` in this PR doesn’t include the new devDependencies). Please standardize on a single lockfile: either update/commit `bun.lock` and remove `package-lock.json`, or switch CI/package manager to npm and keep `package-lock.json`.
This PR fixes stock increment/decrement to use the backend delta endpoint (POST /stock/:id/delta) instead of mutating local quantity and doing a full stock PUT, and adds a Vitest-based unit test setup for the mobile frontend.
Changes:
Update useStockManager increment/decrement to call adjustStockQuantity(stock.id, ±1) and manage per-line save state (saving → saved/error).
Add Vitest + jsdom + Vue test tooling and unit tests for backend stock HTTP helpers, the useStocks composable, and useStockManager.
Add npm test / npm run test:watch scripts.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
File
Description
mobile/vitest.config.ts
Adds Vitest configuration (jsdom, globals) for frontend tests.
mobile/src/composables/useStockManager.ts
Switches increment/decrement to delta endpoint via adjustStockQuantity; removes debounced PUT path.
mobile/src/tests/useStockManager.test.ts
Adds unit tests for useStockManager behavior (increment/decrement/save/etc.).
mobile/src/tests/stocks.test.ts
Adds unit tests for useStocks (including adjust-by-delta).
mobile/src/tests/backend.test.ts
Adds unit tests for stock HTTP functions/endpoints and error paths.
mobile/package.json
Adds test scripts and devDependencies for Vitest/jsdom/test-utils.
mobile/package-lock.json
Introduces npm lockfile alongside existing Bun lockfile.
**Review:** Commented
## Pull request overview
This PR fixes stock increment/decrement to use the backend delta endpoint (POST `/stock/:id/delta`) instead of mutating local quantity and doing a full stock PUT, and adds a Vitest-based unit test setup for the mobile frontend.
**Changes:**
- Update `useStockManager` increment/decrement to call `adjustStockQuantity(stock.id, ±1)` and manage per-line save state (`saving` → `saved`/`error`).
- Add Vitest + jsdom + Vue test tooling and unit tests for backend stock HTTP helpers, the `useStocks` composable, and `useStockManager`.
- Add `npm test` / `npm run test:watch` scripts.
### Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 5 comments.
<details>
<summary>Show a summary per file</summary>
| File | Description |
| ---- | ----------- |
| mobile/vitest.config.ts | Adds Vitest configuration (jsdom, globals) for frontend tests. |
| mobile/src/composables/useStockManager.ts | Switches increment/decrement to delta endpoint via `adjustStockQuantity`; removes debounced PUT path. |
| mobile/src/__tests__/useStockManager.test.ts | Adds unit tests for `useStockManager` behavior (increment/decrement/save/etc.). |
| mobile/src/__tests__/stocks.test.ts | Adds unit tests for `useStocks` (including adjust-by-delta). |
| mobile/src/__tests__/backend.test.ts | Adds unit tests for stock HTTP functions/endpoints and error paths. |
| mobile/package.json | Adds test scripts and devDependencies for Vitest/jsdom/test-utils. |
| mobile/package-lock.json | Introduces npm lockfile alongside existing Bun lockfile. |
</details>
---
💡 <a href="/THoguet/expiry-scanner/new/main?filename=.github/instructions/*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.
Source requested reviewers: admin-backup (GitLab user 3).
The linked history record retains original IDs and source dates. No historical identity was merged into nessar or granted new authentication permissions.
<!-- gitlab-to-gitea-assignment:16:MergeRequest:5 -->
Preserved source assignment/reviewer metadata. Historical accounts stay inactive.
Source requested reviewers: admin-backup (GitLab user 3).
The linked history record retains original IDs and source dates. No historical identity was merged into nessar or granted new authentication permissions.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
incrementanddecrementwere mutatingcurrent_quantitylocally then firing a debouncedupdateStock(PUT/stock), bypassing the dedicated delta endpoint entirely and risking overwriting concurrent edits with stale local state.Changes
Bug fix —
useStockManager.tsadjustStockQuantityfromuseStocks()queueDebouncedSavewithadjustStockQuantity(stock.id, ±1)→ POST/stock/:id/deltasaving→saved/errorsave-state transitions with feedback timers (consistent withsave())queueDebouncedSaveandsaveDebounceMsTest infrastructure
vitest+jsdom+@vue/test-utils; wirenpm test/npm run test:watchbackend.test.ts— all stock HTTP functions (getStocks,createStock,editStock,deleteStock,adjustStockByDelta), including error pathsstocks.test.ts—useStockscomposable: load, add, update (with/without refresh), remove, adjust-by-deltauseStockManager.test.ts—useStockManager: increment, decrement, save, createNewStock, remove, state labels/classes, toggle view — 44 tests totalOriginal prompt
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.
assigned to
@Copilotassigned to
@THoguetchanged title from {-[WIP] Fix stock delta addition and save functionality-} to {+fix: increment/decrement use delta endpoint instead of full stock update+}
requested review from
@THoguetapproved this merge request
requested review from
@CopilotpendingSavesis now dead state: the debounce queue was removed, but the map is still allocated andsave()still tries to cancel a non-existent pending timeout. Please removependingSaves(and the related cancel logic) or reintroduce the place where timeouts are added so the state is consistent.These tests call
useStockManager()directly, but the composable registersonMounted/onBeforeUnmounthooks. Calling it outside a component setup produces Vue warnings and means the mount/unmount behavior (likeloadStocks()on mount and timer cleanup) is never exercised. Consider mounting a minimal test component (via@vue/test-utils) that invokes the composable insetup(), and assert the lifecycle behavior there.This suite overwrites
globalThis.fetchwithvi.fn()but never restores the original implementation. That can leak into other test files and cause unexpected failures. Save the originalfetchbefore mocking and restore it inafterEach/afterAll.useStockskeepsstocks/loading/erroras module-level refs, so state persists across tests. This file only clears mock calls, not the composable state, which can make tests order-dependent. Reset the module (e.g.vi.resetModules()+ re-import) or explicitly resetstocks.value,loading.value, anderror.valueinbeforeEach.This repo uses Bun in CI (
bun install), and already hasmobile/bun.lock. Addingpackage-lock.jsonintroduces a second lockfile that can drift frombun.lock(andbun.lockin this PR doesn’t include the new devDependencies). Please standardize on a single lockfile: either update/commitbun.lockand removepackage-lock.json, or switch CI/package manager to npm and keeppackage-lock.json.Review: Commented
Pull request overview
This PR fixes stock increment/decrement to use the backend delta endpoint (POST
/stock/:id/delta) instead of mutating local quantity and doing a full stock PUT, and adds a Vitest-based unit test setup for the mobile frontend.Changes:
useStockManagerincrement/decrement to calladjustStockQuantity(stock.id, ±1)and manage per-line save state (saving→saved/error).useStockscomposable, anduseStockManager.npm test/npm run test:watchscripts.Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
adjustStockQuantity; removes debounced PUT path.useStockManagerbehavior (increment/decrement/save/etc.).useStocks(including adjust-by-delta).💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
@copilotrequested review from
@THoguetPreserved source assignment/reviewer metadata. Historical accounts stay inactive.
Source requested reviewers: admin-backup (GitLab user 3).
The linked history record retains original IDs and source dates. No historical identity was merged into nessar or granted new authentication permissions.
Preserved GitLab !5 history: source attribution, exact timestamps, discussion grouping and review positions. Historical diff snapshots: 1; visible source notes: 14.
gitlab-16-mergerequest-5.md (SHA-256
af59a4b487604463b27e6ef7bd5e40ce6abf33e0c52dc98cbd6bad00f94cf4b2)gitlab-16-mergerequest-5.json (SHA-256
b3f69677ab8d0653193b9c0577f2e3dc4bd9cf4be86c98cfd147c96d50d81634)Old CI job execution and reports are omitted. Original source files and rollback backups remain protected.
Pull request closed