Fix: cypress tests invalid token issue (#15581)

This commit is contained in:
Sachin Chaurasiya 2024-03-15 17:34:31 +05:30 committed by GitHub
parent cadca31b1c
commit b86a8438c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 111 additions and 95 deletions

View File

@ -13,6 +13,7 @@
import { interceptURL, verifyResponseStatusCode } from '../../common/common'; import { interceptURL, verifyResponseStatusCode } from '../../common/common';
import { searchServiceFromSettingPage } from '../../common/serviceUtils'; import { searchServiceFromSettingPage } from '../../common/serviceUtils';
import { getToken } from '../../common/Utils/LocalStorage';
import { GlobalSettingOptions } from '../../constants/settings.constant'; import { GlobalSettingOptions } from '../../constants/settings.constant';
const schemaNames = ['sales', 'admin', 'anonymous', 'dip', 'gsmadmin_internal']; const schemaNames = ['sales', 'admin', 'anonymous', 'dip', 'gsmadmin_internal'];
@ -25,7 +26,8 @@ describe('Schema search', { tags: 'DataAssets' }, () => {
}); });
it('Prerequisite', () => { it('Prerequisite', () => {
const token = localStorage.getItem('oidcIdToken'); cy.getAllLocalStorage().then((data) => {
const token = getToken(data);
cy.request({ cy.request({
method: 'POST', method: 'POST',
url: `/api/v1/services/databaseServices`, url: `/api/v1/services/databaseServices`,
@ -77,6 +79,7 @@ describe('Schema search', { tags: 'DataAssets' }, () => {
}); });
}); });
}); });
});
it('Search schema in database page', () => { it('Search schema in database page', () => {
// Click on settings page // Click on settings page
@ -131,8 +134,8 @@ describe('Schema search', { tags: 'DataAssets' }, () => {
}); });
it('Cleanup', () => { it('Cleanup', () => {
const token = localStorage.getItem('oidcIdToken'); cy.getAllLocalStorage().then((data) => {
const token = getToken(data);
cy.request({ cy.request({
method: 'DELETE', method: 'DELETE',
url: `/api/v1/services/databaseServices/${serviceId}?hardDelete=true&recursive=true`, url: `/api/v1/services/databaseServices/${serviceId}?hardDelete=true&recursive=true`,
@ -141,4 +144,5 @@ describe('Schema search', { tags: 'DataAssets' }, () => {
expect(response.status).to.eq(200); expect(response.status).to.eq(200);
}); });
}); });
});
}); });

View File

@ -85,7 +85,8 @@ describe('Customize Landing Page Flow', { tags: 'Settings' }, () => {
after(() => { after(() => {
cy.login(); cy.login();
const token = localStorage.getItem('oidcIdToken'); cy.getAllLocalStorage().then((data) => {
const token = getToken(data);
// Delete created user // Delete created user
cy.request({ cy.request({
@ -101,6 +102,7 @@ describe('Customize Landing Page Flow', { tags: 'Settings' }, () => {
headers: { Authorization: `Bearer ${token}` }, headers: { Authorization: `Bearer ${token}` },
}); });
}); });
});
beforeEach(() => { beforeEach(() => {
cy.login(); cy.login();

View File

@ -13,6 +13,7 @@
import { interceptURL, verifyResponseStatusCode } from '../../common/common'; import { interceptURL, verifyResponseStatusCode } from '../../common/common';
import { visitClassificationPage } from '../../common/TagUtils'; import { visitClassificationPage } from '../../common/TagUtils';
import { getToken } from '../../common/Utils/LocalStorage';
import { import {
NEW_CLASSIFICATION_FOR_VERSION_TEST, NEW_CLASSIFICATION_FOR_VERSION_TEST,
NEW_CLASSIFICATION_PATCH_PAYLOAD, NEW_CLASSIFICATION_PATCH_PAYLOAD,
@ -45,7 +46,8 @@ describe(
}); });
it('Prerequisites for classification version page tests', () => { it('Prerequisites for classification version page tests', () => {
const token = localStorage.getItem('oidcIdToken'); cy.getAllLocalStorage().then((data) => {
const token = getToken(data);
cy.request({ cy.request({
method: 'PUT', method: 'PUT',
@ -70,6 +72,7 @@ describe(
}); });
}); });
}); });
});
it('Classification version page should display all the changes properly', () => { it('Classification version page should display all the changes properly', () => {
cy.get('[data-testid="data-summary-container"]') cy.get('[data-testid="data-summary-container"]')

View File

@ -22,6 +22,7 @@ import {
verifyResponseStatusCode, verifyResponseStatusCode,
} from '../../common/common'; } from '../../common/common';
import { verifyKpiChart } from '../../common/DataInsightUtils'; import { verifyKpiChart } from '../../common/DataInsightUtils';
import { getToken } from '../../common/Utils/LocalStorage';
import { SidebarItem } from '../../constants/Entity.interface'; import { SidebarItem } from '../../constants/Entity.interface';
import { GlobalSettingOptions } from '../../constants/settings.constant'; import { GlobalSettingOptions } from '../../constants/settings.constant';
@ -43,7 +44,9 @@ const deleteKpiRequest = () => {
cy.wait('@getKpi').then(({ response }) => { cy.wait('@getKpi').then(({ response }) => {
const data = response.body.data; const data = response.body.data;
if (data.length > 0) { if (data.length > 0) {
const token = localStorage.getItem('oidcIdToken'); cy.getAllLocalStorage().then((storageData) => {
const token = getToken(storageData);
data.forEach((element) => { data.forEach((element) => {
cy.request({ cy.request({
method: 'DELETE', method: 'DELETE',
@ -53,6 +56,7 @@ const deleteKpiRequest = () => {
expect(response.status).to.eq(200); expect(response.status).to.eq(200);
}); });
}); });
});
cy.reload(); cy.reload();
} }
}); });

View File

@ -24,6 +24,7 @@ import { deleteGlossary } from '../../common/GlossaryUtils';
import { dragAndDropElement } from '../../common/Utils/DragAndDrop'; import { dragAndDropElement } from '../../common/Utils/DragAndDrop';
import { visitEntityDetailsPage } from '../../common/Utils/Entity'; import { visitEntityDetailsPage } from '../../common/Utils/Entity';
import { confirmationDragAndDropGlossary } from '../../common/Utils/Glossary'; import { confirmationDragAndDropGlossary } from '../../common/Utils/Glossary';
import { getToken } from '../../common/Utils/LocalStorage';
import { addOwner, removeOwner } from '../../common/Utils/Owner'; import { addOwner, removeOwner } from '../../common/Utils/Owner';
import { import {
COLUMN_NAME_FOR_APPLY_GLOSSARY_TERM, COLUMN_NAME_FOR_APPLY_GLOSSARY_TERM,
@ -684,7 +685,8 @@ const checkSummaryListItemSorting = ({ termFQN, columnName }) => {
}; };
const deleteUser = () => { const deleteUser = () => {
const token = localStorage.getItem('oidcIdToken'); cy.getAllLocalStorage().then((storageData) => {
const token = getToken(storageData);
cy.request({ cy.request({
method: 'DELETE', method: 'DELETE',
@ -693,6 +695,7 @@ const deleteUser = () => {
}).then((response) => { }).then((response) => {
expect(response.status).to.eq(200); expect(response.status).to.eq(200);
}); });
});
}; };
describe('Glossary page should work properly', { tags: 'Glossary' }, () => { describe('Glossary page should work properly', { tags: 'Glossary' }, () => {