Skip to content

Commit

Permalink
fix: fix test problem
Browse files Browse the repository at this point in the history
  • Loading branch information
ChengShi-1 committed Dec 18, 2024
1 parent 50590eb commit 8728186
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
8 changes: 4 additions & 4 deletions test/functional/contact/SubmitContactInfo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('submitContactInfo', () => {
const fromEmail = '[email protected]'

const contactDTO: ContactDTO = {
targetId: 6,
targetId: 1,
subject: subject,
body: 'Please help me understand your data. Thank you!',
fromEmail: fromEmail
Expand All @@ -31,9 +31,9 @@ describe('submitContactInfo', () => {
} finally {
expect(contactInfo).toBeDefined()
expect(contactInfo[0].fromEmail).toEqual(fromEmail)
expect(contactInfo[0].subject).toBeDefined()
expect(contactInfo[0].body).toBeDefined()
expect(contactInfo[0].toEmail).toBeDefined()
expect(contactInfo[0].subject).toEqual(expect.any(String))
expect(contactInfo[0].body).toEqual(expect.any(String))
expect(contactInfo[0].toEmail).toEqual(expect.any(String))
}
})

Expand Down
40 changes: 22 additions & 18 deletions test/integration/contact/ContactRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('submitContactInfo', () => {
})

const testContactDTO: ContactDTO = {
targetId: 6,
targetId: 1,
subject: 'Data Question',
body: 'Please help me understand your data. Thank you!',
fromEmail: '[email protected]'
Expand All @@ -22,23 +22,27 @@ describe('submitContactInfo', () => {
const sut: ContactRepository = new ContactRepository()

test('should return ContactDTO when contact info is successfully submitted', async () => {
const contactInfo = await sut.submitContactInfo(testContactDTO)

expect(contactInfo).toBeDefined()
expect(contactInfo[0].fromEmail).toEqual(testContactDTO.fromEmail)
expect(contactInfo[0].subject).toBeDefined()
expect(contactInfo[0].body).toBeDefined()
expect(contactInfo[0].toEmail).toBeDefined()
})

test('should return error if the target id is unexisted', async () => {
const invalidContactDTO: ContactDTO = {
targetId: 0,
subject: '',
body: '',
fromEmail: ''
try {
const contactInfo = await sut.submitContactInfo(testContactDTO)
expect(contactInfo).toBeDefined()
expect(contactInfo[0].fromEmail).toEqual(testContactDTO.fromEmail)
expect(contactInfo[0].subject).toEqual(expect.any(String))
expect(contactInfo[0].body).toEqual(expect.any(String))
expect(contactInfo[0].toEmail).toEqual(expect.any(String))
} catch (error) {
console.error('Error during submission:', error.message, error.response?.data)
throw error
}
const expectedError = new WriteError(`[400] Feedback target object not found`)
await expect(sut.submitContactInfo(invalidContactDTO)).rejects.toThrow(expectedError)

test('should return error if the target id is unexisted', async () => {
const invalidContactDTO: ContactDTO = {
targetId: 0,
subject: '',
body: '',
fromEmail: ''
}
const expectedError = new WriteError(`[400] Feedback target object not found`)
await expect(sut.submitContactInfo(invalidContactDTO)).rejects.toThrow(expectedError)
})
})
})

0 comments on commit 8728186

Please sign in to comment.