Skip to content

Commit 65f379a

Browse files
committed
#RI-4813 - fix tests
1 parent 30223a5 commit 65f379a

File tree

8 files changed

+23
-20
lines changed

8 files changed

+23
-20
lines changed

redisinsight/api/src/modules/database-import/database-import.service.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ describe('DatabaseImportService', () => {
168168
...pick(mockDatabase, ['host', 'port', 'name', 'connectionType', 'timeout', 'compressor']),
169169
provider: 'RE_CLOUD',
170170
new: true,
171-
});
171+
}, false);
172172
});
173173
it('should create standalone with created name', async () => {
174174
await service['createDatabase']({
@@ -180,7 +180,7 @@ describe('DatabaseImportService', () => {
180180
...pick(mockDatabase, ['host', 'port', 'name', 'connectionType', 'timeout', 'compressor']),
181181
name: `${mockDatabase.host}:${mockDatabase.port}`,
182182
new: true,
183-
});
183+
}, false);
184184
});
185185
it('should create standalone with none compressor', async () => {
186186
await service['createDatabase']({
@@ -192,7 +192,7 @@ describe('DatabaseImportService', () => {
192192
...pick(mockDatabase, ['host', 'port', 'name', 'connectionType', 'timeout', 'compressor']),
193193
compressor: Compressor.NONE,
194194
new: true,
195-
});
195+
}, false);
196196
});
197197
it('should create standalone with compressor', async () => {
198198
await service['createDatabase']({
@@ -204,7 +204,7 @@ describe('DatabaseImportService', () => {
204204
...pick(mockDatabase, ['host', 'port', 'name', 'connectionType', 'timeout', 'compressor']),
205205
compressor: Compressor.GZIP,
206206
new: true,
207-
});
207+
}, false);
208208
});
209209
it('should create cluster database', async () => {
210210
await service['createDatabase']({
@@ -217,7 +217,7 @@ describe('DatabaseImportService', () => {
217217
...pick(mockDatabase, ['host', 'port', 'name', 'timeout', 'compressor']),
218218
connectionType: ConnectionType.CLUSTER,
219219
new: true,
220-
});
220+
}, false);
221221
});
222222
});
223223

