@@ -267,6 +267,116 @@ async function buildSeedData() {
267267 console . log ( ` - Distribution Lead: ${ distributionLead . email } ` ) ;
268268 console . log ( ` - Partner 1: ${ partner1 . email } ` ) ;
269269 console . log ( ` - Partner 2: ${ partner2 . email } ` ) ;
270+
271+ // ============================================================================
272+ // Test: partner has an existing manual wishlist entry for an item,
273+ // then a distribution only partially fulfills their request for that same item.
274+ // Expected: existing wishlist entry quantity increases by the unfulfilled amount.
275+ //
276+ // Partner 1 manually added "Gauze Pads" to their wishlist (qty: 50) — this
277+ // simulates a wishlist entry they created themselves before any donor offer.
278+ // A donor offer comes in for Gauze Pads, Partner 1 requests 200.
279+ // Distribution only allocates 1 line item (75 units) → unfulfilled = 125.
280+ // Expected final wishlist qty: 50 + 125 = 175
281+ // ============================================================================
282+
283+ // Step 1: Partner 1 manually creates a wishlist entry beforehand
284+ await db . wishlist . create ( {
285+ data : {
286+ name : "Gauze Pads" ,
287+ quantity : 50 ,
288+ priority : "MEDIUM" ,
289+ comments : "We are always in need of these" ,
290+ partnerId : partner1 . id ,
291+ } ,
292+ } ) ;
293+
294+ console . log ( "✓ Created manual wishlist entry for Partner 1: Gauze Pads qty 50" ) ;
295+
296+ // Step 2: Donor offer comes in with Gauze Pads
297+ const gauzeOffer = await db . donorOffer . create ( {
298+ data : {
299+ offerName : "Gauze Pads Offer" ,
300+ donorName : "Test Donor" ,
301+ state : "FINALIZED" ,
302+ partnerResponseDeadline : new Date ( Date . now ( ) + 7 * 24 * 60 * 60 * 1000 ) ,
303+ donorResponseDeadline : new Date ( Date . now ( ) + 14 * 24 * 60 * 60 * 1000 ) ,
304+ partnerVisibilities : {
305+ connect : [ { id : partner1 . id } ] ,
306+ } ,
307+ } ,
308+ } ) ;
309+
310+ const gauzeItem = await db . generalItem . create ( {
311+ data : {
312+ donorOfferId : gauzeOffer . id ,
313+ title : "Gauze Pads" ,
314+ unitType : "Box" ,
315+ initialQuantity : 200 ,
316+ weight : 0.3 ,
317+ } ,
318+ } ) ;
319+
320+ // Two line items: 75 units and 125 units
321+ const gauzeLineItem1 = await db . lineItem . create ( {
322+ data : {
323+ generalItemId : gauzeItem . id ,
324+ donorName : "Test Donor" ,
325+ quantity : 75 ,
326+ lotNumber : "GLOT-1" ,
327+ palletNumber : "GPAL-1" ,
328+ boxNumber : "GBOX-1" ,
329+ unitPrice : 3.0 ,
330+ allowAllocations : true ,
331+ visible : true ,
332+ gik : true ,
333+ } ,
334+ } ) ;
335+
336+ await db . lineItem . create ( {
337+ data : {
338+ generalItemId : gauzeItem . id ,
339+ donorName : "Test Donor" ,
340+ quantity : 125 ,
341+ lotNumber : "GLOT-2" ,
342+ palletNumber : "GPAL-1" ,
343+ boxNumber : "GBOX-2" ,
344+ unitPrice : 3.0 ,
345+ allowAllocations : true ,
346+ visible : true ,
347+ gik : true ,
348+ } ,
349+ } ) ;
350+
351+ // Step 3: Partner 1 requests 200 units
352+ await db . generalItemRequest . create ( {
353+ data : {
354+ generalItemId : gauzeItem . id ,
355+ partnerId : partner1 . id ,
356+ quantity : 200 ,
357+ priority : "MEDIUM" ,
358+ finalQuantity : 200 ,
359+ comments : "Requested from donor offer" ,
360+ } ,
361+ } ) ;
362+
363+ // Step 4: Distribution created — only allocates the 75 unit line item
364+ const gauzeDist = await db . distribution . create ( {
365+ data : {
366+ partnerId : partner1 . id ,
367+ pending : true ,
368+ allocations : {
369+ create : [ { lineItemId : gauzeLineItem1 . id , partnerId : partner1 . id } ] ,
370+ } ,
371+ } ,
372+ } ) ;
373+
374+ console . log ( "✓ Created Gauze Pads distribution test" ) ;
375+ console . log ( ` - Distribution ID: ${ gauzeDist . id } (pending)` ) ;
376+ console . log ( ` - Partner 1 wishlist BEFORE approval: Gauze Pads qty 50` ) ;
377+ console . log ( ` - After approving dist ${ gauzeDist . id } :` ) ;
378+ console . log ( ` unfulfilled = 200 - 75 = 125` ) ;
379+ console . log ( ` merged wishlist qty = 50 + 125 = 175` ) ;
270380}
271381
272382buildSeedData ( )
0 commit comments