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

wip: update digital planning schema types and map to passport #131

Merged
merged 15 commits into from
Sep 29, 2023
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
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 1 addition & 18 deletions src/export/digitalPlanning/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { GraphQLClient } from "graphql-request";

import { Passport } from "../../models/passport";
import { getDocumentTemplateNamesForSession } from "../../requests/document-templates";
import { getSessionById } from "../../requests/session";
import { hasRequiredDataForTemplate } from "../../templates";
import { Passport as IPassport } from "../../types";
import { DigitalPlanning } from "./model";
import { DigitalPlanningDataSchema as DigitalPlanningPayload } from "./schema/types";

Expand All @@ -20,22 +17,8 @@ export async function generateDigitalPlanningPayload(

const passport = new Passport(session.data.passport);

const allTemplateNames = await getDocumentTemplateNamesForSession(
client,
sessionId,
);
const templateNames = allTemplateNames.filter((templateName) =>
hasRequiredDataForTemplate({
templateName,
passport: session.data.passport as Required<IPassport>,
}),
);

const payload = new DigitalPlanning({
return new DigitalPlanning({
sessionId,
passport,
templateNames,
}).getPayload();

return payload;
}
6,910 changes: 6,910 additions & 0 deletions src/export/digitalPlanning/mocks/lawfulDevelopmentCertificate.ts

Large diffs are not rendered by default.

2,658 changes: 2,658 additions & 0 deletions src/export/digitalPlanning/mocks/planningPermission.ts

Large diffs are not rendered by default.

2,255 changes: 2,255 additions & 0 deletions src/export/digitalPlanning/mocks/priorApproval.ts

Large diffs are not rendered by default.

67 changes: 40 additions & 27 deletions src/export/digitalPlanning/model.test.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,51 @@
import { Passport } from "../../models/passport";
import { mockProposedLDCPassportData } from "../oneApp/mocks/passport";
import {
mockLDCESession,
mockLDCPSession,
} from "./mocks/lawfulDevelopmentCertificate";
import { mockPlanningPermissionSession } from "./mocks/planningPermission";
import { mockPriorApprovalSession } from "./mocks/priorApproval";
import { DigitalPlanning } from "./model";

const mockPassport = new Passport({
data: {
...mockProposedLDCPassportData,
const mockPassports = [
{
name: "LDC - Proposed",
data: new Passport({ data: { ...mockLDCPSession.passport } }),
},
});
{
name: "LDC - Existing",
data: new Passport({ data: { ...mockLDCESession.passport } }),
},
{
name: "Prior Approval",
data: new Passport({ data: { ...mockPriorApprovalSession.passport } }),
},
{
name: "Planning Permission",
data: new Passport({ data: { ...mockPlanningPermissionSession.passport } }),
},
];

describe("DigitalPlanning", () => {
describe("getPayload", () => {
it("should return valid payload", () => {
const instance = new DigitalPlanning({
sessionId: "session123",
passport: mockPassport,
templateNames: ["template1", "template2"],
});
mockPassports.forEach((mock) => {
it(`should return valid payload (${mock.name})`, () => {
const instance = new DigitalPlanning({
sessionId: "session123",
passport: mock.data,
});

const payload = instance.getPayload();
const payload = instance.getPayload();

expect(payload).toEqual(instance.payload);
expect(payload).toEqual(instance.payload);
});
});

describe("invalid payloads", () => {
test("missing values", () => {
const instance = new DigitalPlanning({
sessionId: "session123",
passport: mockPassport,
templateNames: ["template1", "template2"],
passport: mockPassports[0].data,
});

// @ts-expect-error - The operand of a 'delete' operator must be optional
Expand All @@ -41,8 +59,7 @@ describe("DigitalPlanning", () => {
test("undefined values", () => {
const instance = new DigitalPlanning({
sessionId: "session123",
passport: mockPassport,
templateNames: ["template1", "template2"],
passport: mockPassports[0].data,
});

// @ts-expect-error - Type 'undefined' is not assignable to type 'Applicant'
Expand All @@ -56,8 +73,7 @@ describe("DigitalPlanning", () => {
test("incorrect types", () => {
const instance = new DigitalPlanning({
sessionId: "session123",
passport: mockPassport,
templateNames: ["template1", "template2"],
passport: mockPassports[0].data,
});

// @ts-expect-error - Type 'number' is not assignable to type 'string'
Expand All @@ -71,8 +87,7 @@ describe("DigitalPlanning", () => {
test("incorrect string format", () => {
const instance = new DigitalPlanning({
sessionId: "session123",
passport: mockPassport,
templateNames: ["template1", "template2"],
passport: mockPassports[0].data,
});

instance.payload.metadata.service.url =
Expand All @@ -86,8 +101,7 @@ describe("DigitalPlanning", () => {
test("incorrect datetime format", () => {
const instance = new DigitalPlanning({
sessionId: "session123",
passport: mockPassport,
templateNames: ["template1", "template2"],
passport: mockPassports[0].data,
});

instance.payload.metadata.session.submittedAt =
Expand All @@ -101,12 +115,11 @@ describe("DigitalPlanning", () => {
test("incorrect enum value", () => {
const instance = new DigitalPlanning({
sessionId: "session123",
passport: mockPassport,
templateNames: ["template1", "template2"],
passport: mockPassports[0].data,
});

// @ts-expect-error Type '"invalid enum"' is not assignable to type '"bar" | "baz" | "boo"'
instance.payload.files[0].foo = "invalid enum";
// @ts-expect-error Type '"invalid enum"' is not assignable to type '"applicant" | "agent" | "proxy"'
instance.payload.data.user.role = "tester";

expect(() => instance.getPayload()).toThrowError(
/Invalid DigitalPlanning payload/,
Expand Down
Loading
Loading