Skip to content

Commit

Permalink
Develop Merge (#237)
Browse files Browse the repository at this point in the history
* Added PINNED status in bot. (#235)

* Fix: Fix for migration history (#236)

---------

Co-authored-by: Anvansh <[email protected]>
  • Loading branch information
chinmoy12c and RyanWalker277 authored Mar 13, 2024
1 parent 030056f commit 8d7e2a3
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 4 deletions.
2 changes: 2 additions & 0 deletions prisma/migrations/20220822130634_bot_add_image/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Bot" ADD COLUMN "botImage" TEXT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "BotStatus" ADD VALUE 'PINNED';
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum BotStatus {
ENABLED
DISABLED
DRAFT
PINNED
}

model Adapter {
Expand Down
15 changes: 14 additions & 1 deletion src/modules/bot/bot.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ const mockBotService = {
if (id == 'disabled') {
mockBotDataCopy['status'] = BotStatus.DISABLED;
}
else if (id == 'enabled') {
mockBotDataCopy['status'] = BotStatus.ENABLED;
}
else if (id == 'pinned') {
mockBotDataCopy['status'] = BotStatus.PINNED;
}
if (id == 'noUser') {
mockBotDataCopy['users'] = []
}
Expand Down Expand Up @@ -85,7 +91,9 @@ const mockBotService = {
};
}),

getBroadcastReport: jest.fn()
getBroadcastReport: jest.fn(),

start: jest.fn(),
}

const mockBotData: Prisma.BotGetPayload<{
Expand Down Expand Up @@ -265,6 +273,11 @@ describe('BotController', () => {
await expect(() => botController.startOne('disabled', {})).rejects.toThrowError(ServiceUnavailableException);
});

it('only disabled bot returns unavailable error',async () => {
expect(botController.startOne('pinned', {})).resolves;
expect(botController.startOne('enabled', {})).resolves;
});

it('update only passes relevant bot data to bot service', async () => {
updateParametersPassed = [
'status',
Expand Down
2 changes: 1 addition & 1 deletion src/modules/bot/bot.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class BotController {
throw new BadRequestException('Bot does not contain user segment data');
}
console.log(bot?.users[0].all);
if (bot?.status != BotStatus.ENABLED) {
if (bot?.status == BotStatus.DISABLED) {
throw new ServiceUnavailableException("Bot is not enabled!");
}
const res = await this.botService.start(id, bot?.users[0].all?.config, headers['conversation-authorization']);
Expand Down
18 changes: 18 additions & 0 deletions src/modules/bot/bot.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { CacheModule } from '@nestjs/common';
import { BotStatus } from '../../../prisma/generated/prisma-client-js';
import { UserSegmentService } from '../user-segment/user-segment.service';
import { ConversationLogicService } from '../conversation-logic/conversation-logic.service';
import { assert } from 'console';


const MockPrismaService = {
Expand All @@ -20,6 +21,8 @@ const MockPrismaService = {
mockBotsDbCopy.purpose = createData.data.purpose;
if (createData.data.description)
mockBotsDbCopy.description = createData.data.description;
if (createData.data.status)
mockBotsDbCopy.status = createData.data.status;
return mockBotsDbCopy;
},
findUnique: (filter) => {
Expand Down Expand Up @@ -367,6 +370,7 @@ let deletedIds: any[] = []
describe('BotService', () => {
let botService: BotService;
let configService: ConfigService;
jest.setTimeout(15000);

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
Expand Down Expand Up @@ -758,4 +762,18 @@ describe('BotService', () => {
mockCreateBotDtoCopy.logic = ['NonExisting'];
expect(botService.create(mockCreateBotDtoCopy, mockFile)).rejects.toThrowError('Converstaion Logic does not exist!');
});

it('bot status pinned is passed to db', async () => {
fetchMock.postOnce(`${configService.get<string>('MINIO_MEDIA_UPLOAD_URL')}`, {
fileName: 'testFileName'
});
const mockCreateBotDtoCopy: CreateBotDto & { ownerID: string; ownerOrgID: string } = { ...mockCreateBotDto };
mockCreateBotDtoCopy.status = 'PINNED';
mockCreateBotDtoCopy.name = 'testBotNotExisting';
mockCreateBotDtoCopy.startingMessage = 'testBotStartingMessageNotExisting';
const response = await botService.create(mockCreateBotDtoCopy, mockFile);
assert(response != null);
expect(response!['status']).toStrictEqual('PINNED');
fetchMock.restore();
});
});
17 changes: 15 additions & 2 deletions src/modules/bot/bot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@ export class BotService {
name: data.name,
ownerID: data.ownerid,
ownerOrgID: data.ownerorgid,
status:
data.status && data.status.toLocaleLowerCase() === 'enabled' ? BotStatus.ENABLED : BotStatus.DISABLED,
status: this.getBotStatus(data.status),
startDate: this.getDateFromString(data.startDate),
endDate: this.getDateFromString(data.endDate),
tags: data.tags,
Expand Down Expand Up @@ -269,6 +268,20 @@ export class BotService {
}
}

private getBotStatus(status: string): BotStatus {
status = status.toLocaleLowerCase();
switch (status) {
case 'enabled':
return BotStatus.ENABLED;
case 'disabled':
return BotStatus.DISABLED;
case 'pinned':
return BotStatus.PINNED;
default:
return BotStatus.ENABLED;
}
}

async findAllUnresolved(): Promise<Prisma.BotGetPayload<{
include: {
users: {
Expand Down

0 comments on commit 8d7e2a3

Please sign in to comment.