test: update test cases

This commit is contained in:
Louis 2024-12-17 18:11:07 +07:00
parent 8613e35c15
commit 3a9c99972c
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2
3 changed files with 24 additions and 23 deletions

View File

@ -1,27 +1,28 @@
import { displayDate } from './datetime'
import { isToday } from './datetime'
import { displayDate } from './datetime'; test("should return only time for today's timestamp", () => {
import { isToday } from './datetime'; const today = new Date()
const timestamp = today.getTime()
test('should return only time for today\'s timestamp', () => { const expectedTime = `${today.toLocaleDateString(undefined, {
const today = new Date(); day: '2-digit',
const timestamp = today.getTime(); month: 'short',
const expectedTime = today.toLocaleTimeString(undefined, { year: 'numeric',
})}, ${today.toLocaleTimeString(undefined, {
hour: '2-digit', hour: '2-digit',
minute: '2-digit', minute: '2-digit',
second: '2-digit', second: '2-digit',
hour12: true, hour12: true,
}); })}`
expect(displayDate(timestamp)).toBe(expectedTime); expect(displayDate(timestamp / 1000)).toBe(expectedTime)
}); })
test('should return N/A for undefined timestamp', () => { test('should return N/A for undefined timestamp', () => {
expect(displayDate()).toBe('N/A'); expect(displayDate()).toBe('N/A')
}); })
test("should return true for today's timestamp", () => {
test('should return true for today\'s timestamp', () => { const today = new Date()
const today = new Date(); const timestamp = today.setHours(0, 0, 0, 0)
const timestamp = today.setHours(0, 0, 0, 0); expect(isToday(timestamp)).toBe(true)
expect(isToday(timestamp)).toBe(true); })
});

View File

@ -23,8 +23,8 @@ describe('ThreadMessageBuilder', () => {
expect(result.thread_id).toBe(msgRequest.thread.id) expect(result.thread_id).toBe(msgRequest.thread.id)
expect(result.role).toBe(ChatCompletionRole.User) expect(result.role).toBe(ChatCompletionRole.User)
expect(result.status).toBe(MessageStatus.Ready) expect(result.status).toBe(MessageStatus.Ready)
expect(result.created).toBeDefined() expect(result.created_at).toBeDefined()
expect(result.updated).toBeDefined() expect(result.completed_at).toBeDefined()
expect(result.object).toBe('thread.message') expect(result.object).toBe('thread.message')
expect(result.content).toEqual([]) expect(result.content).toEqual([])
}) })

View File

@ -29,8 +29,8 @@ export class ThreadMessageBuilder {
attachments: this.attachments, attachments: this.attachments,
role: ChatCompletionRole.User, role: ChatCompletionRole.User,
status: MessageStatus.Ready, status: MessageStatus.Ready,
created: timestamp, created_at: timestamp,
updated: timestamp, completed_at: timestamp,
object: 'thread.message', object: 'thread.message',
content: this.content, content: this.content,
} }