Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production deploy #2655

Merged
merged 5 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe("Create payment send events webhook", () => {
it("returns a 400 if a required value is missing", async () => {
await supertest(app)
.post(ENDPOINT)
.set({ Authorization: process.env.HASURA_PLANX_API_KEY })
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: { somethingElse: "123" } })
.expect(400)
.then((response) =>
Expand All @@ -92,7 +92,7 @@ describe("Create payment send events webhook", () => {

await supertest(app)
.post(ENDPOINT)
.set({ Authorization: process.env.HASURA_PLANX_API_KEY })
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: { sessionId: "123" } })
.expect(200)
.then((response) => {
Expand All @@ -108,7 +108,7 @@ describe("Create payment send events webhook", () => {

await supertest(app)
.post(ENDPOINT)
.set({ Authorization: process.env.HASURA_PLANX_API_KEY })
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send(body)
.expect(200)
.then((response) => {
Expand All @@ -131,7 +131,7 @@ describe("Create payment send events webhook", () => {

await supertest(app)
.post(ENDPOINT)
.set({ Authorization: process.env.HASURA_PLANX_API_KEY })
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send(body)
.expect(500)
.then((response) => {
Expand Down
16 changes: 8 additions & 8 deletions api.planx.uk/modules/send/bops/bops.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe(`sending an application to BOPS`, () => {

await supertest(app)
.post("/bops/southwark")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY })
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: { sessionId: "123" } })
.expect(200)
.then((res) => {
Expand All @@ -115,7 +115,7 @@ describe(`sending an application to BOPS`, () => {
it("throws an error if payload is missing", async () => {
await supertest(app)
.post("/bops/southwark")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY })
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: null })
.expect(400)
.then((res) => {
Expand All @@ -126,7 +126,7 @@ describe(`sending an application to BOPS`, () => {
it("throws an error if team is unsupported", async () => {
await supertest(app)
.post("/bops/unsupported-team")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY })
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: { sessionId: "123" } })
.expect(400)
.then((res) => {
Expand All @@ -150,7 +150,7 @@ describe(`sending an application to BOPS`, () => {

await supertest(app)
.post("/bops/southwark")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY })
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: { sessionId: "previously_submitted_app" } })
.expect(200)
.then((res) => {
Expand Down Expand Up @@ -226,7 +226,7 @@ describe(`sending an application to BOPS v2`, () => {

await supertest(app)
.post("/bops-v2/southwark")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY })
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: { sessionId: "123" } })
.expect(200)
.then((res) => {
Expand All @@ -246,7 +246,7 @@ describe(`sending an application to BOPS v2`, () => {
it("throws an error if payload is missing", async () => {
await supertest(app)
.post("/bops-v2/southwark")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY })
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: null })
.expect(400)
.then((res) => {
Expand All @@ -257,7 +257,7 @@ describe(`sending an application to BOPS v2`, () => {
it("throws an error if team is unsupported", async () => {
await supertest(app)
.post("/bops-v2/unsupported-team")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY })
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: { sessionId: "123" } })
.expect(400)
.then((res) => {
Expand All @@ -281,7 +281,7 @@ describe(`sending an application to BOPS v2`, () => {

await supertest(app)
.post("/bops-v2/southwark")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY })
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: { sessionId: "previously_submitted_app" } })
.expect(200)
.then((res) => {
Expand Down
8 changes: 4 additions & 4 deletions api.planx.uk/modules/send/email/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe(`sending an application by email to a planning office`, () => {
it("succeeds when provided with valid data", async () => {
await supertest(app)
.post("/email-submission/southwark")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY })
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: { sessionId: "123" } })
.expect(200)
.then((res) => {
Expand All @@ -133,7 +133,7 @@ describe(`sending an application by email to a planning office`, () => {
it("errors if the payload body does not include a sessionId", async () => {
await supertest(app)
.post("/email-submission/southwark")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY })
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: { somethingElse: "123" } })
.expect(400)
.then((res) => {
Expand All @@ -160,7 +160,7 @@ describe(`sending an application by email to a planning office`, () => {

await supertest(app)
.post("/email-submission/other-council")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY })
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: { sessionId: "123" } })
.expect(400)
.then((res) => {
Expand All @@ -183,7 +183,7 @@ describe(`sending an application by email to a planning office`, () => {

await supertest(app)
.post("/email-submission/other-council")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY })
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: { sessionId: "123" } })
.expect(500)
.then((res) => {
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/send/uniform/uniform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe(`sending an application to uniform`, () => {
it("errors if the payload body does not include a sessionId", async () => {
await supertest(app)
.post("/uniform/southwark")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY })
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: { somethingElse: "123" } })
.expect(400)
.then((res) => {
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/send/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function logPaymentStatus({
}

// tmp explicit error handling
function reportError(obj: object) {
export function reportError(obj: object) {
if (airbrake) {
airbrake.notify(obj);
return;
Expand Down
20 changes: 20 additions & 0 deletions api.planx.uk/modules/webhooks/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { SanitiseApplicationData } from "./service/sanitiseApplicationData/types";
import { sanitiseApplicationData } from "./service/sanitiseApplicationData";
import { IsCleanJSONBController } from "./service/validateInput/schema";
import { analyzeSessions } from "./service/analyzeSessions";

export const sendSlackNotificationController: SendSlackNotification = async (
_req,
Expand Down Expand Up @@ -146,6 +147,25 @@ export const sanitiseApplicationDataController: SanitiseApplicationData =
}
};

export const analyzeSessionsController: SanitiseApplicationData = async (
_req,
res,
next,
) => {
try {
const { operationFailed, results } = await analyzeSessions();
if (operationFailed) res.status(500);
return res.json(results);
} catch (error) {
return next(
new ServerError({
message: "Failed to update session analytics",
cause: error,
}),
);
}
};

export const isCleanJSONBController: IsCleanJSONBController = async (
_req,
res,
Expand Down
3 changes: 2 additions & 1 deletion api.planx.uk/modules/webhooks/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
createSessionReminderEventController,
sanitiseApplicationDataController,
sendSlackNotificationController,
analyzeSessionsController,
} from "./controller";
import { sendSlackNotificationSchema } from "./service/sendNotification/schema";
import { createPaymentEventSchema } from "./service/paymentRequestEvents/schema";
Expand Down Expand Up @@ -54,7 +55,7 @@ router.post(
"/webhooks/hasura/sanitise-application-data",
sanitiseApplicationDataController,
);

router.post("/webhooks/hasura/analyze-sessions", analyzeSessionsController);
router.post(
"/webhooks/hasura/validate-input/jsonb/clean-html",
validate(isCleanJSONBSchema),
Expand Down
Loading
Loading