Skip to content

Commit 84cea2b

Browse files
author
Artem
committed
#RI-3902 add transformers for host, port fields + add tests (resolve pr comments)
1 parent f945ff1 commit 84cea2b

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

redisinsight/api/src/modules/database-import/dto/database-import.response.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isArray } from 'lodash';
1+
import { isArray, isString, isNumber } from 'lodash';
22
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
33
import { Expose, Transform, Type } from 'class-transformer';
44

@@ -28,13 +28,15 @@ export class DatabaseImportResult {
2828
type: String,
2929
})
3030
@Expose()
31+
@Transform((v) => (isString(v) ? v : undefined), { toPlainOnly: true })
3132
host?: string;
3233

3334
@ApiPropertyOptional({
3435
description: 'Database port',
3536
type: Number,
3637
})
3738
@Expose()
39+
@Transform((v) => (isNumber(v) ? v : undefined), { toPlainOnly: true })
3840
port?: number;
3941

4042
@ApiPropertyOptional({

redisinsight/api/test/api/database-import/POST-databases-import.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ describe('POST /databases/import', () => {
6868
total: 1,
6969
success: [],
7070
partial: [],
71+
},
72+
checkFn: ({ body }) => {
73+
expect(body.fail.length).to.eq(1);
74+
expect(body.fail[0].status).to.eq('fail');
75+
expect(body.fail[0].index).to.eq(0);
76+
expect(body.fail[0].error).to.be.a('string');
77+
if (body.fail[0].host) {
78+
expect(body.fail[0].host).to.be.a('string');
79+
}
80+
if (body.fail[0].port) {
81+
expect(body.fail[0].port).to.be.a('number');
82+
}
7183
}
7284
}
7385
})

0 commit comments

Comments
 (0)