|
10 | 10 | import com.urbanairship.PrivacyManager;
|
11 | 11 | import com.urbanairship.ShadowAirshipExecutorsLegacy;
|
12 | 12 | import com.urbanairship.TestApplication;
|
| 13 | +import com.urbanairship.TestDeviceInfoProvider; |
13 | 14 | import com.urbanairship.TestRequestSession;
|
14 | 15 | import com.urbanairship.UAirship;
|
15 | 16 | import com.urbanairship.analytics.CustomEvent;
|
|
79 | 80 | import static org.junit.Assert.assertFalse;
|
80 | 81 | import static org.junit.Assert.assertTrue;
|
81 | 82 | import static org.mockito.ArgumentMatchers.any;
|
| 83 | +import static org.mockito.ArgumentMatchers.anyInt; |
82 | 84 | import static org.mockito.ArgumentMatchers.eq;
|
83 | 85 | import static org.mockito.ArgumentMatchers.nullable;
|
84 | 86 | import static org.mockito.Mockito.atLeastOnce;
|
@@ -139,6 +141,9 @@ public class InAppAutomationTest {
|
139 | 141 | @Before
|
140 | 142 | public void setup() {
|
141 | 143 | when(mockRuntimeConfig.getConfigOptions()).thenAnswer((Answer<AirshipConfigOptions>) invocation -> config);
|
| 144 | + |
| 145 | + when(mockInfoProvider.getChannelId()).thenReturn("channel-id"); |
| 146 | + |
142 | 147 | mockChannel = mock(AirshipChannel.class);
|
143 | 148 | mockIamManager = mock(InAppMessageManager.class);
|
144 | 149 | mockObserver = mock(InAppRemoteDataObserver.class);
|
@@ -324,6 +329,38 @@ public void testPrepareSchedule() {
|
324 | 329 | verify(callback).onFinish(AutomationDriver.PREPARE_RESULT_CONTINUE);
|
325 | 330 | }
|
326 | 331 |
|
| 332 | + |
| 333 | + @Test |
| 334 | + public void testPrepareScheduleNoChannelId() { |
| 335 | + when(mockInfoProvider.getChannelId()).thenReturn(null); |
| 336 | + |
| 337 | + InAppMessage message = InAppMessage.newBuilder() |
| 338 | + .setDisplayContent(new CustomDisplayContent(JsonValue.NULL)) |
| 339 | + .build(); |
| 340 | + |
| 341 | + Schedule<InAppMessage> schedule = Schedule.newBuilder(message) |
| 342 | + .addTrigger(Triggers.newAppInitTriggerBuilder().setGoal(1).build()) |
| 343 | + .setBypassHoldoutGroups(true) |
| 344 | + .build(); |
| 345 | + |
| 346 | + when(mockObserver.requiresRefresh(eq(schedule))).thenReturn(false); |
| 347 | + when(mockObserver.bestEffortRefresh(eq(schedule))).thenReturn(true); |
| 348 | + |
| 349 | + AutomationDriver.PrepareScheduleCallback callback = mock(AutomationDriver.PrepareScheduleCallback.class); |
| 350 | + driver.onPrepareSchedule(schedule, null, callback); |
| 351 | + verify(mockMessageScheduleDelegate, never()).onPrepareSchedule(eq(schedule), eq(schedule.getData()), any(), any()); |
| 352 | + verify(callback, never()).onFinish(anyInt()); |
| 353 | + |
| 354 | + // Sanity check: we should be able to prepare a schedule once we do have a channel ID. |
| 355 | + when(mockInfoProvider.getChannelId()).thenReturn("channel-id"); |
| 356 | + |
| 357 | + driver.onPrepareSchedule(schedule, null, callback); |
| 358 | + ArgumentCaptor<AutomationDriver.PrepareScheduleCallback> argumentCaptor = ArgumentCaptor.forClass(AutomationDriver.PrepareScheduleCallback.class); |
| 359 | + verify(mockMessageScheduleDelegate).onPrepareSchedule(eq(schedule), eq(schedule.getData()), any(), argumentCaptor.capture()); |
| 360 | + argumentCaptor.getValue().onFinish(AutomationDriver.PREPARE_RESULT_CONTINUE); |
| 361 | + verify(callback).onFinish(AutomationDriver.PREPARE_RESULT_CONTINUE); |
| 362 | + } |
| 363 | + |
327 | 364 | @Test
|
328 | 365 | public void testPrepareScheduleRequiresRefresh() {
|
329 | 366 | InAppMessage message = InAppMessage.newBuilder()
|
|
0 commit comments