-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Basic boilerplate for GOSS API endpoint (#3893)
- Loading branch information
1 parent
7c5a73a
commit d37679c
Showing
5 changed files
with
132 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { ServerError } from "../../../errors/serverError.js"; | ||
import type { SendIntegrationController } from "../types.js"; | ||
import { checkGOSSAuditTable, isTeamUsingGOSS, sendToGOSS } from "./service.js"; | ||
|
||
export const sendToGOSSController: SendIntegrationController = async ( | ||
_req, | ||
res, | ||
next, | ||
) => { | ||
const { | ||
payload: { sessionId }, | ||
} = res.locals.parsedReq.body; | ||
const localAuthority = res.locals.parsedReq.params.localAuthority; | ||
|
||
if (!isTeamUsingGOSS(localAuthority)) { | ||
return next( | ||
new ServerError({ | ||
message: `Cannot submit to GOSS. Team "${localAuthority}" does not support this integration.`, | ||
status: 400, | ||
}), | ||
); | ||
} | ||
|
||
const previouslySubmittedApplication = await checkGOSSAuditTable(sessionId); | ||
if (previouslySubmittedApplication) { | ||
return res.status(200).send({ | ||
sessionId, | ||
gossId: previouslySubmittedApplication.id, | ||
message: "Skipping send, already successfully submitted", | ||
}); | ||
} | ||
|
||
const application = await sendToGOSS(sessionId); | ||
|
||
return res.status(200).send({ | ||
message: "Successfully submitted GOSS application", | ||
application, | ||
}); | ||
}; |
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 supertest from "supertest"; | ||
import app from "../../../server.js"; | ||
|
||
it("requires auth", async () => { | ||
await supertest(app) | ||
.post("/goss/west-berkshire") | ||
.send({ payload: { sessionId: "37e3649b-4854-4249-a5c3-7937c1b952b9" } }) | ||
.expect(401); | ||
}); | ||
|
||
it("throws an error if payload is missing", async () => { | ||
await supertest(app) | ||
.post("/goss/west-berkshire") | ||
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! }) | ||
.send({ payload: null }) | ||
.expect(400) | ||
.then((res) => { | ||
expect(res.body).toHaveProperty("issues"); | ||
expect(res.body).toHaveProperty("name", "ZodError"); | ||
}); | ||
}); | ||
|
||
it("throws an error if team is unsupported", async () => { | ||
await supertest(app) | ||
.post("/goss/unsupported-team") | ||
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! }) | ||
.send({ payload: { sessionId: "37e3649b-4854-4249-a5c3-7937c1b952b9" } }) | ||
.expect(400) | ||
.then((res) => { | ||
expect(res.body.error).toMatch( | ||
/Cannot submit to GOSS. Team "unsupported-team" does not support this integration./, | ||
); | ||
}); | ||
}); | ||
|
||
it.todo("does not re-send an application which has already been submitted"); | ||
it.todo("creates an audit record after submitting"); | ||
it.todo("returns a success upon completion"); |
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,28 @@ | ||
import { markSessionAsSubmitted } from "../../saveAndReturn/service/utils.js"; | ||
|
||
export const isTeamUsingGOSS = (team: string) => { | ||
// TODO: Query db for this | ||
const GOSS_TEAMS = ["west-berkshire"]; | ||
return GOSS_TEAMS.includes(team); | ||
}; | ||
|
||
export const createGOSSApplicationAuditRecord = async () => { | ||
console.log("TODO: Create audit record"); | ||
}; | ||
|
||
export const checkGOSSAuditTable = async (sessionId: string) => { | ||
console.log("TODO: Check GOSS audit table"); | ||
return { | ||
id: "abc123", | ||
}; | ||
}; | ||
|
||
export const sendToGOSS = async (sessionId: string) => { | ||
const applicationData = {}; | ||
// TODO: Post payload to GOSS | ||
|
||
await createGOSSApplicationAuditRecord(); | ||
await markSessionAsSubmitted(sessionId); | ||
|
||
return applicationData; | ||
}; |
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