Skip to content

Commit

Permalink
chore: solve some chore problems, make the code prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
ChengShi-1 committed Dec 18, 2024
1 parent 8f606e3 commit 25e7f52
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/contactInfo/domain/useCases/SubmitContactInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ export class SubmitContactInfo implements UseCase<Contact[]> {
constructor(contactRepository: IContactRepository) {
this.contactRepository = contactRepository
}

/**
* Submits contact information and returns a DTO containing the submitted data.
*
* @param {ContactDTO} contactDTO - The contact information to be submitted.
* @returns {Promise<Contact>} A promise resolving to a ContactDTO.
*/

async execute(contactDTO: ContactDTO): Promise<Contact[]> {
try {
return await this.contactRepository.submitContactInfo(contactDTO)
Expand Down
9 changes: 3 additions & 6 deletions test/functional/contact/SubmitContactInfo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ describe('submitContactInfo', () => {
})

test('should return success result on repository success', async () => {
const subject = 'Data Question'
const fromEmail = '[email protected]'

const contactDTO: ContactDTO = {
targetId: 1,
subject: subject,
subject: 'Data Question',
body: 'Please help me understand your data. Thank you!',
fromEmail: fromEmail
fromEmail: '[email protected]'
}

let contactInfo
Expand All @@ -29,7 +26,7 @@ describe('submitContactInfo', () => {
throw new Error('Contact info should be submitted')
} finally {
expect(contactInfo).toBeDefined()
expect(contactInfo[0].fromEmail).toEqual(fromEmail)
expect(contactInfo[0].fromEmail).toEqual('[email protected]')
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
18 changes: 7 additions & 11 deletions test/integration/contact/ContactRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,13 @@ describe('submitContactInfo', () => {
const sut: ContactRepository = new ContactRepository()

test('should return ContactDTO when contact info is successfully submitted', async () => {
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 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))
})

test('should return error if the target id is unexisted', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/contact/SubmitContactInfo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { WriteError, Contact, ContactDTO } from '../../../src'
import { SubmitContactInfo } from '../../../src/contactInfo/domain/useCases/SubmitContactInfo'
import { IContactRepository } from '../../../src/contactInfo/domain/repositories/IContactRepository'

describe('execute', () => {
describe('execute submit information to contacts', () => {
test('should return a ContactDTO when repository call is successful', async () => {
const fromEmail = '[email protected]'

Expand Down

0 comments on commit 25e7f52

Please sign in to comment.