Skip to content

Commit

Permalink
better test
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Pickett committed Dec 17, 2024
1 parent 7b1c072 commit 9a4ad0c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion ee/presencedetection/presencedetection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,18 @@ func TestPresenceDetector_AttemptInterval(t *testing.T) {
minDetectionAttemptInterval: 500 * time.Millisecond,
}

// first detection, should prompt user for new detection
interval, err := pd.DetectPresence("this is a test", 0)
assert.NoError(t, err)

require.Equal(t, time.Duration(0), interval,
"interval should be 0 since detection just happened",
)

d = mocks.NewDetectorIface(t)
pd.detector = d

// second detection, should NOT prompt user for new detection
// since within min interval
interval, err = pd.DetectPresence("this is a test", 0)
assert.NoError(t, err)
require.Greater(t, interval, time.Duration(0),
Expand All @@ -137,4 +139,14 @@ func TestPresenceDetector_AttemptInterval(t *testing.T) {

// should not have been called since we are within the minDetectionAttemptInterval
d.AssertNotCalled(t, "Detect", mock.Anything)

time.Sleep(1 * time.Second)

// third detection, should prompt user for new detection since minDetectionAttemptInterval has passed
d.On("Detect", mock.AnythingOfType("string")).Return(true, nil).Once()
interval, err = pd.DetectPresence("this is a test", 0)
assert.NoError(t, err)
require.Equal(t, time.Duration(0), interval,
"interval should be 0 since detection just happened",
)
}

0 comments on commit 9a4ad0c

Please sign in to comment.