From d980268e0f16d1429d37ea9c64a401eeb112e076 Mon Sep 17 00:00:00 2001 From: Umer <160427254+MuhammadUmer44@users.noreply.github.com> Date: Sun, 12 Jan 2025 11:28:45 +0500 Subject: [PATCH 1/3] GetChat-unit-Test --- src/store/__test__/chatStore.spec.ts | 111 +++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 src/store/__test__/chatStore.spec.ts diff --git a/src/store/__test__/chatStore.spec.ts b/src/store/__test__/chatStore.spec.ts new file mode 100644 index 00000000..27a03dab --- /dev/null +++ b/src/store/__test__/chatStore.spec.ts @@ -0,0 +1,111 @@ +import { ChatHistoryStore } from '../chat'; +import { Chat } from '../interface'; + +describe('ChatHistoryStore', () => { + let store: ChatHistoryStore; + + beforeEach(() => { + store = new ChatHistoryStore(); + }); + + describe('getChat', () => { + const mockChat: Chat = { + id: 'chat123', + workspaceId: 'workspace123', + title: 'Test Chat', + createdAt: '2024-03-20T10:00:00Z', + updatedAt: '2024-03-20T10:00:00Z' + }; + + it('should return chat when valid ID exists', () => { + store.addChat(mockChat); + const result = store.getChat('chat123'); + expect(result).toEqual(mockChat); + }); + + it('should return undefined for non-existing chat ID', () => { + const result = store.getChat('nonexistent123'); + expect(result).toBeUndefined(); + }); + + it('should return undefined for empty string ID', () => { + const result = store.getChat(''); + expect(result).toBeUndefined(); + }); + + it('should handle IDs with special characters', () => { + const specialChat: Chat = { + ...mockChat, + id: 'chat!@#$%^&*()' + }; + store.addChat(specialChat); + const result = store.getChat('chat!@#$%^&*()'); + expect(result).toEqual(specialChat); + }); + + it('should handle IDs with maximum length', () => { + const longId = 'a'.repeat(256); + const longChat: Chat = { + ...mockChat, + id: longId + }; + store.addChat(longChat); + const result = store.getChat(longId); + expect(result).toEqual(longChat); + }); + + it('should be case sensitive when retrieving chats', () => { + store.addChat(mockChat); + const result = store.getChat('CHAT123'); + expect(result).toBeUndefined(); + }); + + it('should handle IDs with leading/trailing whitespace', () => { + const result = store.getChat(' chat123 '); + expect(result).toBeUndefined(); + + store.addChat(mockChat); + const validResult = store.getChat('chat123'); + expect(validResult).toEqual(mockChat); + }); + + it('should handle IDs with internal whitespace', () => { + const spaceChat: Chat = { + ...mockChat, + id: 'chat 123' + }; + store.addChat(spaceChat); + const result = store.getChat('chat 123'); + expect(result).toEqual(spaceChat); + }); + + it('should handle IDs with unicode characters', () => { + const unicodeChat: Chat = { + ...mockChat, + id: 'chat🚀你好' + }; + store.addChat(unicodeChat); + const result = store.getChat('chat🚀你好'); + expect(result).toEqual(unicodeChat); + }); + + it('should correctly manage multiple chats', () => { + const chat1 = { ...mockChat, id: 'chat1' }; + const chat2 = { ...mockChat, id: 'chat2' }; + + store.addChat(chat1); + store.addChat(chat2); + + expect(store.getChat('chat1')).toEqual(chat1); + expect(store.getChat('chat2')).toEqual(chat2); + }); + + it('should return updated chat after modification', () => { + store.addChat(mockChat); + store.updateChat('chat123', { title: 'Updated Title' }); + + const result = store.getChat('chat123'); + expect(result?.title).toBe('Updated Title'); + }); + }); +}); From 16820b2a476840be08385343eedf735bb6a0ec0c Mon Sep 17 00:00:00 2001 From: Umer <160427254+MuhammadUmer44@users.noreply.github.com> Date: Sun, 12 Jan 2025 11:42:01 +0500 Subject: [PATCH 2/3] fix prettier error From 0458e6893353c3a760a84664d5f2a5dfd86451de Mon Sep 17 00:00:00 2001 From: MuhammadUmer44 Date: Sun, 12 Jan 2025 11:56:25 +0500 Subject: [PATCH 3/3] fix prettier error --- src/store/__test__/chatStore.spec.ts | 222 +++++++++++++-------------- 1 file changed, 111 insertions(+), 111 deletions(-) diff --git a/src/store/__test__/chatStore.spec.ts b/src/store/__test__/chatStore.spec.ts index 27a03dab..f20e6dfb 100644 --- a/src/store/__test__/chatStore.spec.ts +++ b/src/store/__test__/chatStore.spec.ts @@ -1,111 +1,111 @@ -import { ChatHistoryStore } from '../chat'; -import { Chat } from '../interface'; - -describe('ChatHistoryStore', () => { - let store: ChatHistoryStore; - - beforeEach(() => { - store = new ChatHistoryStore(); - }); - - describe('getChat', () => { - const mockChat: Chat = { - id: 'chat123', - workspaceId: 'workspace123', - title: 'Test Chat', - createdAt: '2024-03-20T10:00:00Z', - updatedAt: '2024-03-20T10:00:00Z' - }; - - it('should return chat when valid ID exists', () => { - store.addChat(mockChat); - const result = store.getChat('chat123'); - expect(result).toEqual(mockChat); - }); - - it('should return undefined for non-existing chat ID', () => { - const result = store.getChat('nonexistent123'); - expect(result).toBeUndefined(); - }); - - it('should return undefined for empty string ID', () => { - const result = store.getChat(''); - expect(result).toBeUndefined(); - }); - - it('should handle IDs with special characters', () => { - const specialChat: Chat = { - ...mockChat, - id: 'chat!@#$%^&*()' - }; - store.addChat(specialChat); - const result = store.getChat('chat!@#$%^&*()'); - expect(result).toEqual(specialChat); - }); - - it('should handle IDs with maximum length', () => { - const longId = 'a'.repeat(256); - const longChat: Chat = { - ...mockChat, - id: longId - }; - store.addChat(longChat); - const result = store.getChat(longId); - expect(result).toEqual(longChat); - }); - - it('should be case sensitive when retrieving chats', () => { - store.addChat(mockChat); - const result = store.getChat('CHAT123'); - expect(result).toBeUndefined(); - }); - - it('should handle IDs with leading/trailing whitespace', () => { - const result = store.getChat(' chat123 '); - expect(result).toBeUndefined(); - - store.addChat(mockChat); - const validResult = store.getChat('chat123'); - expect(validResult).toEqual(mockChat); - }); - - it('should handle IDs with internal whitespace', () => { - const spaceChat: Chat = { - ...mockChat, - id: 'chat 123' - }; - store.addChat(spaceChat); - const result = store.getChat('chat 123'); - expect(result).toEqual(spaceChat); - }); - - it('should handle IDs with unicode characters', () => { - const unicodeChat: Chat = { - ...mockChat, - id: 'chat🚀你好' - }; - store.addChat(unicodeChat); - const result = store.getChat('chat🚀你好'); - expect(result).toEqual(unicodeChat); - }); - - it('should correctly manage multiple chats', () => { - const chat1 = { ...mockChat, id: 'chat1' }; - const chat2 = { ...mockChat, id: 'chat2' }; - - store.addChat(chat1); - store.addChat(chat2); - - expect(store.getChat('chat1')).toEqual(chat1); - expect(store.getChat('chat2')).toEqual(chat2); - }); - - it('should return updated chat after modification', () => { - store.addChat(mockChat); - store.updateChat('chat123', { title: 'Updated Title' }); - - const result = store.getChat('chat123'); - expect(result?.title).toBe('Updated Title'); - }); - }); -}); +import { ChatHistoryStore } from '../chat'; +import { Chat } from '../interface'; + +describe('ChatHistoryStore', () => { + let store: ChatHistoryStore; + + beforeEach(() => { + store = new ChatHistoryStore(); + }); + + describe('getChat', () => { + const mockChat: Chat = { + id: 'chat123', + workspaceId: 'workspace123', + title: 'Test Chat', + createdAt: '2024-03-20T10:00:00Z', + updatedAt: '2024-03-20T10:00:00Z' + }; + + it('should return chat when valid ID exists', () => { + store.addChat(mockChat); + const result = store.getChat('chat123'); + expect(result).toEqual(mockChat); + }); + + it('should return undefined for non-existing chat ID', () => { + const result = store.getChat('nonexistent123'); + expect(result).toBeUndefined(); + }); + + it('should return undefined for empty string ID', () => { + const result = store.getChat(''); + expect(result).toBeUndefined(); + }); + + it('should handle IDs with special characters', () => { + const specialChat: Chat = { + ...mockChat, + id: 'chat!@#$%^&*()' + }; + store.addChat(specialChat); + const result = store.getChat('chat!@#$%^&*()'); + expect(result).toEqual(specialChat); + }); + + it('should handle IDs with maximum length', () => { + const longId = 'a'.repeat(256); + const longChat: Chat = { + ...mockChat, + id: longId + }; + store.addChat(longChat); + const result = store.getChat(longId); + expect(result).toEqual(longChat); + }); + + it('should be case sensitive when retrieving chats', () => { + store.addChat(mockChat); + const result = store.getChat('CHAT123'); + expect(result).toBeUndefined(); + }); + + it('should handle IDs with leading/trailing whitespace', () => { + const result = store.getChat(' chat123 '); + expect(result).toBeUndefined(); + + store.addChat(mockChat); + const validResult = store.getChat('chat123'); + expect(validResult).toEqual(mockChat); + }); + + it('should handle IDs with internal whitespace', () => { + const spaceChat: Chat = { + ...mockChat, + id: 'chat 123' + }; + store.addChat(spaceChat); + const result = store.getChat('chat 123'); + expect(result).toEqual(spaceChat); + }); + + it('should handle IDs with unicode characters', () => { + const unicodeChat: Chat = { + ...mockChat, + id: 'chat🚀你好' + }; + store.addChat(unicodeChat); + const result = store.getChat('chat🚀你好'); + expect(result).toEqual(unicodeChat); + }); + + it('should correctly manage multiple chats', () => { + const chat1 = { ...mockChat, id: 'chat1' }; + const chat2 = { ...mockChat, id: 'chat2' }; + + store.addChat(chat1); + store.addChat(chat2); + + expect(store.getChat('chat1')).toEqual(chat1); + expect(store.getChat('chat2')).toEqual(chat2); + }); + + it('should return updated chat after modification', () => { + store.addChat(mockChat); + store.updateChat('chat123', { title: 'Updated Title' }); + + const result = store.getChat('chat123'); + expect(result?.title).toBe('Updated Title'); + }); + }); +});