Skip to content

Commit 62c04b4

Browse files
Feat/remove ff from logs (#687)
* Feat : Removed feature flag dependency and fixed UI issue * Test : Added tests for ff removal * Chore : Removed comments * Refactor : Removed fix for accordion height issue --------- Co-authored-by: Ajoy Kumar Das <[email protected]>
1 parent 09c97da commit 62c04b4

File tree

3 files changed

+37
-85
lines changed

3 files changed

+37
-85
lines changed

__tests__/extension-requests/extension-requests.test.js

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ describe('Tests the Extension Requests Screen', () => {
305305
});
306306
} else if (
307307
url ===
308-
'https://api.realdevsquad.com/logs/extensionRequests/?meta.extensionRequestId=fuQs71a0Y7BX3n4rc5Ii&dev=true'
308+
'https://api.realdevsquad.com/logs/extensionRequests/?meta.extensionRequestId=fuQs71a0Y7BX3n4rc5Ii'
309309
) {
310310
interceptedRequest.respond({
311311
status: 200,
@@ -319,7 +319,7 @@ describe('Tests the Extension Requests Screen', () => {
319319
});
320320
} else if (
321321
url ===
322-
'https://api.realdevsquad.com/extension-requests/fuQs71a0Y7BX3n4rc5Ii?dev=true'
322+
'https://api.realdevsquad.com/extension-requests/fuQs71a0Y7BX3n4rc5Ii'
323323
) {
324324
interceptedRequest.respond({
325325
status: 200,
@@ -332,7 +332,7 @@ describe('Tests the Extension Requests Screen', () => {
332332
});
333333
} else if (
334334
url ===
335-
'https://api.realdevsquad.com/logs/extensionRequests/?meta.extensionRequestId=lw7dRB0I3a6ivsFR5Izs&dev=true'
335+
'https://api.realdevsquad.com/logs/extensionRequests/?meta.extensionRequestId=lw7dRB0I3a6ivsFR5Izs'
336336
) {
337337
interceptedRequest.respond({
338338
status: 200,
@@ -771,54 +771,37 @@ describe('Tests the Extension Requests Screen', () => {
771771
expect(isTooltipVisible).toBe(true);
772772
});
773773
it('Validating audit logs for extension request', async () => {
774-
// Visit extension request under dev flag
775-
await page.goto('http://localhost:8000/extension-requests/?dev=true');
774+
await page.goto('http://localhost:8000/extension-requests');
776775
const extensionRequestIds = [
777776
'log-container-fuQs71a0Y7BX3n4rc5Ii',
778777
'log-container-lw7dRB0I3a6ivsFR5Izs',
779778
];
780779

781-
// Select all types of status of extension requests
782780
await page.click('#filter-button');
783781
await page.click('input[value="APPROVED"]');
784782
await page.click('input[value="DENIED"]');
785783
await page.click('#apply-filter-button');
786784
await page.waitForNetworkIdle();
787785

788-
// Checking if both the extension request cards are renedered or not
789786
const cardsList = await page.$$('.extension-card');
790787
expect(cardsList.length).toBe(2);
791788

792789
const accordionButton = await page.$$('.accordion');
793-
// Validate first extension card which is based on updated logs
794790
accordionButton[0].click();
795791
await page.waitForNetworkIdle();
796792
let extensionLogsForFirstER = await page.$(`#${extensionRequestIds[0]}`);
797793
let logs = await extensionLogsForFirstER.$$('.log-div');
798794
expect(Array.from(logs).length).toBe(6);
799-
// Array.from(logs).forEach(async (log) => {
800-
// const innerText = await log.evaluate((element) => element.innerText);
801-
// expect(extensionRequestLogsInSentence[extensionRequestIds[0]]).toContain(
802-
// innerText,
803-
// );
804-
// });
805-
806-
// Validating if it is backward compatible or not
795+
807796
accordionButton[1].click();
808797
await page.waitForNetworkIdle();
809798
extensionLogsForFirstER = await page.$(`#${extensionRequestIds[1]}`);
810799
logs = await extensionLogsForFirstER.$$('.log-div');
811800
expect(Array.from(logs).length).toBe(1);
812-
// Array.from(logs).forEach(async (log) => {
813-
// const innerText = await log.evaluate((element) => element.innerText);
814-
// expect(extensionRequestLogsInSentence[extensionRequestIds[1]]).toContain(
815-
// innerText,
816-
// );
817-
// });
818801
});
819802

820803
test('Checks the Request Number and request value element on Extension requests listing page', async () => {
821-
const url = 'http://localhost:8000/extension-requests/?dev=true'; // Include the dev parameter in the URL
804+
const url = 'http://localhost:8000/extension-requests';
822805
await page.goto(url);
823806

824807
const extensionRequestNumberContainer = await page.$$(
@@ -834,7 +817,7 @@ describe('Tests the Extension Requests Screen', () => {
834817
});
835818

836819
test('Default Request Number to 1 if requestNumber field is missing in API Response', async () => {
837-
const url = 'http://localhost:8000/extension-requests/?dev=true'; // Include the dev parameter in the URL
820+
const url = 'http://localhost:8000/extension-requests';
838821
await page.goto(url);
839822

840823
const extensionRequestNumberContainer = await page.$$(
@@ -851,38 +834,32 @@ describe('Tests the Extension Requests Screen', () => {
851834
});
852835

853836
it('Validating if audit logs are being generated in realtime', async () => {
854-
// Visit extension request under dev flag
855-
await page.goto('http://localhost:8000/extension-requests/?dev=true');
837+
await page.goto('http://localhost:8000/extension-requests');
856838
const extensionRequestIds = [
857839
'log-container-fuQs71a0Y7BX3n4rc5Ii',
858840
'log-container-lw7dRB0I3a6ivsFR5Izs',
859841
];
860842

861-
// Select all types of status of extension requests
862843
await page.click('#filter-button');
863844
await page.click('input[value="APPROVED"]');
864845
await page.click('input[value="DENIED"]');
865846
await page.click('#apply-filter-button');
866847
await page.waitForNetworkIdle();
867848

868-
// Checking if both the extension request cards are renedered or not
869849
const cardsList = await page.$$('.extension-card');
870850
expect(cardsList.length).toBe(2);
871851

872852
const accordionButton = await page.$$('.accordion');
873-
// Validate first extension card which is based on updated logs
874853
accordionButton[0].click();
875854
await page.waitForNetworkIdle();
876855
let extensionLogsForFirstER = await page.$(`#${extensionRequestIds[0]}`);
877856
let logs = await extensionLogsForFirstER.$$('.log-div');
878857

879-
// Click the first element with class '.edit-button'
880858
await page.$$eval('.edit-button', (buttons) => buttons[0].click());
881859
const newTitle = 'This is a new title test case';
882860
const newDate = '2024-09-19';
883861
const newReason = 'This is the new reason';
884862

885-
// Updating all the input fields
886863
await page.$$eval(
887864
'.title-text-input',
888865
(inputFields, newTitle) => (inputFields[0].value = newTitle),

extension-requests/local-utils.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,8 @@ const parseExtensionRequestParams = (uri, nextPageParamsObject) => {
103103
return nextPageParamsObject;
104104
};
105105

106-
async function updateExtensionRequest({ id, body, isDev = false }) {
107-
const url = `${API_BASE_URL}/extension-requests/${id}${
108-
isDev ? `?dev=true` : ''
109-
}`;
106+
async function updateExtensionRequest({ id, body }) {
107+
const url = `${API_BASE_URL}/extension-requests/${id}`;
110108
const res = await fetch(url, {
111109
credentials: 'include',
112110
method: 'PATCH',
@@ -120,10 +118,8 @@ async function updateExtensionRequest({ id, body, isDev = false }) {
120118
}
121119
}
122120

123-
async function updateExtensionRequestStatus({ id, body, isDev = false }) {
124-
const url = `${API_BASE_URL}/extension-requests/${id}/status${
125-
isDev ? `?dev=true` : ''
126-
}`;
121+
async function updateExtensionRequestStatus({ id, body }) {
122+
const url = `${API_BASE_URL}/extension-requests/${id}/status`;
127123
const res = await fetch(url, {
128124
credentials: 'include',
129125
method: 'PATCH',
@@ -332,10 +328,8 @@ function addErrorElement(container) {
332328
container.appendChild(errorHeading);
333329
}
334330

335-
async function getExtensionRequestLogs({ extensionRequestId, isDev = false }) {
336-
const url = `${API_BASE_URL}/logs/extensionRequests/?meta.extensionRequestId=${extensionRequestId}${
337-
isDev ? `&dev=true` : ''
338-
}`;
331+
async function getExtensionRequestLogs({ extensionRequestId }) {
332+
const url = `${API_BASE_URL}/logs/extensionRequests/?meta.extensionRequestId=${extensionRequestId}`;
339333
const res = await fetch(url, {
340334
credentials: 'include',
341335
method: 'GET',

extension-requests/script.js

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,6 @@ async function createExtensionCard(data) {
868868
updateWrapper.classList.toggle('hidden');
869869
});
870870
cancelButton.addEventListener('click', (event) => {
871-
// Resetting input fields
872871
titleInput.value = data.title;
873872
reasonInput.value = data.reason;
874873
extensionInput.value = dateString(secondsToMilliSeconds(data.newEndsOn));
@@ -897,14 +896,11 @@ async function createExtensionCard(data) {
897896
};
898897
updateExtensionRequestStatus({
899898
id: data.id,
900-
isDev,
901899
body: { status: Status.APPROVED },
902900
})
903901
.then(async () => {
904902
removeSpinner();
905-
if (isDev) {
906-
appendLogs(payloadForLog, data.id);
907-
}
903+
appendLogs(payloadForLog, data.id);
908904
await removeCard(rootElement, 'green-card');
909905
})
910906
.catch(() => {
@@ -933,15 +929,12 @@ async function createExtensionCard(data) {
933929
};
934930
updateExtensionRequestStatus({
935931
id: data.id,
936-
isDev,
937932
body: { status: Status.DENIED },
938933
})
939934
.then(async () => {
940935
removeSpinner();
941936
await removeCard(rootElement, 'red-card');
942-
if (isDev) {
943-
appendLogs(payloadForLog, data.id);
944-
}
937+
appendLogs(payloadForLog, data.id);
945938
})
946939
.catch(() => {
947940
removeSpinner();
@@ -1038,34 +1031,28 @@ async function createExtensionCard(data) {
10381031
creationLog.appendChild(logText);
10391032
logContainer.appendChild(creationLog);
10401033
};
1041-
// Adding log feature under dev flag
1042-
if (isDev) {
1043-
// Div for log container
1044-
const logContainer = createElement({
1045-
type: 'div',
1046-
attributes: { id: `log-container-${data.id}` },
1047-
});
1048-
panel.appendChild(logContainer);
1034+
const logContainer = createElement({
1035+
type: 'div',
1036+
attributes: { id: `log-container-${data.id}` },
1037+
});
1038+
panel.appendChild(logContainer);
10491039

1050-
// Creating title for container
1051-
const logDetailsLine = createElement({
1052-
type: 'span',
1053-
attributes: { class: 'log-details-line' },
1054-
innerText: 'Logs',
1055-
});
1056-
logContainer.appendChild(logDetailsLine);
1040+
const logDetailsLine = createElement({
1041+
type: 'span',
1042+
attributes: { class: 'log-details-line' },
1043+
innerText: 'Logs',
1044+
});
1045+
logContainer.appendChild(logDetailsLine);
10571046

1058-
// Separation line
1059-
const logDetailsLines = createElement({
1060-
type: 'span',
1061-
attributes: { class: 'details-line' },
1062-
});
1063-
logContainer.appendChild(logDetailsLines);
1047+
const logDetailsLines = createElement({
1048+
type: 'span',
1049+
attributes: { class: 'details-line' },
1050+
});
1051+
logContainer.appendChild(logDetailsLines);
10641052

1065-
accordionContainer.addEventListener('click', function () {
1066-
renderLogs(data.id);
1067-
});
1068-
}
1053+
accordionContainer.addEventListener('click', function () {
1054+
renderLogs(data.id);
1055+
});
10691056
const cardFooter = createElement({ type: 'div' });
10701057
cardFooter.appendChild(cardAssigneeButtonContainer);
10711058
cardFooter.appendChild(accordionContainer);
@@ -1104,17 +1091,14 @@ async function createExtensionCard(data) {
11041091
};
11051092
updateExtensionRequest({
11061093
id: data.id,
1107-
isDev,
11081094
body: formData,
11091095
})
11101096
.then(() => {
11111097
data.reason = formData.reason;
11121098
data.tile = formData.title;
11131099
data.newEndsOn = data.newEndsOn;
11141100
handleSuccess(rootElement);
1115-
if (isDev) {
1116-
appendLogs(payloadForLog, data.id);
1117-
}
1101+
appendLogs(payloadForLog, data.id);
11181102
})
11191103
.catch(() => {
11201104
revertDataChange();
@@ -1181,7 +1165,6 @@ async function createExtensionCard(data) {
11811165
}
11821166
const extensionLogs = await getExtensionRequestLogs({
11831167
extensionRequestId,
1184-
isDev: true,
11851168
});
11861169
const innerHTML = generateSentence(
11871170
extensionLogs.logs,
@@ -1195,7 +1178,6 @@ async function createExtensionCard(data) {
11951178
tempDiv.classList.add('invisible-div');
11961179
tempDiv.innerHTML = innerHTML;
11971180

1198-
// Insert all the html before the first local-log
11991181
const localLogElement = logContainer.querySelector('.local-log');
12001182
logContainer.insertBefore(tempDiv, localLogElement);
12011183
} else {
@@ -1228,7 +1210,7 @@ async function createExtensionCard(data) {
12281210
}
12291211

12301212
removeSpinner();
1231-
if (isDev) renderExtensionCreatedLog();
1213+
renderExtensionCreatedLog();
12321214
rootElement.classList.remove('disabled');
12331215
});
12341216
return rootElement;
@@ -1238,7 +1220,6 @@ async function createExtensionCard(data) {
12381220
`log-container-${extensionRequestId}`,
12391221
);
12401222

1241-
// If logs has been previously rendered then only append logs
12421223
if (
12431224
payload?.body?.status &&
12441225
!logContainer.querySelector('.server-log')?.innerHTML

0 commit comments

Comments
 (0)