Skip to content

Commit

Permalink
Merge branch 'development' of github.com:Brain-Defrost/Brain-Defrost_…
Browse files Browse the repository at this point in the history
…FE into development
  • Loading branch information
EthanDuvall committed Jun 7, 2024
2 parents aa46795 + 2692227 commit a7580d6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 24 deletions.
11 changes: 6 additions & 5 deletions cypress/e2e/GamePlay.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,19 @@ describe('Brain Defrost GamePlay Stories', () => {
statusCode: 200,
fixture: 'gameStats'
}).as('getStats')
//stub email address post request
cy.intercept('POST', 'https://brain-defrost-f8afea5ead0a.herokuapp.com/api/v1/games/1/stats/email',
{
statusCode: 200,
body: ''
}).as('postEmail')
cy.visit('http://localhost:3000/game/results/1')
.get('.send-stats-btn').contains('Send Me The Stats').click()
.get('.form-message').contains('Send me those stats!')
.get('label[for=email]').contains('Enter your Email Address')
.get('#email').should('have.value', '').type('[email protected]').should('have.value', '[email protected]')
.get('.submit-btn').click()
//check that confirmation message is displayed
.get('.form-message').contains('Check your email for the stats!')
.get('.close-btn').click()
.get('.form-modal').should('not.exist')
})
// it('Allows non-creator player to play game', () => {

// })
})
8 changes: 1 addition & 7 deletions src/components/SendStatsForm/SendStatsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@ function SendStatsForm({closeForm, gameId}: Props) {
const [succesfulSubmission, setSuccessfulSubmission] = useState<boolean | null>(null);

const submitEmail = async () => {
const requestBody = {
email: emailInput,
gameId
};
console.log({requestBody})
try {
const response = await postEmail(requestBody.gameId, requestBody);
console.log(response)
await postEmail(gameId, emailInput);
setSuccessfulSubmission(true)
} catch (error) {
setSuccessfulSubmission(false)
Expand Down
2 changes: 1 addition & 1 deletion src/components/Stats/Stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function Stats() {
<button className='send-stats-btn' onClick={showForm}>Send Me The Stats</button>
<button className='new-game-btn' onClick={goHome}>Generate A New Game</button>
</div>
{openDialoge && <SendStatsForm closeForm={closeForm} gameId={finalStats?.data.id}/>}
{openDialoge && <SendStatsForm closeForm={closeForm} gameId={gameid}/>}
</div>
);
}
Expand Down
14 changes: 8 additions & 6 deletions src/components/Util/fetchCalls.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CreateGameRequest, EmailRequestBody } from "./interfaces";
import type { CreateGameRequest } from "./interfaces";

const getGame = async (gameID: string) => {
try {
Expand Down Expand Up @@ -188,13 +188,15 @@ const patchGame = async (gameID: string | undefined) => {
}
};

const postEmail = async (gameID: string | undefined, requestBody: EmailRequestBody) => {
const postEmail = async (gameID: string | undefined, email: string | undefined) => {
try {
const response = await fetch(
`endpoint/${gameID}`,
`https://brain-defrost-f8afea5ead0a.herokuapp.com/api/v1/games/${gameID}/stats/email`,
{
method: "PATCH",
body: JSON.stringify(requestBody),
method: "POST",
body: JSON.stringify({
email: email
}),
headers: {
"Content-Type": "application/json",
},
Expand All @@ -205,7 +207,7 @@ const postEmail = async (gameID: string | undefined, requestBody: EmailRequestBo
console.log(status);
throw new Error(`Couldn't send email - ${status}`);
}
return await response.json();
// return await response.json();
} catch (error: unknown) {
console.log("API CALLS catch block - email stats", error);
throw error;
Expand Down
5 changes: 0 additions & 5 deletions src/components/Util/interfaces.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,4 @@ export interface Question {
};
}

export interface EmailRequestBody {
email: string | undefined;
gameId: string | undefined;
}

export {}

0 comments on commit a7580d6

Please sign in to comment.