Skip to content

Commit

Permalink
fix: Get session by pk for public client (with headers)
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Nov 1, 2023
1 parent 5c545c0 commit c1746ca
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 33 deletions.
46 changes: 22 additions & 24 deletions api.planx.uk/saveAndReturn/validateSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ async function diffLatestPublishedFlow({
return response.diff_latest_published_flow.data;
}

interface FindSession {
session: Partial<LowCalSession> | null;
}

async function findSession({
sessionId,
email,
Expand All @@ -235,32 +239,26 @@ async function findSession({
email: string;
}): Promise<Partial<LowCalSession> | undefined> {
const headers = getSaveAndReturnPublicHeaders(sessionId, email);
const response: { lowcal_sessions: Partial<LowCalSession>[] } =
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 $public.client.request<FindSession>(
gql`
query FindSession($sessionId: uuid!) {
session: lowcal_sessions_by_pk(id: $sessionId) {
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 },
headers,
);
return response.session ?? undefined;
}

async function createAuditEntry(
Expand Down
16 changes: 7 additions & 9 deletions api.planx.uk/tests/mocks/saveAndReturnMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,13 @@ export const mockLowcalSession: LowCalSession = {
export const mockFindSession = (breadcrumbs = {}) => ({
name: "FindSession",
data: {
lowcal_sessions: [
{
...mockLowcalSession,
data: {
...mockLowcalSession.data,
breadcrumbs,
},
session: {
...mockLowcalSession,
data: {
...mockLowcalSession.data,
breadcrumbs,
},
],
},
},
variables: {
sessionId: mockLowcalSession.id,
Expand All @@ -92,7 +90,7 @@ export const mockFindSession = (breadcrumbs = {}) => ({
export const mockNotFoundSession = {
name: "FindSession",
data: {
lowcal_sessions: [],
session: null,
},
variables: {
sessionId: "not-found-id",
Expand Down

0 comments on commit c1746ca

Please sign in to comment.