From 93db24b7f7650abac1bb7095026e3a1f367b0c0a Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Mon, 11 Dec 2023 17:52:38 +0100 Subject: refactor(pages): refine Contact page * remove next/router dependency * remove pageTitle since it is defined in MDX * reduce statements by grouping messages * mock response with MSW and add test for sendEmail --- src/services/graphql/mutators/send-email.ts | 31 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'src/services/graphql/mutators/send-email.ts') diff --git a/src/services/graphql/mutators/send-email.ts b/src/services/graphql/mutators/send-email.ts index 45b6fca..82c974b 100644 --- a/src/services/graphql/mutators/send-email.ts +++ b/src/services/graphql/mutators/send-email.ts @@ -1,21 +1,20 @@ -import { fetchGraphQL, getGraphQLUrl } from 'src/utils/helpers'; +import type { Nullable } from '../../../types'; +import { fetchGraphQL, getGraphQLUrl } from '../../../utils/helpers'; -type SentEmail = { - clientMutationId: string; +export type SendEmail = { + clientMutationId: Nullable; message: string; origin: string; replyTo: string; sent: boolean; }; -type SendEmailResponse = { - sendEmail: SentEmail; +export type SendEmailResponse = { + sendEmail: SendEmail; }; -const sendMailMutation = `mutation SendEmail($body: String, $clientMutationId: String, $replyTo: String, $subject: String) { - sendEmail( - input: {body: $body, clientMutationId: $clientMutationId, replyTo: $replyTo, subject: $subject} - ) { +const sendEmailMutation = `mutation SendEmail($input: SendEmailInput!) { + sendEmail(input: $input) { clientMutationId message origin @@ -25,24 +24,24 @@ const sendMailMutation = `mutation SendEmail($body: String, $clientMutationId: S } }`; -export type SendMailInput = { +export type SendEmailInput = { body: string; clientMutationId: string; replyTo: string; - subject: string; + subject?: string; }; /** * Send an email using GraphQL API. * - * @param {SendMailInput} data - The mail data. - * @returns {Promise} The mutation response. + * @param {SendEmailInput} input - The mail input. + * @returns {Promise} The mutation response. */ -export const sendMail = async (data: SendMailInput): Promise => { +export const sendEmail = async (input: SendEmailInput): Promise => { const response = await fetchGraphQL({ - query: sendMailMutation, + query: sendEmailMutation, url: getGraphQLUrl(), - variables: { ...data }, + variables: { input }, }); return response.sendEmail; -- cgit v1.2.3