redisinsight/api/src/modules/database-import/database-import.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ export class DatabaseImportService {
242242

243243
const database = classToClass(Database, dto);
244244

245-
await this.databaseRepository.create(database);
245+
await this.databaseRepository.create(database, false);
246246

247247
return {
248248
index,

redisinsight/api/src/modules/database/database.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class DatabaseController {
9898
async create(
9999
@Body() dto: CreateDatabaseDto,
100100
): Promise<Database> {
101-
return await this.service.create(dto);
101+
return await this.service.create(dto, true);
102102
}
103103

104104
@UseInterceptors(ClassSerializerInterceptor)

redisinsight/api/src/modules/database/database.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,16 @@ export class DatabaseService {
9898
/**
9999
* Create new database with auto-detection of database type, modules, etc.
100100
* @param dto
101+
* @param uniqueCheck
101102
*/
102-
async create(dto: CreateDatabaseDto): Promise<Database> {
103+
async create(dto: CreateDatabaseDto, uniqueCheck = false): Promise<Database> {
103104
try {
104105
this.logger.log('Creating new database.');
105106

106107
const database = await this.repository.create({
107108
...await this.databaseFactory.createDatabaseModel(classToClass(Database, dto)),
108109
new: true,
109-
});
110+
}, uniqueCheck);
110111

111112
// todo: clarify if we need this and if yes - rethink implementation
112113
try {

redisinsight/api/src/modules/database/repositories/database.repository.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ export abstract class DatabaseRepository {
2727
/**
2828
* Create database
2929
* @param database
30+
* @param uniqueCheck
3031
*/
31-
abstract create(database: Database): Promise<Database>;
32+
abstract create(database: Database, uniqueCheck: boolean): Promise<Database>;
3233

3334
/**
3435
* Update database with new data

redisinsight/api/src/modules/database/repositories/local.database.repository.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,18 +253,17 @@ describe('LocalDatabaseRepository', () => {
253253

254254
describe('create', () => {
255255
it('should create standalone database', async () => {
256-
const result = await service.create(mockDatabase);
256+
const result = await service.create(mockDatabase, false);
257257

258258
expect(result).toEqual(mockDatabase);
259259
expect(caCertRepository.create).not.toHaveBeenCalled();
260260
expect(clientCertRepository.create).not.toHaveBeenCalled();
261261
});
262262

263263
it('should create standalone database with cloud details', async () => {
264-
repository.findOneBy.mockResolvedValueOnce(null);
265264
repository.save.mockResolvedValue(mockDatabaseEntityWithCloudDetails);
266265

267-
const result = await service.create(mockDatabaseWithCloudDetails);
266+
const result = await service.create(mockDatabaseWithCloudDetails, false);
268267

269268
expect(result).toEqual(mockDatabaseWithCloudDetails);
270269
expect(caCertRepository.create).not.toHaveBeenCalled();
@@ -274,7 +273,7 @@ describe('LocalDatabaseRepository', () => {
274273
it('should create standalone database (with existing certificates)', async () => {
275274
repository.save.mockResolvedValueOnce(mockDatabaseWithTlsAuthEntity);
276275

277-
const result = await service.create(mockDatabaseWithTlsAuth);
276+
const result = await service.create(mockDatabaseWithTlsAuth, false);
278277

279278
expect(result).toEqual(mockDatabaseWithTlsAuth);
280279
expect(caCertRepository.create).not.toHaveBeenCalled();
@@ -286,6 +285,7 @@ describe('LocalDatabaseRepository', () => {
286285

287286
const result = await service.create(
288287
omit(cloneClassInstance(mockDatabaseWithTlsAuth), 'caCert.id', 'clientCert.id'),
288+
false,
289289
);
290290

291291
expect(result).toEqual(mockDatabaseWithTlsAuth);
@@ -296,7 +296,7 @@ describe('LocalDatabaseRepository', () => {
296296
it('should throw an error if create called with cloud details and have the same entity', async () => {
297297
repository.findOneBy.mockResolvedValueOnce(mockDatabaseEntity);
298298
try {
299-
await service.create(mockDatabaseEntityWithCloudDetails);
299+
await service.create(mockDatabaseEntityWithCloudDetails, true);
300300
fail();
301301
} catch (e) {
302302
expect(e).toBeInstanceOf(DatabaseAlreadyExistsException);

redisinsight/api/src/modules/database/repositories/local.database.repository.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,12 @@ export class LocalDatabaseRepository extends DatabaseRepository {
100100
/**
101101
* Create database with encrypted sensitive fields
102102
* @param database
103+
* @param uniqueCheck
103104
*/
104-
public async create(database: Database): Promise<Database> {
105-
await this.checkUniqueness(database);
106-
105+
public async create(database: Database, uniqueCheck: boolean): Promise<Database> {
106+
if (uniqueCheck) {
107+
await this.checkUniqueness(database);
108+
}
107109
const entity = classToClass(DatabaseEntity, await this.populateCertificates(database));
108110
return classToClass(
109111
Database,
@@ -248,7 +250,6 @@ export class LocalDatabaseRepository extends DatabaseRepository {
248250
set(query, field, get(entity, field));
249251
});
250252

251-
252253
const existingDatabase = await this.repository.findOneBy(query);
253254
if (existingDatabase) {
254255
throw new DatabaseAlreadyExistsException(existingDatabase.id);

redisinsight/api/src/modules/database/repositories/stack.databases.repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class StackDatabasesRepository extends LocalDatabaseRepository implements
8282
verifyServerCert: false,
8383
connectionType: ConnectionType.STANDALONE,
8484
lastConnection: null,
85-
});
85+
}, false);
8686
}
8787
this.logger.log(`Succeed to set predefined database ${id}`);
8888
} catch (error) {

0 commit comments

Comments
 (0)