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
11 changes: 5 additions & 6 deletions redisinsight/api/src/__mocks__/cloud-common.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { HttpStatus } from '@nestjs/common';
import ERROR_MESSAGES from 'src/constants/error-messages';
import { CustomErrorCodes } from 'src/constants';

export const mockCapiUnauthorizedError = {
message: 'Request failed with status code 401',
message: 'Custom unauthorized message',
response: {
status: 401,
},
Expand All @@ -12,14 +11,14 @@ export const mockCapiUnauthorizedError = {
export const mockSmApiUnauthorizedError = mockCapiUnauthorizedError;

export const mockSmApiInternalServerError = {
message: 'Something wrong',
message: 'Custom server error message',
response: {
status: 500,
},
};

export const mockSmApiBadRequestError = {
message: 'Bad Request',
message: 'Custom bad request message',
response: {
status: 400,
},
Expand All @@ -34,13 +33,13 @@ export const mockUtm = {
export const mockCloudApiUnauthorizedExceptionResponse = {
error: 'CloudApiUnauthorized',
errorCode: CustomErrorCodes.CloudApiUnauthorized,
message: ERROR_MESSAGES.UNAUTHORIZED,
message: mockCapiUnauthorizedError.message,
statusCode: HttpStatus.UNAUTHORIZED,
};

export const mockCloudApiBadRequestExceptionResponse = {
error: 'CloudApiBadRequest',
errorCode: CustomErrorCodes.CloudApiBadRequest,
message: ERROR_MESSAGES.BAD_REQUEST,
message: mockSmApiBadRequestError.message,
statusCode: HttpStatus.BAD_REQUEST,
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ describe('DELETE /ai/assistant/chats/:id', () => {
{
name: 'Should return Unauthorized error',
before: () => {
aiAssistantNock.post('/reset').reply(401, { message: 'Unauthorized' })
aiAssistantNock.post('/reset').replyWithError({ response: { status: 401 }, message: 'Custom unauthorized message' })
},
statusCode: 401,
responseBody: {
statusCode: 401,
error: 'ConvAiUnauthorized',
message: 'Authorization failed',
message: 'Custom unauthorized message',
errorCode: 11301,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ describe('GET /ai/assistant/chats/:id', () => {
{
name: 'Should return Unauthorized error',
before: () => {
aiAssistantNock.get('/history').reply(401, { message: 'Unauthorized' })
aiAssistantNock.get('/history').replyWithError({ response: { status: 401 }, message: 'Custom unauthorized message' })
},
statusCode: 401,
responseBody: {
statusCode: 401,
error: 'ConvAiUnauthorized',
message: 'Authorization failed',
message: 'Custom unauthorized message',
errorCode: 11301,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ describe('POST /ai/assistant/chats/:id/messages', () => {
{
name: 'Should return Unauthorized error',
before: () => {
aiAssistantNock.post('/chat').query(true).reply(401, { message: 'Unauthorized' })
aiAssistantNock.post('/chat').query(true)
.replyWithError({ message: 'Custom unauthorized message', response: { status: 401 } })
},
data: {
content: mockHumanMessage1Response.content,
Expand All @@ -43,7 +44,7 @@ describe('POST /ai/assistant/chats/:id/messages', () => {
responseBody: {
statusCode: 401,
error: 'ConvAiUnauthorized',
message: 'Authorization failed',
message: 'Custom unauthorized message',
errorCode: 11301,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ describe('POST /ai/assistant/chats', () => {
{
name: 'Should return Unauthorized error',
before: () => {
aiAssistantNock.post('/auth').reply(401, { message: 'Unauthorized' })
aiAssistantNock.post('/auth').replyWithError({ message: 'Custom unauthorized message', response: { status: 401 } })
},
statusCode: 401,
responseBody: {
statusCode: 401,
error: 'ConvAiUnauthorized',
message: 'Authorization failed',
message: 'Custom unauthorized message',
errorCode: 11301,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe('POST /cloud/autodiscovery/databases', () => {
before: () => {
nockScope
.get(`/fixed/subscriptions/${mockImportCloudDatabaseDtoFixed.subscriptionId}/databases/${mockImportCloudDatabaseDtoFixed.databaseId}`)
.reply(403, {
.replyWithError({
response: {
status: 403,
data: { message: 'Unauthorized for this action' },
Expand All @@ -143,19 +143,19 @@ describe('POST /cloud/autodiscovery/databases', () => {
responseBody: [{
...mockImportCloudDatabaseDtoFixed,
status: 'fail',
message: ERROR_MESSAGES.FORBIDDEN,
message: 'Unauthorized for this action',
error: {
statusCode: 403,
error: 'CloudApiForbidden',
message: ERROR_MESSAGES.FORBIDDEN,
message: 'Unauthorized for this action',
errorCode: CustomErrorCodes.CloudApiForbidden,
},
}],
},
{
before: () => {
nockScope.get(`/subscriptions/${mockImportCloudDatabaseDto.subscriptionId}/databases/${mockImportCloudDatabaseDto.databaseId}`)
.reply(401, {
.replyWithError({
response: {
status: 401,
data: '',
Expand Down Expand Up @@ -184,7 +184,7 @@ describe('POST /cloud/autodiscovery/databases', () => {
{
before: () => {
nockScope.get(`/subscriptions/${mockImportCloudDatabaseDto.subscriptionId}/databases/${mockImportCloudDatabaseDto.databaseId}`)
.reply(404, {
.replyWithError({
response: {
status: 404,
data: 'Database was not found',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe('POST /cloud/autodiscovery/get-databases', () => {
{
before: () => {
nockScope.get(`/subscriptions/${mockGetCloudSubscriptionDatabasesDto.subscriptionId}/databases`)
.reply(403, {
.replyWithError({
response: {
status: 403,
data: { message: 'Unauthorized for this action' },
Expand All @@ -127,14 +127,14 @@ describe('POST /cloud/autodiscovery/get-databases', () => {
responseBody: {
statusCode: 403,
error: 'CloudApiForbidden',
message: ERROR_MESSAGES.FORBIDDEN,
message: 'Unauthorized for this action',
errorCode: CustomErrorCodes.CloudApiForbidden,
},
},
{
before: () => {
nockScope.get(`/subscriptions/${mockGetCloudSubscriptionDatabasesDto.subscriptionId}/databases`)
.reply(401, {
.replyWithError({
response: {
status: 401,
data: '',
Expand All @@ -157,7 +157,7 @@ describe('POST /cloud/autodiscovery/get-databases', () => {
{
before: () => {
nockScope.get(`/subscriptions/${mockGetCloudSubscriptionDatabasesDto.subscriptionId}/databases`)
.reply(404, {
.replyWithError({
response: {
status: 404,
data: 'Subscription is not found',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ describe('PUT /cloud/me/accounts/:id/current', () => {
before: () => {
initSMApiNockScope()
.post(`/accounts/setcurrent/${mockCloudUserAccount.id}`)
.reply(401, mockCapiUnauthorizedError)
.replyWithError(mockCapiUnauthorizedError)
.post(`/accounts/setcurrent/${mockCloudUserAccount.id}`)
.reply(401, mockCapiUnauthorizedError)
.replyWithError(mockCapiUnauthorizedError)
},
statusCode: 401,
checkFn: ({ body }) => {
Expand All @@ -85,7 +85,7 @@ describe('PUT /cloud/me/accounts/:id/current', () => {
before: () => {
initSMApiNockScope()
.post(`/accounts/setcurrent/${mockCloudUserAccount.id}`)
.reply(400, mockSmApiBadRequestError)
.replyWithError(mockSmApiBadRequestError)
},
statusCode: 400,
checkFn: ({ body }) => {
Expand Down
Loading