@@ -170,6 +170,55 @@ describe('mapFeedItem', () => {
170170 expect ( result ?. action ) . toBe ( 'sold' ) ;
171171 } ) ;
172172
173+ it ( 'keeps a perp enter fill as "opened" even when the snapshot looks closed' , ( ) => {
174+ const result = mapFeedItem (
175+ mockPerpFeedItem ( {
176+ // A closed-looking snapshot (Clicker reports currentValueUSD === 0) must
177+ // not override the triggering trade's `enter` intent.
178+ currentValueUSD : 0 ,
179+ trades : [
180+ {
181+ direction : 'buy' ,
182+ intent : 'enter' ,
183+ tokenAmount : 5 ,
184+ usdCost : 50600 ,
185+ timestamp : 1_700_000_500 ,
186+ transactionHash : '0xhash' ,
187+ classification : 'perp' ,
188+ perpPositionType : 'long' ,
189+ perpLeverage : 8 ,
190+ } ,
191+ ] ,
192+ } ) ,
193+ ) ;
194+
195+ expect ( result ?. action ) . toBe ( 'opened' ) ;
196+ } ) ;
197+
198+ it ( 'keeps a spot enter fill as "bought" even when the snapshot looks closed' , ( ) => {
199+ const result = mapFeedItem (
200+ mockSpotFeedItem ( {
201+ // Closed-looking spot snapshot (fully sold out) must still defer to the
202+ // triggering trade's `enter` intent.
203+ positionAmount : 0 ,
204+ soldUsd : 100_000 ,
205+ trades : [
206+ {
207+ direction : 'buy' ,
208+ intent : 'enter' ,
209+ tokenAmount : 1000 ,
210+ usdCost : 120000 ,
211+ timestamp : 1_700_000_000 ,
212+ transactionHash : '0xhash' ,
213+ classification : 'spot' ,
214+ } ,
215+ ] ,
216+ } ) ,
217+ ) ;
218+
219+ expect ( result ?. action ) . toBe ( 'bought' ) ;
220+ } ) ;
221+
173222 it ( 'returns null for a spot trade on an unsupported chain' , ( ) => {
174223 const result = mapFeedItem ( mockSpotFeedItem ( { chain : 'fantom' } ) ) ;
175224
0 commit comments