|
| 1 | +import { ContactRepository } from '../../../src/contactInfo/infra/repositories/ContactRepository' |
| 2 | +import { ApiConfig, Contact, ContactDTO, WriteError } from '../../../src' |
| 3 | +import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig' |
| 4 | +import { TestConstants } from '../../testHelpers/TestConstants' |
| 5 | + |
| 6 | +describe('submitContactInfo', () => { |
| 7 | + beforeAll(async () => { |
| 8 | + ApiConfig.init( |
| 9 | + TestConstants.TEST_API_URL, |
| 10 | + DataverseApiAuthMechanism.API_KEY, |
| 11 | + process.env.TEST_API_KEY |
| 12 | + ) |
| 13 | + }) |
| 14 | + |
| 15 | + const testContactDTO: ContactDTO = { |
| 16 | + targetId: 6, |
| 17 | + subject: 'Data Question', |
| 18 | + body: 'Please help me understand your data. Thank you!', |
| 19 | + |
| 20 | + } |
| 21 | + |
| 22 | + const sut: ContactRepository = new ContactRepository() |
| 23 | + |
| 24 | + test('should return ContactDTO when contact info is successfully submitted', async () => { |
| 25 | + const collectionAlias = 'collection-1' |
| 26 | + |
| 27 | + const baseUrl = 'http://localhost:8080/dataverse/' |
| 28 | + const bodyMessage = |
| 29 | + 'You have just been sent the following message from ' + |
| 30 | + testContactDTO.fromEmail + |
| 31 | + ' via the Root hosted dataverse named "' + |
| 32 | + collectionAlias + |
| 33 | + '":\n' + |
| 34 | + '\n' + |
| 35 | + '---\n' + |
| 36 | + '\n' + |
| 37 | + 'Please help me understand your data. Thank you!\n' + |
| 38 | + '\n' + |
| 39 | + '---\n' + |
| 40 | + '\n' + |
| 41 | + 'Root Support\n' + |
| 42 | + 'null\n' + |
| 43 | + '\n' + |
| 44 | + 'Go to dataverse ' + |
| 45 | + baseUrl + |
| 46 | + collectionAlias + |
| 47 | + '\n' + |
| 48 | + '\n' + |
| 49 | + 'You received this email because you have been listed as a contact for the dataverse. If you believe this was an error, please contact Root Support at null. To respond directly to the individual who sent the message, simply reply to this email.' |
| 50 | + |
| 51 | + const expectedResponse: Contact[] = [ |
| 52 | + { |
| 53 | + fromEmail: testContactDTO.fromEmail, |
| 54 | + toEmail: collectionEmail, |
| 55 | + subject: 'Root contact: ' + testContactDTO.subject, |
| 56 | + body: bodyMessage |
| 57 | + } |
| 58 | + ] |
| 59 | + const actual = await sut.submitContactInfo(testContactDTO) |
| 60 | + expect(actual).toEqual(expectedResponse) |
| 61 | + }) |
| 62 | + |
| 63 | + test('should return error if the target id is unexisted', async () => { |
| 64 | + const invalidContactDTO: ContactDTO = { |
| 65 | + targetId: 0, |
| 66 | + subject: '', |
| 67 | + body: '', |
| 68 | + fromEmail: '' |
| 69 | + } |
| 70 | + const expectedError = new WriteError(`[400] Feedback target object not found`) |
| 71 | + await expect(sut.submitContactInfo(invalidContactDTO)).rejects.toThrow(expectedError) |
| 72 | + }) |
| 73 | +}) |
0 commit comments