11import { WriteError , Contact , ContactDTO } from '../../../src'
22import { SubmitContactInfo } from '../../../src/contactInfo/domain/useCases/SubmitContactInfo'
33import { IContactRepository } from '../../../src/contactInfo/domain/repositories/IContactRepository'
4+ import { TestConstants } from '../../testHelpers/TestConstants'
45
56describe ( 'execute submit information to contacts' , ( ) => {
67 test ( 'should return a Contact when repository call is successful' , async ( ) => {
7- const fromEmail = '1314 @gmail.com'
8+ const fromEmail = 'example @gmail.com'
89
910 const contactDTO : ContactDTO = {
1011 targetId : 6 ,
@@ -14,8 +15,7 @@ describe('execute submit information to contacts', () => {
1415 }
1516
1617 const collectionAlias = 'collection-1'
17- 18- const baseUrl = 'http://localhost:8080/dataverse/'
18+ const baseUrl = TestConstants . TEST_API_URL + '/dataverse/'
1919 const bodyMessage =
2020 'You have just been sent the following message from ' +
2121 fromEmail +
@@ -42,7 +42,6 @@ describe('execute submit information to contacts', () => {
4242 const expectedResponse : Contact [ ] = [
4343 {
4444 fromEmail : contactDTO . fromEmail ,
45- toEmail : collectionEmail ,
4645 subject : 'Root contact: ' + contactDTO . subject ,
4746 body : bodyMessage
4847 }
@@ -57,7 +56,37 @@ describe('execute submit information to contacts', () => {
5756 expect ( contactRepositoryStub . submitContactInfo ) . toHaveBeenCalledWith ( contactDTO )
5857 } )
5958
60- test ( 'should return error result on error response' , async ( ) => {
59+ test ( 'should return a Contact when targetId is not provided' , async ( ) => {
60+ const fromEmail = '[email protected] ' 61+
62+ const contactDTO : ContactDTO = {
63+ subject : 'Data Question' ,
64+ body : 'Please help me understand your data. Thank you!' ,
65+ fromEmail : fromEmail
66+ }
67+
68+ const bodyMessage =
69+ 'Root Support,\n\nThe following message was sent from ' +
70+ fromEmail +
71+ '.\n\n---\n\nPlease help me understand your data. Thank you!\n\n---\n\nMessage sent from Support contact form.'
72+ const expectedResponse : Contact [ ] = [
73+ {
74+ fromEmail : contactDTO . fromEmail ,
75+ subject : 'Root Support Request: ' + contactDTO . subject ,
76+ body : bodyMessage
77+ }
78+ ]
79+
80+ const contactRepositoryStub = < IContactRepository > { }
81+
82+ contactRepositoryStub . submitContactInfo = jest . fn ( ) . mockResolvedValue ( expectedResponse )
83+ const sut = new SubmitContactInfo ( contactRepositoryStub )
84+ const actual = await sut . execute ( contactDTO )
85+ expect ( actual ) . toEqual ( expectedResponse )
86+ expect ( contactRepositoryStub . submitContactInfo ) . toHaveBeenCalledWith ( contactDTO )
87+ } )
88+
89+ test ( 'should return error result once there is a invalid targetId' , async ( ) => {
6190 const contactDTO : ContactDTO = {
6291 targetId : 0 ,
6392 subject : '' ,
0 commit comments