-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
81 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use server'; | ||
|
||
import { getCurrentUser } from '@/access/AuthenticationService'; | ||
import { ApiError } from '@/groupings/GroupingsApiResults'; | ||
import { postRequest } from './FetchService'; | ||
|
||
const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL as string; | ||
|
||
export type Feedback = { | ||
name?: string, | ||
email: string, | ||
type: string, | ||
message: string, | ||
exceptionMessage?: string | ||
}; | ||
|
||
export type EmailResult = { | ||
resultCode: string, | ||
recipient: string, | ||
from: string, | ||
subject: string, | ||
text: string | ||
} | ||
|
||
export const sendFeedback = async (feedback: Feedback): Promise<EmailResult & ApiError> => { | ||
const currentUser = await getCurrentUser(); | ||
const endpoint = `${baseUrl}/email/send/feedback`; | ||
return postRequest(endpoint, currentUser.uid, feedback); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import User from '@/access/User'; | ||
import { Feedback, sendFeedback } from '@/services/EmailService'; | ||
import * as AuthenticationService from '@/access/AuthenticationService'; | ||
|
||
const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL as string; | ||
const testUser: User = JSON.parse(process.env.TEST_USER_A as string); | ||
|
||
jest.mock('@/access/AuthenticationService'); | ||
|
||
describe('EmailService', () => { | ||
|
||
const currentUser = testUser; | ||
const headers = { 'current_user': currentUser.uid }; | ||
|
||
beforeAll(() => { | ||
jest.spyOn(AuthenticationService, 'getCurrentUser').mockResolvedValue(testUser); | ||
}); | ||
|
||
describe('sendFeedback', () => { | ||
|
||
const feedback: Feedback = { | ||
name: 'name', | ||
email: 'email', | ||
type: 'type', | ||
message: 'message' | ||
}; | ||
|
||
it('should make a POST request at the correct endpoint', async () => { | ||
await sendFeedback(feedback); | ||
expect(fetch).toHaveBeenCalledWith(`${baseUrl}/email/send/feedback`, { | ||
body: JSON.stringify(feedback), | ||
headers, | ||
method: 'POST' | ||
}); | ||
}); | ||
|
||
}); | ||
}); |