Skip to content

Commit

Permalink
FFM-10286 Unit test for missing last auth tie
Browse files Browse the repository at this point in the history
  • Loading branch information
erdirowlands committed Dec 29, 2023
1 parent 37c123d commit 6b2cc22
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion force-app/test/FFClientTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private class FFClientTest {
private FFModels.AuthInfo mockAuthInfo;
private Long mockLastAuthTime;
public Boolean authenticateCalled = false;
public Boolean simulateEvictedAuthToken;
public Boolean simulateEvictedAuthToken = false;

public MockFFAuthService(FFModels.AuthInfo mockAuthInfo) {
this.mockAuthInfo = mockAuthInfo;
Expand Down Expand Up @@ -325,6 +325,36 @@ private class FFClientTest {
System.assertEquals(true, mockAuthService.authenticateCalled, 'Reauthentication was not triggered as expected');
}

@isTest
private static void shouldReauthenticateWhenLastAuthTimeIsMissing() {
// Create mock authentication information
FFModels.AuthInfo mockAuthInfo = new FFModels.AuthInfo('mockToken', 'envUUID', 'cluster');
MockFFAuthService mockAuthService = new MockFFAuthService(mockAuthInfo);

// Don't set the last auth time in order to simulate a cache eviction, just create client

// Create the FFClient configuration with a specified expiration interval
FFConfig config = FFConfig.builder().authExpireAfter(24 * 60 * 60) // Token expires after 24 hours
.cache(new FFMockCache()).build();

List<FFModelsFeatures.FeatureConfig> features = new List<FFModelsFeatures.FeatureConfig>();
List<FFModelsFeatures.TargetSegment> targets = new List<FFModelsFeatures.TargetSegment>();

// Instantiate FFClient with the mock auth service
FFClient client = new FFClient(mockAuthService, mockApi(features, targets), mockMetricsApi(features, targets), config, 'test', 'test');

// Instantiate the CacheUpdator with the FFClient instance
FFClient.CacheUpdator cacheUpdator = new FFClient.CacheUpdator(client);

// Directly invoke the logic that would be triggered by the poller
// Call the cacheUpdator twice, because it skips on the first iteration.
cacheUpdator.call(null, null);
cacheUpdator.call(null, null);

// Verify that reauthentication was triggered due to the token missing
System.assertEquals(true, mockAuthService.authenticateCalled, 'Reauthentication was not triggered as expected');
}

@isTest
private static void shouldNotReauthenticateWhenTokenIsStillValid() {
// Create mock authentication information
Expand Down

0 comments on commit 6b2cc22

Please sign in to comment.