Skip to content

Commit 8728186

Browse files
committed
fix: fix test problem
1 parent 50590eb commit 8728186

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

test/functional/contact/SubmitContactInfo.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('submitContactInfo', () => {
1616
const fromEmail = '[email protected]'
1717

1818
const contactDTO: ContactDTO = {
19-
targetId: 6,
19+
targetId: 1,
2020
subject: subject,
2121
body: 'Please help me understand your data. Thank you!',
2222
fromEmail: fromEmail
@@ -31,9 +31,9 @@ describe('submitContactInfo', () => {
3131
} finally {
3232
expect(contactInfo).toBeDefined()
3333
expect(contactInfo[0].fromEmail).toEqual(fromEmail)
34-
expect(contactInfo[0].subject).toBeDefined()
35-
expect(contactInfo[0].body).toBeDefined()
36-
expect(contactInfo[0].toEmail).toBeDefined()
34+
expect(contactInfo[0].subject).toEqual(expect.any(String))
35+
expect(contactInfo[0].body).toEqual(expect.any(String))
36+
expect(contactInfo[0].toEmail).toEqual(expect.any(String))
3737
}
3838
})
3939

test/integration/contact/ContactRepository.test.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('submitContactInfo', () => {
1313
})
1414

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

2424
test('should return ContactDTO when contact info is successfully submitted', async () => {
25-
const contactInfo = await sut.submitContactInfo(testContactDTO)
26-
27-
expect(contactInfo).toBeDefined()
28-
expect(contactInfo[0].fromEmail).toEqual(testContactDTO.fromEmail)
29-
expect(contactInfo[0].subject).toBeDefined()
30-
expect(contactInfo[0].body).toBeDefined()
31-
expect(contactInfo[0].toEmail).toBeDefined()
32-
})
33-
34-
test('should return error if the target id is unexisted', async () => {
35-
const invalidContactDTO: ContactDTO = {
36-
targetId: 0,
37-
subject: '',
38-
body: '',
39-
fromEmail: ''
25+
try {
26+
const contactInfo = await sut.submitContactInfo(testContactDTO)
27+
expect(contactInfo).toBeDefined()
28+
expect(contactInfo[0].fromEmail).toEqual(testContactDTO.fromEmail)
29+
expect(contactInfo[0].subject).toEqual(expect.any(String))
30+
expect(contactInfo[0].body).toEqual(expect.any(String))
31+
expect(contactInfo[0].toEmail).toEqual(expect.any(String))
32+
} catch (error) {
33+
console.error('Error during submission:', error.message, error.response?.data)
34+
throw error
4035
}
41-
const expectedError = new WriteError(`[400] Feedback target object not found`)
42-
await expect(sut.submitContactInfo(invalidContactDTO)).rejects.toThrow(expectedError)
36+
37+
test('should return error if the target id is unexisted', async () => {
38+
const invalidContactDTO: ContactDTO = {
39+
targetId: 0,
40+
subject: '',
41+
body: '',
42+
fromEmail: ''
43+
}
44+
const expectedError = new WriteError(`[400] Feedback target object not found`)
45+
await expect(sut.submitContactInfo(invalidContactDTO)).rejects.toThrow(expectedError)
46+
})
4347
})
4448
})

0 commit comments

Comments
 (0)