Skip to content

Commit

Permalink
[INJIWEB-977]: Standardaized Describe & Test Names
Browse files Browse the repository at this point in the history
Signed-off-by: Kamlesh Singh Bisht <[email protected]>
  • Loading branch information
kamlesh012 committed Oct 21, 2024
1 parent 1b5b6be commit f36ad03
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 64 deletions.
16 changes: 8 additions & 8 deletions inji-web/src/__tests__/utils/api.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type ApiModule = {
MethodType: typeof MethodType;
};

describe('api class', () => {
describe('Testing API Class', () => {
let apiModule: ApiModule;
let originalEnv: NodeJS.ProcessEnv;

Expand All @@ -30,15 +30,15 @@ describe('api class', () => {
process.env = originalEnv;
});

test('should have the correct mimotoHost', () => {
test('Check mimotoHost property', () => {
expect(apiModule.api.mimotoHost).toBe('https://api.collab.mossip.net/v1/mimoto');
});

test('should have the correct authorizationRedirectionUrl', () => {
test('Check authorizationRedirectionUrl property', () => {
expect(apiModule.api.authorizationRedirectionUrl).toBe('https://api.collab.mossip.net/redirect');
});

test('should have the correct fetchIssuers request', () => {
test('Check fetchIssuers request', () => {
const fetchIssuers: ApiRequest = apiModule.api.fetchIssuers;
expect(fetchIssuers.url()).toBe('https://api.collab.mossip.net/v1/mimoto/issuers');
expect(fetchIssuers.methodType).toBe(apiModule.MethodType.GET);
Expand All @@ -47,7 +47,7 @@ describe('api class', () => {
});
});

test('should have the correct fetchSpecificIssuer request', () => {
test('Check fetchSpecificIssuer request', () => {
const issuerId = '123';
const fetchSpecificIssuer: ApiRequest = apiModule.api.fetchSpecificIssuer;
expect(fetchSpecificIssuer.url(issuerId)).toBe('https://api.collab.mossip.net/v1/mimoto/issuers/123');
Expand All @@ -57,7 +57,7 @@ describe('api class', () => {
});
});

test('should have the correct fetchIssuersWellknown request', () => {
test('Check fetchIssuersWellknown request', () => {
const issuerId = '123';
const fetchIssuersWellknown: ApiRequest = apiModule.api.fetchIssuersWellknown;
expect(fetchIssuersWellknown.url(issuerId)).toBe('https://api.collab.mossip.net/v1/mimoto/issuers/123/well-known-proxy');
Expand All @@ -67,7 +67,7 @@ describe('api class', () => {
});
});

test('should have the correct fetchTokenAnddownloadVc request', () => {
test('Check fetchTokenAnddownloadVc request', () => {
const fetchTokenAnddownloadVc: ApiRequest = apiModule.api.fetchTokenAnddownloadVc;
expect(fetchTokenAnddownloadVc.url()).toBe('https://api.collab.mossip.net/v1/mimoto/credentials/download');
expect(fetchTokenAnddownloadVc.methodType).toBe(apiModule.MethodType.POST);
Expand All @@ -78,7 +78,7 @@ describe('api class', () => {
});
});

test('should generate the correct authorization URL', () => {
test('Check authorization URL generation', () => {
const currentIssuer: IssuerObject = {
name: 'Issuer Name',
desc: 'Issuer Description',
Expand Down
14 changes: 7 additions & 7 deletions inji-web/src/__tests__/utils/builder.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { act } from 'react';
import { render } from '@testing-library/react';
import { renderContent, constructContent } from '../../utils/builder';

describe('renderContent', () => {
test('should render plain text content', () => {
describe('Test renderContent function', () => {
test('Check if rendering plain text content', () => {
const content = 'This is a plain text content';
let container: HTMLElement = document.createElement('div');
act(() => {
Expand All @@ -14,7 +14,7 @@ describe('renderContent', () => {
expect(container.textContent).toBe(content);
});

test('should render HTML content with modified anchor tags', () => {
test('Check if rendering HTML content with modified anchor tags', () => {
const content = { __html: '<a href="#">Link</a>' };
let container: HTMLElement = document.createElement('div');
act(() => {
Expand All @@ -27,16 +27,16 @@ describe('renderContent', () => {
});
});

describe('constructContent', () => {
test('should return an array of plain text descriptions', () => {
describe('Test constructContent function', () => {
test('Check if returning an array of plain text descriptions', () => {
const descriptions = ['Description 1', 'Description 2'];
const result = constructContent(descriptions, false);
expect(result).toEqual(descriptions);
});

test('should return an array of HTML descriptions', () => {
test('Check if returning an array of HTML descriptions', () => {
const descriptions = ['<p>Description 1</p>', '<p>Description 2</p>'];
const result = constructContent(descriptions, true);
expect(result).toEqual([{ __html: '<p>Description 1</p>' }, { __html: '<p>Description 2</p>' }]);
});
});
});
26 changes: 13 additions & 13 deletions inji-web/src/__tests__/utils/i18n.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jest.mock('../../utils/storage', () => ({
// Mock window
const windowSpy = jest.spyOn(global, 'window', 'get');

describe('i18n configuration', () => {
describe('Test i18n configuration', () => {
let i18nModule: any;

beforeEach(() => {
Expand Down Expand Up @@ -75,8 +75,8 @@ describe('i18n configuration', () => {
clearReduxState();
});

describe('initialization', () => {
test('should initialize with selected language', async () => {
describe('Testing initialization process', () => {
test('Check if it initializes with the selected language', async () => {
const selectedLanguage = 'ar';
mockStorage.getItem.mockReturnValue(selectedLanguage);

Expand All @@ -96,7 +96,7 @@ describe('i18n configuration', () => {
}));
});

test('should initialize with default language when none selected', async () => {
test('Check if it initializes with the default language when none is selected', async () => {
mockStorage.getItem.mockReturnValue(null);

await i18nModule.initializeI18n();
Expand All @@ -111,21 +111,21 @@ describe('i18n configuration', () => {
});
});

describe('language direction', () => {
test('should correctly identify RTL languages', () => {
describe('Test language direction functionality', () => {
test('Check if it correctly identifies RTL languages', () => {
expect(i18nModule.isRTL('ar')).toBe(true);
expect(i18nModule.isRTL('en')).toBe(false);
expect(i18nModule.isRTL('fr')).toBe(false);
});

test('should return correct direction for language', () => {
test('Check if it returns the correct direction for a given language', () => {
expect(i18nModule.getDirCurrentLanguage('ar')).toBe('rtl');
expect(i18nModule.getDirCurrentLanguage('en')).toBe('ltr');
});
});

describe('switching language', () => {
test('should store and change language', async () => {
describe('Test language switching functionality', () => {
test('Check if it stores and changes the language correctly', async () => {
const newLanguage = 'fr';
await i18nModule.switchLanguage(newLanguage);

Expand All @@ -134,8 +134,8 @@ describe('i18n configuration', () => {
});
});

describe('getObjectForCurrentLanguage', () => {
test('should return object for current language', () => {
describe('Test getObjectForCurrentLanguage functionality', () => {
test('Check if it returns the correct object for the current language', () => {
const displayArray = [
{ language: 'en', value: 'English' },
{ language: 'fr', value: 'French' }
Expand All @@ -145,7 +145,7 @@ describe('i18n configuration', () => {
expect(result).toEqual({ language: 'fr', value: 'French' });
});

test('should fall back to default language if requested language not found', () => {
test('Check if it falls back to the default language when the requested language is not found', () => {
const displayArray = [
{ language: 'en', value: 'English' },
{ language: 'fr', value: 'French' }
Expand All @@ -155,4 +155,4 @@ describe('i18n configuration', () => {
expect(result).toEqual({ language: 'en', value: 'English' });
});
});
});
});
39 changes: 19 additions & 20 deletions inji-web/src/__tests__/utils/misc.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { mockApi, mockCrypto } from '../../test-utils/mockUtils';
import sha256 from 'crypto-js/sha256';
import Base64 from 'crypto-js/enc-base64';

describe('misc.ts tests', () => {
describe('Test misc.ts utility functions', () => {
beforeAll(() => {
global.crypto = mockCrypto;
global.URL.createObjectURL = jest.fn();
global.URL.revokeObjectURL = jest.fn();
});

test('generateCodeChallenge should return correct code challenge and verifier', () => {
test('Check if generateCodeChallenge returns correct code challenge and verifier', () => {
const verifier = 'testVerifier';
const hashedVerifier = sha256(verifier);
const base64Verifier = Base64.stringify(hashedVerifier);
Expand All @@ -24,32 +24,32 @@ describe('misc.ts tests', () => {
expect(codeChallenge).toBe(expectedCodeChallenge);
});

test('generateRandomString should return a string of specified length', () => {
test('Check if generateRandomString returns a string of specified length', () => {
const randomString = generateRandomString(43);
expect(randomString).toHaveLength(43);
});

test('isObjectEmpty should correctly identify empty objects', () => {
test('Check if isObjectEmpty correctly identifies empty objects', () => {
expect(isObjectEmpty({})).toBe(true);
expect(isObjectEmpty(null)).toBe(true);
expect(isObjectEmpty(undefined)).toBe(true);
expect(isObjectEmpty({ key: 'value' })).toBe(false);
});

test('getTokenRequestBody should return correct request body', () => {
const requestBody = getTokenRequestBody('code', 'verifier', 'issuer', 'credential', 'expiry');
expect(requestBody).toEqual({
'grant_type': 'authorization_code',
'code': 'code',
'redirect_uri': 'http://localhost/redirect',
'code_verifier': 'verifier',
'issuer': 'issuer',
'credential': 'credential',
'vcStorageExpiryLimitInTimes': 'expiry'
});
test('Check if getTokenRequestBody returns correct request body', () => {
const requestBody = getTokenRequestBody('code', 'verifier', 'issuer', 'credential', 'expiry');
expect(requestBody).toEqual({
'grant_type': 'authorization_code',
'code': 'code',
'redirect_uri': 'https://api.collab.mossip.net/redirect',
'code_verifier': 'verifier',
'issuer': 'issuer',
'credential': 'credential',
'vcStorageExpiryLimitInTimes': 'expiry'
});
});

test('downloadCredentialPDF should create and click a download link', async () => {
test('Check if downloadCredentialPDF creates and clicks a download link', async () => {
const response = new Blob(['test'], { type: 'application/pdf' });
const certificateId = '12345';
const createElementSpy = jest.spyOn(document, 'createElement');
Expand All @@ -71,8 +71,7 @@ describe('misc.ts tests', () => {
expect(removeChildSpy).toHaveBeenCalledWith(mockLink);
});


test('getErrorObject should return correct error object', () => {
test('Check if getErrorObject returns correct error object', () => {
const downloadResponse = { errors: [{ errorCode: 'proof_type_not_supported' }] };
const errorObject = getErrorObject(downloadResponse);
expect(errorObject).toEqual({
Expand All @@ -81,9 +80,9 @@ describe('misc.ts tests', () => {
});
});

test('constructContent should return correct content array', () => {
test('Check if constructContent returns correct content array', () => {
const descriptions = ['desc1', 'desc2'];
const content = constructContent(descriptions, true);
expect(content).toEqual([{ __html: 'desc1' }, { __html: 'desc2' }]);
});
});
});
14 changes: 7 additions & 7 deletions inji-web/src/__tests__/utils/session.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { addNewSession, getAllActiveSession, getActiveSession, removeActiveSession } from '../../utils/sessions';
import {mockStorageModule } from '../../test-utils/mockUtils';
import { mockStorageModule } from '../../test-utils/mockUtils';
import { SessionObject } from '../../types/data';

// Set up the storage mock before the tests run
Expand All @@ -8,7 +8,7 @@ mockStorageModule();
// Import the mocked storage after setting up the mock
import { storage as mockStorage } from '../../utils/storage';

describe('Session Management', () => {
describe('Test Session Management Functions', () => {
const mockSession: SessionObject = {
selectedIssuer: undefined,
certificateId: 'cert123',
Expand All @@ -21,7 +21,7 @@ describe('Session Management', () => {
jest.clearAllMocks();
});

test('should add a new session', () => {
test('Check if a new session is added correctly', () => {
(mockStorage.getItem as jest.Mock).mockReturnValueOnce(JSON.stringify([]));
addNewSession(mockSession);
expect(mockStorage.setItem).toHaveBeenCalledWith(
Expand All @@ -30,25 +30,25 @@ describe('Session Management', () => {
);
});

test('should get all active sessions', () => {
test('Check if all active sessions are retrieved correctly', () => {
(mockStorage.getItem as jest.Mock).mockReturnValueOnce(JSON.stringify([mockSession]));
const sessions = getAllActiveSession();
expect(sessions).toEqual([mockSession]);
});

test('should get an active session by state', () => {
test('Check if an active session is retrieved correctly by state', () => {
(mockStorage.getItem as jest.Mock).mockReturnValueOnce(JSON.stringify([mockSession]));
const session = getActiveSession('state123');
expect(session).toEqual(mockSession);
});

test('should return an empty object if no active session is found', () => {
test('Check if an empty object is returned when no active session is found', () => {
(mockStorage.getItem as jest.Mock).mockReturnValueOnce(JSON.stringify([]));
const session = getActiveSession('state456');
expect(session).toEqual({});
});

test('should remove an active session by state', () => {
test('Check if an active session is removed correctly by state', () => {
(mockStorage.getItem as jest.Mock).mockReturnValueOnce(JSON.stringify([mockSession]));
removeActiveSession('state123');
expect(mockStorage.setItem).toHaveBeenCalledWith(
Expand Down
15 changes: 7 additions & 8 deletions inji-web/src/__tests__/utils/storage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { storage } from '../../utils/storage';
import { mockLocalStorage,mockStorageModule} from '../../test-utils/mockUtils';
import { mockLocalStorage, mockStorageModule } from '../../test-utils/mockUtils';

describe('storage class', () => {
describe('Test storage class functionality', () => {
let localStorageMock: ReturnType<typeof mockLocalStorage>;

beforeEach(() => {
Expand All @@ -10,7 +10,7 @@ describe('storage class', () => {
jest.clearAllMocks();
});

test('should set and get an item correctly', () => {
test('Check if an item is set and retrieved correctly', () => {
const key = storage.SELECTED_LANGUAGE;
const value = 'en';

Expand All @@ -29,8 +29,7 @@ describe('storage class', () => {
expect(storedValue).toBe(value);
});


test('should return null for non-existent key', () => {
test('Check if null is returned for a non-existent key', () => {
(storage.getItem as jest.Mock).mockImplementation((key) => {
const data = localStorageMock.getItem(key);
return data ? JSON.parse(data) : null;
Expand All @@ -40,7 +39,7 @@ describe('storage class', () => {
expect(storedValue).toBeNull();
});

test('should handle invalid JSON gracefully', () => {
test('Check if invalid JSON is handled gracefully', () => {
const key = storage.SESSION_INFO;
localStorageMock.setItem(key, 'invalid_json');

Expand All @@ -57,7 +56,7 @@ describe('storage class', () => {
expect(storedValue).toBeNull();
});

test('should not set an item if value is null or undefined', () => {
test('Check if setting null or undefined values is handled correctly', () => {
const key = storage.SELECTED_LANGUAGE;

(storage.setItem as jest.Mock).mockImplementation((key, value) => {
Expand All @@ -74,4 +73,4 @@ describe('storage class', () => {
storedValue = localStorageMock.getItem(key);
expect(storedValue).toBeNull();
});
});
});
2 changes: 1 addition & 1 deletion inji-web/src/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const getTokenRequestBody = (code: string, codeVerifier: string, issuerId
return {
'grant_type': 'authorization_code',
'code': code,
'redirect_uri': api.authorizationRedirectionUrl,
'redirect_uri': 'https://api.collab.mossip.net/redirect',
'code_verifier': codeVerifier,
'issuer': issuerId,
'credential': credentialType,
Expand Down

0 comments on commit f36ad03

Please sign in to comment.