Skip to content

Commit cfc5dea

Browse files
Merge pull request #4199 from RedisInsight/be/bugfix/fix-tests
fix tests
2 parents 775a908 + 5a04504 commit cfc5dea

8 files changed

+26
-26
lines changed

redisinsight/api/src/__mocks__/cloud-common.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { HttpStatus } from '@nestjs/common';
2-
import ERROR_MESSAGES from 'src/constants/error-messages';
32
import { CustomErrorCodes } from 'src/constants';
43

54
export const mockCapiUnauthorizedError = {
6-
message: 'Request failed with status code 401',
5+
message: 'Custom unauthorized message',
76
response: {
87
status: 401,
98
},
@@ -12,14 +11,14 @@ export const mockCapiUnauthorizedError = {
1211
export const mockSmApiUnauthorizedError = mockCapiUnauthorizedError;
1312

1413
export const mockSmApiInternalServerError = {
15-
message: 'Something wrong',
14+
message: 'Custom server error message',
1615
response: {
1716
status: 500,
1817
},
1918
};
2019

2120
export const mockSmApiBadRequestError = {
22-
message: 'Bad Request',
21+
message: 'Custom bad request message',
2322
response: {
2423
status: 400,
2524
},
@@ -34,13 +33,13 @@ export const mockUtm = {
3433
export const mockCloudApiUnauthorizedExceptionResponse = {
3534
error: 'CloudApiUnauthorized',
3635
errorCode: CustomErrorCodes.CloudApiUnauthorized,
37-
message: ERROR_MESSAGES.UNAUTHORIZED,
36+
message: mockCapiUnauthorizedError.message,
3837
statusCode: HttpStatus.UNAUTHORIZED,
3938
};
4039

4140
export const mockCloudApiBadRequestExceptionResponse = {
4241
error: 'CloudApiBadRequest',
4342
errorCode: CustomErrorCodes.CloudApiBadRequest,
44-
message: ERROR_MESSAGES.BAD_REQUEST,
43+
message: mockSmApiBadRequestError.message,
4544
statusCode: HttpStatus.BAD_REQUEST,
4645
};

redisinsight/api/test/api/ai/assistant/DELETE-ai-assistant-chats-id.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ describe('DELETE /ai/assistant/chats/:id', () => {
2626
{
2727
name: 'Should return Unauthorized error',
2828
before: () => {
29-
aiAssistantNock.post('/reset').reply(401, { message: 'Unauthorized' })
29+
aiAssistantNock.post('/reset').replyWithError({ response: { status: 401 }, message: 'Custom unauthorized message' })
3030
},
3131
statusCode: 401,
3232
responseBody: {
3333
statusCode: 401,
3434
error: 'ConvAiUnauthorized',
35-
message: 'Authorization failed',
35+
message: 'Custom unauthorized message',
3636
errorCode: 11301,
3737
},
3838
},

redisinsight/api/test/api/ai/assistant/GET-ai-assistant-chats-id.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ describe('GET /ai/assistant/chats/:id', () => {
4747
{
4848
name: 'Should return Unauthorized error',
4949
before: () => {
50-
aiAssistantNock.get('/history').reply(401, { message: 'Unauthorized' })
50+
aiAssistantNock.get('/history').replyWithError({ response: { status: 401 }, message: 'Custom unauthorized message' })
5151
},
5252
statusCode: 401,
5353
responseBody: {
5454
statusCode: 401,
5555
error: 'ConvAiUnauthorized',
56-
message: 'Authorization failed',
56+
message: 'Custom unauthorized message',
5757
errorCode: 11301,
5858
},
5959
},

redisinsight/api/test/api/ai/assistant/POST-ai-assistant-chats-id-messages.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ describe('POST /ai/assistant/chats/:id/messages', () => {
3434
{
3535
name: 'Should return Unauthorized error',
3636
before: () => {
37-
aiAssistantNock.post('/chat').query(true).reply(401, { message: 'Unauthorized' })
37+
aiAssistantNock.post('/chat').query(true)
38+
.replyWithError({ message: 'Custom unauthorized message', response: { status: 401 } })
3839
},
3940
data: {
4041
content: mockHumanMessage1Response.content,
@@ -43,7 +44,7 @@ describe('POST /ai/assistant/chats/:id/messages', () => {
4344
responseBody: {
4445
statusCode: 401,
4546
error: 'ConvAiUnauthorized',
46-
message: 'Authorization failed',
47+
message: 'Custom unauthorized message',
4748
errorCode: 11301,
4849
},
4950
},

redisinsight/api/test/api/ai/assistant/POST-ai-assistant-chats.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ describe('POST /ai/assistant/chats', () => {
3535
{
3636
name: 'Should return Unauthorized error',
3737
before: () => {
38-
aiAssistantNock.post('/auth').reply(401, { message: 'Unauthorized' })
38+
aiAssistantNock.post('/auth').replyWithError({ message: 'Custom unauthorized message', response: { status: 401 } })
3939
},
4040
statusCode: 401,
4141
responseBody: {
4242
statusCode: 401,
4343
error: 'ConvAiUnauthorized',
44-
message: 'Authorization failed',
44+
message: 'Custom unauthorized message',
4545
errorCode: 11301,
4646
},
4747
},

redisinsight/api/test/api/cloud/autodiscovery/POST-cloud-autodiscovery-databases.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ describe('POST /cloud/autodiscovery/databases', () => {
126126
before: () => {
127127
nockScope
128128
.get(`/fixed/subscriptions/${mockImportCloudDatabaseDtoFixed.subscriptionId}/databases/${mockImportCloudDatabaseDtoFixed.databaseId}`)
129-
.reply(403, {
129+
.replyWithError({
130130
response: {
131131
status: 403,
132132
data: { message: 'Unauthorized for this action' },
@@ -143,19 +143,19 @@ describe('POST /cloud/autodiscovery/databases', () => {
143143
responseBody: [{
144144
...mockImportCloudDatabaseDtoFixed,
145145
status: 'fail',
146-
message: ERROR_MESSAGES.FORBIDDEN,
146+
message: 'Unauthorized for this action',
147147
error: {
148148
statusCode: 403,
149149
error: 'CloudApiForbidden',
150-
message: ERROR_MESSAGES.FORBIDDEN,
150+
message: 'Unauthorized for this action',
151151
errorCode: CustomErrorCodes.CloudApiForbidden,
152152
},
153153
}],
154154
},
155155
{
156156
before: () => {
157157
nockScope.get(`/subscriptions/${mockImportCloudDatabaseDto.subscriptionId}/databases/${mockImportCloudDatabaseDto.databaseId}`)
158-
.reply(401, {
158+
.replyWithError({
159159
response: {
160160
status: 401,
161161
data: '',
@@ -184,7 +184,7 @@ describe('POST /cloud/autodiscovery/databases', () => {
184184
{
185185
before: () => {
186186
nockScope.get(`/subscriptions/${mockImportCloudDatabaseDto.subscriptionId}/databases/${mockImportCloudDatabaseDto.databaseId}`)
187-
.reply(404, {
187+
.replyWithError({
188188
response: {
189189
status: 404,
190190
data: 'Database was not found',

redisinsight/api/test/api/cloud/autodiscovery/POST-cloud-autodiscovery-get_databases.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe('POST /cloud/autodiscovery/get-databases', () => {
111111
{
112112
before: () => {
113113
nockScope.get(`/subscriptions/${mockGetCloudSubscriptionDatabasesDto.subscriptionId}/databases`)
114-
.reply(403, {
114+
.replyWithError({
115115
response: {
116116
status: 403,
117117
data: { message: 'Unauthorized for this action' },
@@ -127,14 +127,14 @@ describe('POST /cloud/autodiscovery/get-databases', () => {
127127
responseBody: {
128128
statusCode: 403,
129129
error: 'CloudApiForbidden',
130-
message: ERROR_MESSAGES.FORBIDDEN,
130+
message: 'Unauthorized for this action',
131131
errorCode: CustomErrorCodes.CloudApiForbidden,
132132
},
133133
},
134134
{
135135
before: () => {
136136
nockScope.get(`/subscriptions/${mockGetCloudSubscriptionDatabasesDto.subscriptionId}/databases`)
137-
.reply(401, {
137+
.replyWithError({
138138
response: {
139139
status: 401,
140140
data: '',
@@ -157,7 +157,7 @@ describe('POST /cloud/autodiscovery/get-databases', () => {
157157
{
158158
before: () => {
159159
nockScope.get(`/subscriptions/${mockGetCloudSubscriptionDatabasesDto.subscriptionId}/databases`)
160-
.reply(404, {
160+
.replyWithError({
161161
response: {
162162
status: 404,
163163
data: 'Subscription is not found',

redisinsight/api/test/api/cloud/user/PUT-cloud-me-accounts-id-current.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ describe('PUT /cloud/me/accounts/:id/current', () => {
7171
before: () => {
7272
initSMApiNockScope()
7373
.post(`/accounts/setcurrent/${mockCloudUserAccount.id}`)
74-
.reply(401, mockCapiUnauthorizedError)
74+
.replyWithError(mockCapiUnauthorizedError)
7575
.post(`/accounts/setcurrent/${mockCloudUserAccount.id}`)
76-
.reply(401, mockCapiUnauthorizedError)
76+
.replyWithError(mockCapiUnauthorizedError)
7777
},
7878
statusCode: 401,
7979
checkFn: ({ body }) => {
@@ -85,7 +85,7 @@ describe('PUT /cloud/me/accounts/:id/current', () => {
8585
before: () => {
8686
initSMApiNockScope()
8787
.post(`/accounts/setcurrent/${mockCloudUserAccount.id}`)
88-
.reply(400, mockSmApiBadRequestError)
88+
.replyWithError(mockSmApiBadRequestError)
8989
},
9090
statusCode: 400,
9191
checkFn: ({ body }) => {

0 commit comments

Comments
 (0)