Skip to content

Commit

Permalink
Fix issues affecting the pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
j-maynard committed Dec 10, 2024
1 parent e01dcc2 commit 9b0d4d2
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/@types/express-session/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'express-session';
import { ViewErrDTO } from '../../dtos/view-dto';
import { DimensionPatchDto } from '../../dtos/dimension-patch-dto';
import { ViewError } from '../../dtos/view-error';

declare module 'express-session' {
interface SessionData {
errors: ViewErrDTO | undefined;
errors: ViewError[] | undefined;
dimensionPatch: DimensionPatchDto | undefined;
}
}
24 changes: 13 additions & 11 deletions src/controllers/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,13 +639,14 @@ export const periodReview = async (req: Request, res: Response, next: NextFuncti
status: error.status || 500,
errors: [
{
tag: {
name: 'errors.dimension_reset'
field: '',
message: {
key: 'errors.dimension_reset'
}
}
],
dataset_id: req.params.datasetId
};
} as ViewErrDTO;
}
break;
}
Expand Down Expand Up @@ -686,8 +687,8 @@ export const dimensionName = async (req: Request, res: Response, next: NextFunct
errors: [
{
field: 'name',
tag: {
name: 'errors.no_name'
message: {
key: 'errors.no_name'
}
}
],
Expand All @@ -704,8 +705,8 @@ export const dimensionName = async (req: Request, res: Response, next: NextFunct
errors: [
{
field: 'name',
tag: {
name: 'errors.dimension.name_to_long'
message: {
key: 'errors.dimension.name_to_long'
}
}
],
Expand All @@ -721,8 +722,8 @@ export const dimensionName = async (req: Request, res: Response, next: NextFunct
errors: [
{
field: 'name',
tag: {
name: 'errors.dimension.name_to_short'
message: {
key: 'errors.dimension.name_to_short'
}
}
],
Expand All @@ -747,8 +748,9 @@ export const dimensionName = async (req: Request, res: Response, next: NextFunct
status: error.status || 500,
errors: [
{
tag: {
name: 'errors.dimension.naming_failed'
field: '',
message: {
key: 'errors.dimension.naming_failed'
}
}
],
Expand Down
1 change: 1 addition & 0 deletions src/dtos/dimension-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import { TaskStatus } from '../enums/task-status';
export interface DimensionState {
name: string;
status: TaskStatus;
type: string;
}
5 changes: 3 additions & 2 deletions src/services/stats-wales-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ export class StatsWalesApi {
return fetch(`${this.backendUrl}/${url}`, { method, headers: head, body: data })
.then(async (response: Response) => {
if (!response.ok) {
if (response.body) {
const body = await new Response(response.body).text();
if (body) {
throw new ApiException(response.statusText, response.status, body);
}
throw new ApiException(response.statusText, response.status, body);
throw new ApiException(response.statusText, response.status);
}
return response;
})
Expand Down
17 changes: 11 additions & 6 deletions src/validators/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable prettier/prettier */

import { Request } from 'express';
import { body, FieldValidationError, param, ValidationChain } from 'express-validator';
import { ResultWithContext } from 'express-validator/lib/chain/context-runner';
Expand Down Expand Up @@ -42,10 +40,17 @@ export const datasetIdValidator = () => param('datasetId').trim().notEmpty().isU
export const revisionIdValidator = () => param('revisionId').trim().notEmpty().isUUID(4);
export const factTableIdValidator = () => param('factTableId').trim().notEmpty().isUUID(4);

export const titleValidator = () => body('title').trim()
.notEmpty().withMessage('missing').bail()
.isLength({ min: 3 }).withMessage('too_short').bail()
.isLength({ max: 1000 }).withMessage('too_long');
export const titleValidator = () =>
body('title')
.trim()
.notEmpty()
.withMessage('missing')
.bail()
.isLength({ min: 3 })
.withMessage('too_short')
.bail()
.isLength({ max: 1000 })
.withMessage('too_long');

export const descriptionValidator = () => body('description').trim().notEmpty();
export const collectionValidator = () => body('collection').trim().notEmpty();
Expand Down
2 changes: 1 addition & 1 deletion src/views/publish/tasklist.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<% const dim = locals.dimensions.find((d) => d.dimensionInfo.name === dimension.name) %>
<li class="govuk-task-list__item govuk-task-list__item--with-link">
<div class="govuk-task-list__name-and-hint">
<% if (dim.type === 'time_period') { %>
<% if (dimension.type === 'time_period') { %>
<a class="govuk-link govuk-task-list__link" href="<%= buildUrl(`/publish/${locals.datasetId}/time-period/${dim.id}`, i18n.language) %>"><%= dimension.name %></a>
<% } else { %>
<a class="govuk-link govuk-task-list__link" href="<%= buildUrl(`/publish/${locals.datasetId}/dimension-data-chooser/${dim.id}`, i18n.language) %>"><%= dimension.name %></a>
Expand Down
2 changes: 1 addition & 1 deletion test/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('Publisher Journey Tests', () => {
test('Publish title page returns 400 if no title is provided', async () => {
const res = await request(app).post('/en-GB/publish/title');
expect(res.status).toBe(400);
expect(res.text).toContain(t('errors.title.missing'));
expect(res.text).toContain(t('publish.title.form.title.error.missing'));
});

test('Set title returns 302 and directs the user to the upload page', async () => {
Expand Down

0 comments on commit 9b0d4d2

Please sign in to comment.