Skip to content
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
3 changes: 0 additions & 3 deletions frontend/jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ Object.assign(global, {
*/
createMocks();

// set feature flag
process.env.NEXT_PUBLIC_ENABLE_PROOFING = 'true';

// mock unimplemented scrollIntoView
if (typeof window !== 'undefined') {
window.HTMLElement.prototype.scrollIntoView = jest.fn();
Expand Down
44 changes: 5 additions & 39 deletions frontend/src/__tests__/app/submit-letter-template/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,54 +27,20 @@ const redirectMock = jest.mocked(redirect);
const serverIsFeatureEnabledMock = jest.mocked(serverIsFeatureEnabled);

describe('SubmitLetterTemplatePage', () => {
const OLD_ENV = { ...process.env };

beforeEach(() => {
jest.resetAllMocks();
process.env.NEXT_PUBLIC_ENABLE_PROOFING = 'true';
});

afterAll(() => {
process.env = OLD_ENV;
});

test.each([
{
globalProofing: true,
clientProofing: true,
expectedProofingEnabled: true,
},
{
globalProofing: false,
clientProofing: true,
expectedProofingEnabled: false,
},
{
globalProofing: true,
clientProofing: false,
expectedProofingEnabled: false,
},
{
globalProofing: false,
clientProofing: false,
expectedProofingEnabled: false,
},
])(
'should load page with proofingEnabled $expectedProofingEnabled when global proofing is $globalProofing and client proofing is $clientProofing',
async ({
globalProofing,
clientProofing,
expectedProofingEnabled: proofingEnabled,
}) => {
process.env.NEXT_PUBLIC_ENABLE_PROOFING = String(globalProofing);

test.each([true, false])(
'should load page when client proofing is %s',
async (clientProofingEnabled) => {
getTemplateMock.mockResolvedValue({
...LETTER_TEMPLATE,
createdAt: 'today',
updatedAt: 'today',
});

serverIsFeatureEnabledMock.mockResolvedValueOnce(clientProofing);
serverIsFeatureEnabledMock.mockResolvedValueOnce(clientProofingEnabled);

const page = await SubmitLetterTemplatePage({
params: Promise.resolve({
Expand All @@ -86,7 +52,7 @@ describe('SubmitLetterTemplatePage', () => {
<SubmitLetterTemplate
templateName={LETTER_TEMPLATE.name}
templateId={LETTER_TEMPLATE.id}
proofingEnabled={proofingEnabled}
proofingEnabled={clientProofingEnabled}
/>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ jest.mock('@forms/SubmitTemplate/server-action', () => ({
submitTemplate: '/action',
}));

const OLD_ENV = { ...process.env };

beforeEach(() => {
process.env.NEXT_PUBLIC_ENABLE_PROOFING = 'true';
});

afterAll(() => {
process.env = OLD_ENV;
});

describe('SubmitLetterTemplate component', () => {
it('should render', () => {
const container = render(
Expand All @@ -41,9 +31,7 @@ describe('SubmitLetterTemplate component', () => {
expect(container.asFragment()).toMatchSnapshot();
});

it('should render with proofing flag disabled', () => {
process.env.NEXT_PUBLIC_ENABLE_PROOFING = 'false';

it('should render with client proofing disabled', () => {
const container = render(
<SubmitLetterTemplate
templateId='template-id'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ exports[`SubmitLetterTemplate component should render 1`] = `
</DocumentFragment>
`;

exports[`SubmitLetterTemplate component should render with proofing flag disabled 1`] = `
exports[`SubmitLetterTemplate component should render with client proofing disabled 1`] = `
<DocumentFragment>
<main
class="nhsuk-main-wrapper"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,12 @@ const SubmitLetterTemplatePage = async (props: PageProps) => {
}

const clientProofingEnabled = await serverIsFeatureEnabled('proofing');
const globalProofingEnabled =
process.env.NEXT_PUBLIC_ENABLE_PROOFING === 'true';

const proofingEnabled = clientProofingEnabled && globalProofingEnabled;

return (
<SubmitLetterTemplate
templateName={validatedTemplate.name}
templateId={validatedTemplate.id}
proofingEnabled={proofingEnabled}
proofingEnabled={clientProofingEnabled}
/>
);
};
Expand Down
1 change: 0 additions & 1 deletion infrastructure/terraform/components/app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
| <a name="input_enable_amplify_branch_auto_build"></a> [enable\_amplify\_branch\_auto\_build](#input\_enable\_amplify\_branch\_auto\_build) | Enable automatic building of branches | `bool` | `false` | no |
| <a name="input_enable_cognito_built_in_idp"></a> [enable\_cognito\_built\_in\_idp](#input\_enable\_cognito\_built\_in\_idp) | Enable the use of Cognito as an IDP; CIS2 is prefered | `bool` | `false` | no |
| <a name="input_enable_event_caching"></a> [enable\_event\_caching](#input\_enable\_event\_caching) | Enable caching of events to an S3 bucket | `bool` | `true` | no |
| <a name="input_enable_proofing"></a> [enable\_proofing](#input\_enable\_proofing) | Feature flag for proofing | `string` | `false` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | The name of the tfscaffold environment | `string` | n/a | yes |
| <a name="input_event_delivery_logging"></a> [event\_delivery\_logging](#input\_event\_delivery\_logging) | Enable SNS Event Delivery logging | `bool` | `true` | no |
| <a name="input_event_delivery_logging_success_sample_percentage"></a> [event\_delivery\_logging\_success\_sample\_percentage](#input\_event\_delivery\_logging\_success\_sample\_percentage) | Enable caching of events to an S3 bucket | `number` | `0` | no |
Expand Down
1 change: 0 additions & 1 deletion infrastructure/terraform/components/app/amplify_app.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ resource "aws_amplify_app" "main" {
AMPLIFY_MONOREPO_APP_ROOT = "frontend"
API_BASE_URL = module.backend_api.api_base_url
CSRF_SECRET = aws_ssm_parameter.csrf_secret.value
NEXT_PUBLIC_ENABLE_PROOFING = var.enable_proofing
NEXT_PUBLIC_PROMPT_SECONDS_BEFORE_LOGOUT = 120
NEXT_PUBLIC_TIME_TILL_LOGOUT_SECONDS = 900
NOTIFY_ENVIRONMENT = var.environment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module "backend_api" {

enable_backup = var.destination_vault_arn != null ? true : false

enable_proofing = var.enable_proofing
letter_suppliers = var.letter_suppliers
log_destination_arn = local.log_destination_arn
log_subscription_role_arn = local.acct.log_subscription_role_arn
Expand Down
6 changes: 0 additions & 6 deletions infrastructure/terraform/components/app/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,6 @@ variable "control_plane_bus_arn" {
description = "Data plane event bus arn"
}

variable "enable_proofing" {
type = string
description = "Feature flag for proofing"
default = false
}

variable "observability_account_id" {
type = string
description = "The Observability Account ID that needs access"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ module "backend_api" {
USER_POOL_CLIENT_ID = aws_cognito_user_pool_client.sandbox.id
}

enable_proofing = true
letter_suppliers = {
WTMMOCK = {
email_addresses = [local.sandbox_letter_supplier_mock_recipient]
Expand Down
1 change: 0 additions & 1 deletion infrastructure/terraform/modules/backend-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ No requirements.
| <a name="input_email_domain"></a> [email\_domain](#input\_email\_domain) | Email domain | `string` | n/a | yes |
| <a name="input_enable_backup"></a> [enable\_backup](#input\_enable\_backup) | Enable Backups for the DynamoDB table? | `bool` | `true` | no |
| <a name="input_enable_event_stream"></a> [enable\_event\_stream](#input\_enable\_event\_stream) | Enable DynamoDB streaming to EventBridge | `bool` | `true` | no |
| <a name="input_enable_proofing"></a> [enable\_proofing](#input\_enable\_proofing) | Enable proofing feature flag | `bool` | n/a | yes |
| <a name="input_environment"></a> [environment](#input\_environment) | The name of the tfscaffold environment | `string` | n/a | yes |
| <a name="input_function_s3_bucket"></a> [function\_s3\_bucket](#input\_function\_s3\_bucket) | Name of S3 bucket to upload lambda artefacts to | `string` | n/a | yes |
| <a name="input_group"></a> [group](#input\_group) | The group variables are being inherited from (often synonmous with account short-name) | `string` | n/a | yes |
Expand Down
1 change: 0 additions & 1 deletion infrastructure/terraform/modules/backend-api/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ locals {
CLIENT_CONFIG_SSM_KEY_PREFIX = local.client_ssm_path_prefix
CLIENT_CONFIG_TTL_SECONDS = 900
DEFAULT_LETTER_SUPPLIER = local.default_letter_supplier_name
ENABLE_PROOFING = var.enable_proofing
ENVIRONMENT = var.environment
NODE_OPTIONS = "--enable-source-maps"
REQUEST_PROOF_QUEUE_URL = module.sqs_sftp_upload.sqs_queue_url
Expand Down
5 changes: 0 additions & 5 deletions infrastructure/terraform/modules/backend-api/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ variable "enable_backup" {
default = true
}

variable "enable_proofing" {
type = bool
description = "Enable proofing feature flag"
}

variable "enable_event_stream" {
type = bool
description = "Enable DynamoDB streaming to EventBridge"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ jest.mock('node:crypto');
const templateId = 'abc-def-ghi-jkl-123';
const templatesTableName = 'templates';

const setup = (enableProofing = false) => {
const setup = () => {
const ddbDocClient = mockClient(DynamoDBDocumentClient);

const templateRepository = new TemplateRepository(
ddbDocClient as unknown as DynamoDBDocumentClient,
templatesTableName,
enableProofing
templatesTableName
);

return { templateRepository, mocks: { ddbDocClient } };
Expand Down Expand Up @@ -1456,10 +1455,8 @@ describe('templateRepository', () => {
});

describe('setLetterValidationResult', () => {
describe('when proofing flag is enabled', () => {
const proofingEnabled = true;

const { templateRepository, mocks } = setup(proofingEnabled);
describe('when proofing is enabled for the client', () => {
const { templateRepository, mocks } = setup();

it('should update the templateStatus to PENDING_PROOF_REQUEST, personalisationParameters and csvHeader when template is valid', async () => {
await templateRepository.setLetterValidationResult(
Expand All @@ -1468,7 +1465,7 @@ describe('templateRepository', () => {
true,
['personalisation', 'parameters'],
['csv', 'headers'],
proofingEnabled
true
);

expect(mocks.ddbDocClient).toHaveReceivedCommandWith(UpdateCommand, {
Expand Down Expand Up @@ -1506,7 +1503,7 @@ describe('templateRepository', () => {
false,
[],
[],
proofingEnabled
true
);

expect(mocks.ddbDocClient).toHaveReceivedCommandWith(UpdateCommand, {
Expand Down Expand Up @@ -1534,65 +1531,49 @@ describe('templateRepository', () => {
});
});

describe('when proofing flag is disabled', () => {
test.each([
{
globalProofing: false,
clientProofing: false,
},
{
globalProofing: true,
clientProofing: false,
},
{
globalProofing: false,
clientProofing: true,
},
])(
'updates the templateStatus to NOT_YET_SUBMITTED when global proofing is $globalProofing and client proofing is $clientProofing',
async ({ clientProofing, globalProofing }) => {
const { templateRepository, mocks } = setup(globalProofing);

await templateRepository.setLetterValidationResult(
{ owner: 'template-owner', id: 'template-id' },
'file-version-id',
true,
['personalisation', 'parameters'],
['csv', 'headers'],
clientProofing
);

expect(mocks.ddbDocClient).toHaveReceivedCommandWith(UpdateCommand, {
TableName: 'templates',
Key: { id: 'template-id', owner: 'template-owner' },
UpdateExpression:
'SET #templateStatus = :templateStatus , #updatedAt = :updatedAt , #personalisationParameters = :personalisationParameters , #testDataCsvHeaders = :testDataCsvHeaders',
ConditionExpression:
'#files.#file.#version = :version and not #templateStatus in (:templateStatusDeleted, :templateStatusSubmitted)',
ExpressionAttributeNames: {
'#testDataCsvHeaders': 'testDataCsvHeaders',
'#file': 'pdfTemplate',
'#files': 'files',
'#personalisationParameters': 'personalisationParameters',
'#templateStatus': 'templateStatus',
'#updatedAt': 'updatedAt',
'#version': 'currentVersion',
},
ExpressionAttributeValues: {
':testDataCsvHeaders': ['csv', 'headers'],
':personalisationParameters': ['personalisation', 'parameters'],
':templateStatus': 'NOT_YET_SUBMITTED',
':templateStatusDeleted': 'DELETED',
':templateStatusSubmitted': 'SUBMITTED',
':updatedAt': '2024-12-27T00:00:00.000Z',
':version': 'file-version-id',
},
});
}
);
describe('when proofing is disabled for the client', () => {
test('updates the templateStatus to NOT_YET_SUBMITTED when client proofing is turned off', async () => {
const { templateRepository, mocks } = setup();

await templateRepository.setLetterValidationResult(
{ owner: 'template-owner', id: 'template-id' },
'file-version-id',
true,
['personalisation', 'parameters'],
['csv', 'headers'],
false
);

expect(mocks.ddbDocClient).toHaveReceivedCommandWith(UpdateCommand, {
TableName: 'templates',
Key: { id: 'template-id', owner: 'template-owner' },
UpdateExpression:
'SET #templateStatus = :templateStatus , #updatedAt = :updatedAt , #personalisationParameters = :personalisationParameters , #testDataCsvHeaders = :testDataCsvHeaders',
ConditionExpression:
'#files.#file.#version = :version and not #templateStatus in (:templateStatusDeleted, :templateStatusSubmitted)',
ExpressionAttributeNames: {
'#testDataCsvHeaders': 'testDataCsvHeaders',
'#file': 'pdfTemplate',
'#files': 'files',
'#personalisationParameters': 'personalisationParameters',
'#templateStatus': 'templateStatus',
'#updatedAt': 'updatedAt',
'#version': 'currentVersion',
},
ExpressionAttributeValues: {
':testDataCsvHeaders': ['csv', 'headers'],
':personalisationParameters': ['personalisation', 'parameters'],
':templateStatus': 'NOT_YET_SUBMITTED',
':templateStatusDeleted': 'DELETED',
':templateStatusSubmitted': 'SUBMITTED',
':updatedAt': '2024-12-27T00:00:00.000Z',
':version': 'file-version-id',
},
});
});

it('updates the templateStatus to VALIDATION_FAILED if not valid', async () => {
const { templateRepository, mocks } = setup(false);
const { templateRepository, mocks } = setup();

await templateRepository.setLetterValidationResult(
{ owner: 'template-owner', id: 'template-id' },
Expand Down
8 changes: 3 additions & 5 deletions lambdas/backend-api/src/templates/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ export function createContainer() {

const templateRepository = new TemplateRepository(
ddbDocClient,
config.templatesTableName,
config.enableProofing
config.templatesTableName
);

const letterUploadRepository = new LetterUploadRepository(
Expand Down Expand Up @@ -93,12 +92,11 @@ export const uploadLetterFileRepositoryContainer = () => {
};

export const createTemplateRepositoryContainer = () => {
const { templatesTableName, enableProofing } = loadConfig();
const { templatesTableName } = loadConfig();

const templateRepository = new TemplateRepository(
ddbDocClient,
templatesTableName,
enableProofing
templatesTableName
);

return {
Expand Down
Loading