-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
694 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
Oops, something went wrong.