From 6ed792ac2a2ac96da588904817709b727718ec60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Wed, 1 Nov 2023 17:48:47 +0000 Subject: [PATCH] fix: FindSession --- api.planx.uk/saveAndReturn/validateSession.ts | 52 +++++++++---------- .../tests/mocks/saveAndReturnMocks.ts | 4 +- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/api.planx.uk/saveAndReturn/validateSession.ts b/api.planx.uk/saveAndReturn/validateSession.ts index 739075ac0e..13c107d105 100644 --- a/api.planx.uk/saveAndReturn/validateSession.ts +++ b/api.planx.uk/saveAndReturn/validateSession.ts @@ -15,8 +15,7 @@ import type { PublishedFlow, Node, } from "../types"; -import { $api, $public, getClient } from "../client"; -import { getSaveAndReturnPublicHeaders } from "./utils"; +import { $api, getClient } from "../client"; export interface ValidationResponse { message: string; @@ -227,6 +226,10 @@ async function diffLatestPublishedFlow({ return response.diff_latest_published_flow.data; } +interface FindSession { + sessions: Partial[]; +} + async function findSession({ sessionId, email, @@ -234,33 +237,28 @@ async function findSession({ sessionId: string; email: string; }): Promise | undefined> { - const headers = getSaveAndReturnPublicHeaders(sessionId, email); - const response: { lowcal_sessions: Partial[] } = - await $public.client.request( - gql` - query FindSession($sessionId: uuid!, $email: String!) { - lowcal_sessions( - where: { id: { _eq: $sessionId }, email: { _eq: $email } } - limit: 1 - ) { - flow_id - data - updated_at - lockedAt: locked_at - paymentRequests: payment_requests { - id - payeeName: payee_name - payeeEmail: payee_email - } + const response = await $api.client.request( + gql` + query FindSession($sessionId: uuid!, $email: String!) { + sessions: lowcal_sessions( + where: { id: { _eq: $sessionId }, email: { _eq: $email } } + limit: 1 + ) { + flow_id + data + updated_at + lockedAt: locked_at + paymentRequests: payment_requests { + id + payeeName: payee_name + payeeEmail: payee_email } } - `, - { sessionId, email }, - headers, - ); - return response.lowcal_sessions.length - ? response.lowcal_sessions[0] - : undefined; + } + `, + { sessionId, email }, + ); + return response.sessions.length ? response.sessions[0] : undefined; } async function createAuditEntry( diff --git a/api.planx.uk/tests/mocks/saveAndReturnMocks.ts b/api.planx.uk/tests/mocks/saveAndReturnMocks.ts index 75604b7b92..aa0877cd86 100644 --- a/api.planx.uk/tests/mocks/saveAndReturnMocks.ts +++ b/api.planx.uk/tests/mocks/saveAndReturnMocks.ts @@ -73,7 +73,7 @@ export const mockLowcalSession: LowCalSession = { export const mockFindSession = (breadcrumbs = {}) => ({ name: "FindSession", data: { - lowcal_sessions: [ + sessions: [ { ...mockLowcalSession, data: { @@ -92,7 +92,7 @@ export const mockFindSession = (breadcrumbs = {}) => ({ export const mockNotFoundSession = { name: "FindSession", data: { - lowcal_sessions: [], + sessions: [], }, variables: { sessionId: "not-found-id",