fix on shelf

This commit is contained in:
2026-08-31 15:51:36 +05:30
parent 4bce5ac854
commit d55f101834
11 changed files with 704 additions and 55 deletions

View File

@@ -37,6 +37,10 @@ type fakeProductRepo struct {
calls []string
existing *models.Products
// Set only by tests that exercise the stable-key path; nil leaves the
// import falling through to the catalogueid lookup as before.
existingByImage *models.Products
linked [][2]any
ensuredRefs []models.ProductLocationRef
syncedRefs []models.ProductLocationRef
@@ -64,6 +68,24 @@ func (f *fakeProductRepo) SyncProductLocationStatus(refs []models.ProductLocatio
return nil
}
// The stable-key lookup, which the import now tries FIRST.
//
// Answers nothing unless a test sets `existingByImage`, so the fallback to the
// catalogueid ref still runs and the existing cases keep exercising it. That
// order is the fix for renumbering: `catalogueid` changes on every re-scrape,
// so a miss there makes the import believe it has never seen the product and
// create a duplicate.
func (f *fakeProductRepo) FindTenantProductByImageID(tenantid int, imageid string) (*models.Products, error) {
f.calls = append(f.calls, "FindTenantProductByImageID")
return f.existingByImage, nil
}
func (f *fakeProductRepo) SetCatalogueLink(productid int, imageid string, catalogueid int) error {
f.calls = append(f.calls, "SetCatalogueLink")
f.linked = append(f.linked, [2]any{productid, imageid})
return nil
}
func (f *fakeProductRepo) FindTenantProductByCatalogueRef(tenantid int, brand string, catalogueid int64) (*models.Products, error) {
f.calls = append(f.calls, "FindTenantProductByCatalogueRef")
return f.existing, nil