@@ -10,6 +10,8 @@ import { generatePlay } from "../utils/PlayTestUtils.js";
1010import { TestSource } from "./TestSource.js" ;
1111import spotifyPayload from '../plays/spotifyCurrentPlaybackState.json' ;
1212import SpotifySource from "../../sources/SpotifySource.js" ;
13+ import { timePassesScrobbleThreshold } from "../../utils/TimeUtils.js" ;
14+ import { DEFAULT_SCROBBLE_DURATION_THRESHOLD , DEFAULT_SCROBBLE_PERCENT_THRESHOLD } from "../../common/infrastructure/Atomic.js" ;
1315
1416chai . use ( asPromised ) ;
1517
@@ -159,4 +161,40 @@ describe('Sources correctly parse incoming payloads', function () {
159161 expect ( identicalArtistsPlay . data . artists ) . eql ( [ 'Dubmood' , 'MASTER BOOT RECORD' ] ) ;
160162 expect ( identicalArtistsPlay . data . albumArtists ) . to . be . empty ;
161163 } ) ;
164+ } ) ;
165+
166+ describe ( 'Scrobble Threshold Checks' , function ( ) {
167+
168+ it ( 'uses defaults when no user-configured thresholds are passed' , function ( ) {
169+ const results = timePassesScrobbleThreshold ( { } , 1 , 1 ) ;
170+ expect ( results . duration . threshold ) . to . eq ( DEFAULT_SCROBBLE_DURATION_THRESHOLD ) ;
171+ expect ( results . percent . threshold ) . to . eq ( DEFAULT_SCROBBLE_PERCENT_THRESHOLD ) ;
172+ } ) ;
173+
174+ it ( 'uses user-configured thresholds when passed' , function ( ) {
175+ const results = timePassesScrobbleThreshold ( {
176+ duration : 20 ,
177+ percent : 15
178+ } , 1 , 1 ) ;
179+ expect ( results . duration . threshold ) . to . eq ( 20 ) ;
180+ expect ( results . percent . threshold ) . to . eq ( 15 ) ;
181+ } ) ;
182+
183+ it ( 'passes when duration is above threshold' , function ( ) {
184+ const results = timePassesScrobbleThreshold ( { } , DEFAULT_SCROBBLE_DURATION_THRESHOLD + 1 ) ;
185+ expect ( results . duration . passes ) . is . true ;
186+ expect ( results . passes ) . is . true ;
187+ } ) ;
188+
189+ it ( 'passes when percent is above threshold' , function ( ) {
190+ const results = timePassesScrobbleThreshold ( { } , 30 , 50 ) ;
191+ expect ( results . percent . passes ) . is . true ;
192+ expect ( results . passes ) . is . true ;
193+ } ) ;
194+
195+ it ( 'handles zero duration' , function ( ) {
196+ const results = timePassesScrobbleThreshold ( { } , DEFAULT_SCROBBLE_DURATION_THRESHOLD + 1 , 0 ) ;
197+ expect ( results . duration . passes ) . is . true ;
198+ expect ( results . passes ) . is . true ;
199+ } ) ;
162200} ) ;
0 commit comments