Skip to content

Commit

Permalink
ISPN-14966 Connected clients page
Browse files Browse the repository at this point in the history
  • Loading branch information
dpanshug committed Jul 7, 2023
1 parent 7c92e2f commit fb8e056
Show file tree
Hide file tree
Showing 10 changed files with 694 additions and 0 deletions.
140 changes: 140 additions & 0 deletions src/__tests__/services/connectedClientUtils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import { groupConnections } from '@app/utils/connectedClientUtils';

describe('groupConnections', () => {
it('groups connections based on specific properties', () => {
const connections: ConnectedClients[] = [
{
id: 70,
'server-node-name': 'infinispan-4-e2e',
name: 'flower',
created: '2023-05-18T14:54:37.882566188Z',
principal: 'admin',
'local-address': '/127.0.0.1:11222',
'remote-address': '/127.0.0.1:58230',
'protocol-version': 'RESP3',
'client-library': 'test',
'client-version': null,
'ssl-application-protocol': 'http/1.1',
'ssl-cipher-suite': 'TLS_AES_256_GCM_SHA384',
'ssl-protocol': 'TLSv1.3'
},
{
id: 71,
'server-node-name': 'infinispan-4-e2e',
name: 'car',
created: '2023-07-05T06:50:45.960705319Z',
principal: 'admin',
'local-address': '/127.0.0.1:11222',
'remote-address': '/127.0.0.1:58230',
'protocol-version': 'RESP3',
'client-library': 'test',
'client-version': null,
'ssl-application-protocol': 'http/1.1',
'ssl-cipher-suite': 'TLS_AES_256_GCM_SHA384',
'ssl-protocol': 'TLSv1.3'
},
{
id: 72,
'server-node-name': 'infinispan-4-e2e',
name: 'school',
created: '2023-07-05T10:00:54.472232620Z',
principal: 'observer',
'local-address': '/127.0.0.1:11222',
'remote-address': '/127.0.0.1:58230',
'protocol-version': 'RESP3',
'client-library': 'test',
'client-version': null,
'ssl-application-protocol': 'http/1.1',
'ssl-cipher-suite': 'TLS_AES_256_GCM_SHA384',
'ssl-protocol': 'TLSv1.3'
},
{
id: 73,
'server-node-name': 'infinispan-4-e2e',
name: 'office',
created: '2023-07-05T10:00:53.824309416Z',
principal: 'admin',
'local-address': '/127.0.0.1:11222',
'remote-address': '/127.0.0.1:58231',
'protocol-version': 'RESP3',
'client-library': 'test',
'client-version': null,
'ssl-application-protocol': 'http/1.1',
'ssl-cipher-suite': 'TLS_AES_256_GCM_SHA384',
'ssl-protocol': 'TLSv1.3'
},
{
id: 74,
'server-node-name': 'infinispan-4-e2e',
name: 'bike',
created: '2023-07-05T10:00:53.824533716Z',
principal: 'observer',
'local-address': '/127.0.0.1:11222',
'remote-address': '/127.0.0.1:58230',
'protocol-version': 'RESP3',
'client-library': 'test',
'client-version': null,
'ssl-application-protocol': 'http/1.1',
'ssl-cipher-suite': 'TLS_AES_256_GCM_SHA384',
'ssl-protocol': 'TLSv1.3'
}
];

// Expected output
const expectedGroupedConnections: ConnectedClients[] = [
{
id: 70,
'server-node-name': 'infinispan-4-e2e',
name: 'flower',
created: '2023-05-18T14:54:37.882566188Z',
principal: 'admin',
'local-address': '/127.0.0.1:11222',
'remote-address': '/127.0.0.1:58230',
'protocol-version': 'RESP3',
'client-library': 'test',
'client-version': null,
'ssl-application-protocol': 'http/1.1',
'ssl-cipher-suite': 'TLS_AES_256_GCM_SHA384',
'ssl-protocol': 'TLSv1.3',
count: 2
},
{
id: 72,
'server-node-name': 'infinispan-4-e2e',
name: 'school',
created: '2023-07-05T10:00:54.472232620Z',
principal: 'observer',
'local-address': '/127.0.0.1:11222',
'remote-address': '/127.0.0.1:58230',
'protocol-version': 'RESP3',
'client-library': 'test',
'client-version': null,
'ssl-application-protocol': 'http/1.1',
'ssl-cipher-suite': 'TLS_AES_256_GCM_SHA384',
'ssl-protocol': 'TLSv1.3',
count: 2
},
{
id: 73,
'server-node-name': 'infinispan-4-e2e',
name: 'office',
created: '2023-07-05T10:00:53.824309416Z',
principal: 'admin',
'local-address': '/127.0.0.1:11222',
'remote-address': '/127.0.0.1:58231',
'protocol-version': 'RESP3',
'client-library': 'test',
'client-version': null,
'ssl-application-protocol': 'http/1.1',
'ssl-cipher-suite': 'TLS_AES_256_GCM_SHA384',
'ssl-protocol': 'TLSv1.3',
count: 1
}
];

const result = groupConnections(connections);

// Assert the result
expect(result).toEqual(expectedGroupedConnections);
});
});
44 changes: 44 additions & 0 deletions src/__tests__/services/formatAge.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { formatAge } from '@app/utils/formatAge';

describe('formatAge', () => {
test('should return the formatted age in hours, minutes, and seconds', () => {
const currentTimestamp = new Date().getTime();

// Mock the current date to be 5 hours, 30 minutes, and 45 seconds ahead of the input date
const inputTimestamp = currentTimestamp - (5 * 60 * 60 * 1000 + 30 * 60 * 1000 + 45 * 1000);
const expectedOutput = '5 hr 30 min 45 s';

expect(formatAge(new Date(inputTimestamp).toISOString())).toEqual(expectedOutput);
});

test('should return only the formatted age in minutes and seconds', () => {
const currentTimestamp = new Date().getTime();

// Mock the current date to be 3 minutes and 20 seconds ahead of the input date
const inputTimestamp = currentTimestamp - (3 * 60 * 1000 + 20 * 1000);
const expectedOutput = '3 min 20 s';

expect(formatAge(new Date(inputTimestamp).toISOString())).toEqual(expectedOutput);
});

test('should return only the formatted age in seconds', () => {
const currentTimestamp = new Date().getTime();

// Mock the current date to be 15 seconds ahead of the input date
const inputTimestamp = currentTimestamp - 15 * 1000;
const expectedOutput = '15 s';

expect(formatAge(new Date(inputTimestamp).toISOString())).toEqual(expectedOutput);
});

test('should return an empty string for future dates', () => {
const currentTimestamp = new Date().getTime();

// Mock the input date to be 10 minutes ahead of the current date
const inputTimestamp = currentTimestamp + 10 * 60 * 1000;
console.log('inputTimestamp', inputTimestamp);
const expectedOutput = '';

expect(formatAge(new Date(inputTimestamp).toISOString())).toEqual(expectedOutput);
});
});
Loading

0 comments on commit fb8e056

Please sign in to comment.