Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions redisinsight/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"resolutions": {
"nanoid": "^3.1.31",
"word-wrap": "1.2.4",
"jest/**/micromatch": "^4.0.8",
"ts-loader/micromatch": "^4.0.8",
"mocha/minimatch": "^3.0.5",
"@nestjs/platform-socket.io/socket.io": "^4.8.0",
"**/semver": "^7.5.2",
Expand Down Expand Up @@ -120,7 +122,7 @@
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-sonarjs": "^0.9.1",
"ioredis-mock": "^8.2.2",
"jest": "^26.6.3",
"jest": "^29.7.0",
"jest-when": "^3.2.1",
"joi": "^17.4.0",
"mocha": "^8.4.0",
Expand All @@ -132,7 +134,7 @@
"rimraf": "^3.0.2",
"socket.io-mock": "^1.3.2",
"supertest": "^4.0.2",
"ts-jest": "^26.1.0",
"ts-jest": "^29.2.5",
"ts-loader": "^6.2.1",
"ts-mocha": "^8.0.0",
"ts-node": "^9.1.1",
Expand Down Expand Up @@ -164,8 +166,7 @@
"moduleNameMapper": {
"src/(.*)": "<rootDir>/$1",
"apiSrc/(.*)": "<rootDir>/$1",
"tests/(.*)": "<rootDir>/__tests__/$1",
"axios": "axios/dist/node/axios.cjs"
"tests/(.*)": "<rootDir>/__tests__/$1"
}
}
}
2 changes: 1 addition & 1 deletion redisinsight/api/src/__mocks__/bulk-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const mockCombinedStream = {

export const mockBulkActionOverviewMatcher = {
...mockBulkActionOverview,
duration: jasmine.any(Number),
duration: expect.any(Number),
};

export const mockBulkActionFilter = new BulkActionFilter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('AiQueryService', () => {
clientSocket.disconnect();
serverSocket.disconnect();
wsServer.close();
httpServer.stop();
httpServer?.stop?.();
});

beforeEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ describe('LocalAiQueryAuthProvider', () => {

encryptionService.decrypt.mockImplementation((value) => value);
when(encryptionService.decrypt)
.calledWith(mockAiQueryHumanMessageEntity.content, jasmine.anything())
.calledWith(mockAiQueryHumanMessageEntity.content, expect.anything())
.mockResolvedValue(mockAiQueryHumanMessage.content)
.calledWith(mockAiQueryAiResponseEntity.content, jasmine.anything())
.calledWith(mockAiQueryAiResponseEntity.content, expect.anything())
.mockResolvedValue(mockAiQueryAiResponse.content)
.calledWith(mockAiQueryAiResponseEntity.steps, jasmine.anything())
.calledWith(mockAiQueryAiResponseEntity.steps, expect.anything())
.mockResolvedValue(JSON.stringify(mockAiQueryAiResponse.steps));

encryptionService.encrypt.mockImplementation((value) => value);
when(encryptionService.encrypt)
.calledWith(mockAiQueryHumanMessage.content, jasmine.anything())
.calledWith(mockAiQueryHumanMessage.content, expect.anything())
.mockResolvedValue(mockAiQueryHumanMessageEntity.content)
.calledWith(mockAiQueryAiResponse.content, jasmine.anything())
.calledWith(mockAiQueryAiResponse.content, expect.anything())
.mockResolvedValue(mockAiQueryAiResponseEntity.content)
.calledWith(JSON.stringify(mockAiQueryAiResponse.steps), jasmine.anything())
.calledWith(JSON.stringify(mockAiQueryAiResponse.steps), expect.anything())
.mockResolvedValue(mockAiQueryAiResponseEntity.steps);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
import { SettingsService } from 'src/modules/settings/settings.service';
import { AutodiscoveryService } from 'src/modules/autodiscovery/autodiscovery.service';
import { DatabaseService } from 'src/modules/database/database.service';
import { mocked } from 'ts-jest/utils';
import config, { Config } from 'src/utils/config';
import { RedisClientFactory } from 'src/modules/redis/redis.client.factory';
import { ConstantsProvider } from 'src/modules/constants/providers/constants.provider';
Expand Down Expand Up @@ -84,7 +83,7 @@ describe('AutodiscoveryService', () => {
databaseService = module.get(DatabaseService);
redisClientFactory = module.get(RedisClientFactory);

mocked(utils.convertRedisInfoReplyToObject).mockReturnValue({
(utils.convertRedisInfoReplyToObject as jest.Mock).mockReturnValue({
server: {
redis_mode: 'standalone',
},
Expand Down Expand Up @@ -155,7 +154,7 @@ describe('AutodiscoveryService', () => {
let addRedisDatabaseSpy;

beforeEach(async () => {
mocked(getAvailableEndpoints).mockResolvedValue([]);
(getAvailableEndpoints as jest.Mock).mockResolvedValue([]);
addRedisDatabaseSpy = jest.spyOn(service as any, 'addRedisDatabase');
addRedisDatabaseSpy.mockResolvedValue(null);
});
Expand All @@ -167,7 +166,8 @@ describe('AutodiscoveryService', () => {
});

it('should should call addRedisDatabase 2 times', async () => {
mocked(getAvailableEndpoints).mockResolvedValueOnce([mockAutodiscoveryEndpoint, mockAutodiscoveryEndpoint]);
(getAvailableEndpoints as jest.Mock)
.mockResolvedValueOnce([mockAutodiscoveryEndpoint, mockAutodiscoveryEndpoint]);
await service['discoverDatabases'](mockSessionMetadata);

expect(addRedisDatabaseSpy).toHaveBeenCalledTimes(2);
Expand All @@ -193,7 +193,7 @@ describe('AutodiscoveryService', () => {
});

it('should not create database if redis_mode is not standalone', async () => {
mocked(utils.convertRedisInfoReplyToObject).mockReturnValueOnce({
(utils.convertRedisInfoReplyToObject as jest.Mock).mockReturnValueOnce({
server: {
redis_mode: 'cluster',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
import * as os from 'os';
import * as ch from 'child_process';
import * as net from 'net';
import { mocked } from 'ts-jest/utils';
import * as events from 'events';
import * as stream from 'stream';
import { ChildProcess } from 'child_process';
Expand Down Expand Up @@ -39,17 +38,17 @@ describe('getSpawnArgs', () => {
const getSpawnArgsTests = [
{
name: 'Linux',
before: () => mocked(os.type).mockReturnValue('Linux'),
before: () => (os.type as jest.Mock).mockReturnValue('Linux'),
output: ['netstat', ['-anpt']],
},
{
name: 'Darwin',
before: () => mocked(os.type).mockReturnValue('Darwin'),
before: () => (os.type as jest.Mock).mockReturnValue('Darwin'),
output: ['netstat', ['-anvp', 'tcp']],
},
{
name: 'Windows_NT',
before: () => mocked(os.type).mockReturnValue('Windows_NT'),
before: () => (os.type as jest.Mock).mockReturnValue('Windows_NT'),
output: ['netstat.exe', ['-a', '-n', '-o']],
},
];
Expand All @@ -67,8 +66,8 @@ describe('getSpawnArgs', () => {

describe('getRunningProcesses', () => {
beforeEach(() => {
mocked(os.type).mockReturnValue('Linux');
mocked(ch.spawn).mockReturnValue(mockChildProcess);
(os.type as jest.Mock).mockReturnValue('Linux');
(ch.spawn as jest.Mock).mockReturnValue(mockChildProcess);
});
const getRunningProcessesTests = [
{
Expand All @@ -94,7 +93,7 @@ describe('getRunningProcesses', () => {
});

it('Should throw an error for unsupported platform', async () => {
mocked(os.type).mockReturnValueOnce('custom_os');
(os.type as jest.Mock).mockReturnValueOnce('custom_os');

try {
await autodiscoveryUtility.getRunningProcesses();
Expand Down Expand Up @@ -172,7 +171,7 @@ describe('getTCPEndpoints', () => {

describe('testEndpoint', () => {
beforeEach(() => {
mocked(net.createConnection).mockReturnValue(mockSocket);
(net.createConnection as jest.Mock).mockReturnValue(mockSocket);
});
const testEndpointTests = [
{
Expand Down Expand Up @@ -224,7 +223,7 @@ describe('getAvailableEndpoints', () => {
beforeEach(() => {
const getRunningProcessesSpy = jest.spyOn(autodiscoveryUtility, 'getRunningProcesses');
getRunningProcessesSpy.mockResolvedValue(['']);
mocked(net.createConnection).mockReturnValue(mockSocket);
(net.createConnection as jest.Mock).mockReturnValue(mockSocket);
});
const getAvailableEndpointsTests = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -776,16 +776,16 @@ describe('Cluster Scanner Strategy', () => {
beforeEach(() => {
when(mockClusterRedisClient.sendPipeline)
.calledWith([
jasmine.arrayContaining([BrowserToolKeysCommands.Ttl]),
jasmine.arrayContaining(['memory', 'usage']),
jasmine.arrayContaining([BrowserToolKeysCommands.Type]),
expect.arrayContaining([BrowserToolKeysCommands.Ttl]),
expect.arrayContaining(['memory', 'usage']),
expect.arrayContaining([BrowserToolKeysCommands.Type]),
],
{ replyEncoding: 'utf8' })
.mockResolvedValue([[null, -1], [null, 50], [null, 'string']]);
when(mockClusterRedisClient.sendPipeline)
.calledWith([
jasmine.arrayContaining([BrowserToolKeysCommands.Ttl]),
jasmine.arrayContaining(['memory', 'usage']),
expect.arrayContaining([BrowserToolKeysCommands.Ttl]),
expect.arrayContaining(['memory', 'usage']),
],
{ replyEncoding: 'utf8' })
.mockResolvedValue([[null, 999], [null, 555]]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ describe('BulkImportService', () => {
spy.mockResolvedValue(mockSummary);
expect(await service.import(mockClientMetadata, mockReadableStream)).toEqual({
...mockImportResult,
duration: jasmine.anything(),
duration: expect.anything(),
});
expect(analytics.sendActionSucceed).toHaveBeenCalledWith({
...mockImportResult,
duration: jasmine.anything(),
duration: expect.anything(),
});
});

Expand All @@ -185,7 +185,7 @@ describe('BulkImportService', () => {
failed: 0,
errors: [],
},
duration: jasmine.anything(),
duration: expect.anything(),
});
});

Expand All @@ -204,7 +204,7 @@ describe('BulkImportService', () => {
failed: 0,
errors: [],
},
duration: jasmine.anything(),
duration: expect.anything(),
});
});

Expand All @@ -225,7 +225,7 @@ describe('BulkImportService', () => {
failed: 2,
errors: [],
},
duration: jasmine.anything(),
duration: expect.anything(),
});
expect(mockStandaloneRedisClient.disconnect).toHaveBeenCalled();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('LocalCaCertificateRepository', () => {
repository.save.mockResolvedValue(mockCaCertificateEntity);
repository.create.mockReturnValue(mockCaCertificate); // not entity since it happens before encryption

when(encryptionService.decrypt).calledWith(mockCaCertificateCertificateEncrypted, jasmine.anything())
when(encryptionService.decrypt).calledWith(mockCaCertificateCertificateEncrypted, expect.anything())
.mockResolvedValue(mockCaCertificateCertificatePlain);
when(encryptionService.encrypt).calledWith(mockCaCertificateCertificatePlain)
.mockResolvedValue({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ describe('LocalClientCertificateRepository', () => {
repository.create.mockReturnValue(mockClientCertificate); // not an entity since create happens before encryption

when(encryptionService.decrypt)
.calledWith(mockClientCertificateCertificateEncrypted, jasmine.anything())
.calledWith(mockClientCertificateCertificateEncrypted, expect.anything())
.mockResolvedValue(mockClientCertificateCertificatePlain)
.calledWith(mockClientCertificateKeyEncrypted, jasmine.anything())
.calledWith(mockClientCertificateKeyEncrypted, expect.anything())
.mockResolvedValue(mockClientCertificateKeyPlain);
when(encryptionService.encrypt)
.calledWith(mockClientCertificateCertificatePlain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ describe('LocalCloudCapiKeyRepository', () => {
repository.merge.mockReturnValue(mockFeatureEntity);

when(encryptionService.decrypt)
.calledWith(mockCapiKeyEncrypted, jasmine.anything())
.calledWith(mockCapiKeyEncrypted, expect.anything())
.mockResolvedValue(mockCloudCapiAuthDto.capiKey)
.calledWith(mockCapiSecretEncrypted, jasmine.anything())
.calledWith(mockCapiSecretEncrypted, expect.anything())
.mockResolvedValue(mockCloudCapiAuthDto.capiSecret);

when(encryptionService.encrypt)
Expand All @@ -80,7 +80,7 @@ describe('LocalCloudCapiKeyRepository', () => {
});
it('should return null fields in case of decryption errors', async () => {
when(encryptionService.decrypt)
.calledWith(mockCapiKeyEncrypted, jasmine.anything())
.calledWith(mockCapiKeyEncrypted, expect.anything())
.mockRejectedValueOnce(new KeytarDecryptionErrorException());

expect(await service.get(mockDatabase.id)).toEqual({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('LocalCustomTutorialRepository', () => {
expect(result).toEqual(mockCustomTutorial);
expect(repository.save).toHaveBeenCalledWith({
...mockCustomTutorialEntity,
createdAt: jasmine.anything(),
createdAt: expect.anything(),
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('AbstractInfoStrategy', () => {

beforeEach(async () => {
when(client.sendCommand)
.calledWith(jasmine.arrayContaining(['hlen']))
.calledWith(expect.arrayContaining(['hlen']))
.mockResolvedValue(mockRedisResponse);
});

Expand All @@ -21,7 +21,7 @@ describe('AbstractInfoStrategy', () => {
});
it('should return null in case of error', async () => {
when(client.sendCommand)
.calledWith(jasmine.arrayContaining(['hlen']))
.calledWith(expect.arrayContaining(['hlen']))
.mockRejectedValueOnce(new Error('some error'));

expect(await strategy.getLengthSafe(client, mockKey)).toEqual(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('GraphInfoStrategy', () => {

beforeEach(async () => {
when(client.sendCommand)
.calledWith(jasmine.arrayContaining(['graph.query']), expect.anything())
.calledWith(expect.arrayContaining(['graph.query']), expect.anything())
.mockResolvedValue(mockRedisResponse);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('HashInfoStrategy', () => {

beforeEach(async () => {
when(client.sendCommand)
.calledWith(jasmine.arrayContaining(['hlen']))
.calledWith(expect.arrayContaining(['hlen']))
.mockResolvedValue(mockRedisResponse);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,39 @@ describe('JsonInfoStrategy', () => {

beforeEach(async () => {
when(client.sendCommand)
.calledWith(jasmine.arrayContaining(['json.objlen']), expect.anything())
.calledWith(expect.arrayContaining(['json.objlen']), expect.anything())
.mockResolvedValue(1)
.calledWith(jasmine.arrayContaining(['json.arrlen']), expect.anything())
.calledWith(expect.arrayContaining(['json.arrlen']), expect.anything())
.mockResolvedValue(2)
.calledWith(jasmine.arrayContaining(['json.strlen']), expect.anything())
.calledWith(expect.arrayContaining(['json.strlen']), expect.anything())
.mockResolvedValue(3);
});

describe('getLength', () => {
it('should get length (object)', async () => {
when(client.sendCommand)
.calledWith(jasmine.arrayContaining(['json.type']), expect.anything())
.calledWith(expect.arrayContaining(['json.type']), expect.anything())
.mockResolvedValue('object');

expect(await strategy.getLength(client, mockKey)).toEqual(1);
});
it('should get length (array)', async () => {
when(client.sendCommand)
.calledWith(jasmine.arrayContaining(['json.type']), expect.anything())
.calledWith(expect.arrayContaining(['json.type']), expect.anything())
.mockResolvedValue('array');

expect(await strategy.getLength(client, mockKey)).toEqual(2);
});
it('should get length (string)', async () => {
when(client.sendCommand)
.calledWith(jasmine.arrayContaining(['json.type']), expect.anything())
.calledWith(expect.arrayContaining(['json.type']), expect.anything())
.mockResolvedValue('string');

expect(await strategy.getLength(client, mockKey)).toEqual(3);
});
it('should get length (undefined)', async () => {
when(client.sendCommand)
.calledWith(jasmine.arrayContaining(['json.type']), expect.anything())
.calledWith(expect.arrayContaining(['json.type']), expect.anything())
.mockResolvedValue('undefined');

expect(await strategy.getLength(client, mockKey)).toEqual(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('ListInfoStrategy', () => {

beforeEach(async () => {
when(client.sendCommand)
.calledWith(jasmine.arrayContaining(['llen']))
.calledWith(expect.arrayContaining(['llen']))
.mockResolvedValue(mockRedisResponse);
});

Expand Down
Loading