Skip to content

Commit

Permalink
Disable drawer get resource according feature flag (#3153)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-duval authored Nov 29, 2024
1 parent fee97da commit aeb50ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.redhat.cloud.notifications.routers;

import com.redhat.cloud.notifications.config.BackendConfig;
import com.redhat.cloud.notifications.db.Query;
import com.redhat.cloud.notifications.db.repositories.DrawerNotificationRepository;
import com.redhat.cloud.notifications.models.DrawerEntryPayload;
Expand Down Expand Up @@ -39,6 +40,9 @@ public class DrawerResource {
@Inject
DrawerNotificationRepository drawerRepository;

@Inject
BackendConfig backendConfig;

@Path(API_NOTIFICATIONS_V_1_0 + "/notifications/drawer")
public static class V1 extends DrawerResource {

Expand All @@ -58,10 +62,13 @@ public Page<DrawerEntryPayload> getDrawerEntries(@Context SecurityContext securi
String orgId = getOrgId(securityContext);
String username = getUsername(securityContext);
LocalDateTime start = LocalDateTime.now();
Long count = drawerRepository.count(orgId, username, bundleIds, appIds, eventTypeIds, startDate, endDate, readStatus);
List<DrawerEntryPayload> drawerEntries = new ArrayList<>();
if (count > 0) {
drawerEntries = drawerRepository.getNotifications(orgId, username, bundleIds, appIds, eventTypeIds, startDate, endDate, readStatus, query);
Long count = 0L;
if (backendConfig.isDrawerEnabled()) {
count = drawerRepository.count(orgId, username, bundleIds, appIds, eventTypeIds, startDate, endDate, readStatus);
if (count > 0) {
drawerEntries = drawerRepository.getNotifications(orgId, username, bundleIds, appIds, eventTypeIds, startDate, endDate, readStatus, query);
}
}
LocalDateTime now = LocalDateTime.now();
Log.infof("Drawer request duration %s for orgId: %s, userId: %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.redhat.cloud.notifications.MockServerConfig;
import com.redhat.cloud.notifications.TestHelpers;
import com.redhat.cloud.notifications.TestLifecycleManager;
import com.redhat.cloud.notifications.config.BackendConfig;
import com.redhat.cloud.notifications.db.DbIsolatedTest;
import com.redhat.cloud.notifications.db.ResourceHelpers;
import com.redhat.cloud.notifications.models.Application;
Expand All @@ -14,6 +15,7 @@
import com.redhat.cloud.notifications.models.EventType;
import com.redhat.cloud.notifications.routers.models.Page;
import com.redhat.cloud.notifications.routers.models.UpdateNotificationDrawerStatus;
import io.quarkus.test.InjectMock;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.common.mapper.TypeRef;
Expand All @@ -39,6 +41,7 @@
import static java.time.ZoneOffset.UTC;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

@QuarkusTest
@QuarkusTestResource(TestLifecycleManager.class)
Expand All @@ -53,9 +56,12 @@ public class DrawerResourceTest extends DbIsolatedTest {
@Inject
ResourceHelpers resourceHelpers;

@InjectMock
BackendConfig backendConfig;

@Test
void testMultiplePages() {

when(backendConfig.isDrawerEnabled()).thenReturn(true);
final String USERNAME = "user-1";
Header defaultIdentityHeader = mockRbac(DEFAULT_ACCOUNT_ID, DEFAULT_ORG_ID, USERNAME, FULL_ACCESS);

Expand Down Expand Up @@ -95,7 +101,7 @@ void testMultiplePages() {

@Test
void testFilters() {

when(backendConfig.isDrawerEnabled()).thenReturn(true);
Bundle createdBundle = resourceHelpers.createBundle("test-drawer-event-resource-bundle");
Bundle createdBundle2 = resourceHelpers.createBundle("test-drawer-event-resource-bundle2");
Application createdApplication = resourceHelpers.createApplication(createdBundle.getId(), "test-drawer-event-resource-application");
Expand Down

0 comments on commit aeb50ad

Please sign in to comment.