Skip to content

Commit 53100f3

Browse files
authored
fix: email and proposal download status action logs pages (#1622)
1 parent 4fdf7b8 commit 53100f3

5 files changed

Lines changed: 80 additions & 11 deletions

File tree

apps/backend/src/datasources/StatusActionsDataSource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface StatusActionsDataSource {
1111
getConnectionStatusAction(
1212
workflowConnectionId: number,
1313
statusActionId: number
14-
): Promise<ConnectionHasStatusAction>;
14+
): Promise<ConnectionHasStatusAction | null>;
1515
hasEmailTemplateIdConnectionStatusAction(
1616
emailTemplateId: number
1717
): Promise<boolean>;

apps/backend/src/datasources/postgres/StatusActionsDataSource.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export default class PostgresStatusActionsDataSource
104104
async getConnectionStatusAction(
105105
workflowConnectionId: number,
106106
statusActionId: number
107-
): Promise<ConnectionHasStatusAction> {
107+
): Promise<ConnectionHasStatusAction | null> {
108108
const statusActionRecord: StatusActionRecord &
109109
WorkflowConnectionHasActionsRecord & {
110110
config: typeof StatusActionConfig;
@@ -119,9 +119,12 @@ export default class PostgresStatusActionsDataSource
119119
.first();
120120

121121
if (!statusActionRecord) {
122-
throw new GraphQLError(
123-
`Status action not found ActionId: ${statusActionId} connectionId: ${workflowConnectionId}`
122+
logger.logInfo(
123+
`Status action not found statusActionId: ${statusActionId} workflowConnectionId: ${workflowConnectionId}`,
124+
{}
124125
);
126+
127+
return null;
125128
}
126129

127130
return this.createConnectionStatusActionObject(statusActionRecord);

apps/backend/src/mutations/StatusActionsLogsMutations.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ import 'reflect-metadata';
22
import { container } from 'tsyringe';
33

44
import StatusActionsLogsMutations from './StatusActionsLogsMutations';
5+
import { Tokens } from '../config/Tokens';
56
import { dummyStatusActionsLog } from '../datasources/mockups/StatusActionsLogsDataSource';
67
import { dummyUserOfficerWithRole } from '../datasources/mockups/UserDataSource';
8+
import { StatusActionsDataSource } from '../datasources/StatusActionsDataSource';
9+
import { Rejection } from '../models/Rejection';
710

811
const statusActionsLogsMutations = container.resolve(
912
StatusActionsLogsMutations
@@ -18,4 +21,22 @@ describe('Test Status Actions Logs Mutations', () => {
1821
)
1922
).resolves.toBeTruthy();
2023
});
24+
25+
test('Replaying a status actions log whose connection/action no longer exists should be rejected, not throw', async () => {
26+
const statusActionsDataSource = container.resolve<StatusActionsDataSource>(
27+
Tokens.StatusActionsDataSource
28+
);
29+
const getConnectionStatusActionSpy = jest
30+
.spyOn(statusActionsDataSource, 'getConnectionStatusAction')
31+
.mockResolvedValueOnce(null);
32+
33+
const result = await statusActionsLogsMutations.replayStatusActionsLog(
34+
dummyUserOfficerWithRole,
35+
dummyStatusActionsLog.statusActionsLogId
36+
);
37+
38+
expect(result).toBeInstanceOf(Rejection);
39+
40+
getConnectionStatusActionSpy.mockRestore();
41+
});
2142
});

apps/e2e/cypress/e2e/statusActions.cy.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ let proposal1Id: string;
4444
let proposal2Id: string;
4545
let testEmailTemplate1Id: string;
4646
let testEmailTemplate2Id: string;
47+
let statusActionsConnectionId: number;
4748

4849
context('Status actions tests', () => {
4950
beforeEach(function () {
@@ -783,6 +784,7 @@ context('Status actions tests', () => {
783784
}).then((result) => {
784785
const connection = result.createWorkflowConnection;
785786
if (connection) {
787+
statusActionsConnectionId = connection.id;
786788
cy.setStatusChangingEventsOnConnection({
787789
workflowConnectionId: connection.id,
788790
statusChangingEvents: [PROPOSAL_EVENTS.PROPOSAL_SUBMITTED],
@@ -878,6 +880,32 @@ context('Status actions tests', () => {
878880
});
879881
});
880882

883+
it('User Officer should see status actions logs whose connection configuration was later removed, with replay disabled', () => {
884+
cy.addConnectionStatusActions({
885+
actions: [],
886+
connectionId: statusActionsConnectionId,
887+
workflowId: initialDBData.workflows.defaultWorkflow.id,
888+
});
889+
890+
cy.login('officer');
891+
cy.visit('/');
892+
893+
cy.navigateToStatusActionLogsSubmenu('Email');
894+
895+
cy.finishedLoading();
896+
897+
cy.get('[data-cy="status-actions-logs-table"]')
898+
.find('tbody td')
899+
.filter(':contains("SUCCESSFUL")')
900+
.should('have.length.greaterThan', 0);
901+
902+
cy.get('[data-cy="replay_status_action_icon"]')
903+
.first()
904+
.click({ force: true });
905+
906+
cy.get('[data-cy="confirm-ok"]').should('not.exist');
907+
});
908+
881909
it('User Officer should be able to replay all email status actions in a call', () => {
882910
cy.login('officer');
883911
cy.visit('/');

apps/frontend/src/components/statusActionsLogs/StatusActionsLogsTable.tsx

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ const StatusActionsLogsTable = ({
4848
const [selectedCallName, setSelectedCallName] = useState<string | undefined>(
4949
undefined
5050
);
51-
const ReplayIcon = (): JSX.Element => (
52-
<Replay data-cy="replay_status_action_icon" />
53-
);
5451
const ReplayAllIcon = (): JSX.Element => (
5552
<ReplayCircleFilledIcon data-cy="replay_all_status_action_icon" />
5653
);
@@ -342,11 +339,31 @@ const StatusActionsLogsTable = ({
342339
},
343340
}}
344341
actions={[
345-
{
346-
icon: ReplayIcon,
347-
tooltip: 'Replay status action',
342+
(rowData: StatusActionsLog) => ({
343+
icon: () => (
344+
<Replay
345+
data-cy="replay_status_action_icon"
346+
sx={(theme) => ({
347+
opacity: rowData.connectionStatusAction
348+
? 1
349+
: theme.palette.action.disabledOpacity,
350+
color: rowData.connectionStatusAction
351+
? undefined
352+
: theme.palette.action.disabled,
353+
cursor: rowData.connectionStatusAction
354+
? 'pointer'
355+
: 'not-allowed',
356+
})}
357+
/>
358+
),
359+
tooltip: rowData.connectionStatusAction
360+
? 'Replay status action'
361+
: 'This status action can no longer be replayed',
348362
onClick: (_event: unknown, rowData: unknown): void => {
349363
const statusActionsLog = rowData as StatusActionsLog;
364+
if (!statusActionsLog.connectionStatusAction) {
365+
return;
366+
}
350367
if (statusActionsLog.statusActionsLogId) {
351368
confirm(
352369
() =>
@@ -387,7 +404,7 @@ const StatusActionsLogsTable = ({
387404
)();
388405
}
389406
},
390-
},
407+
}),
391408
{
392409
icon: RefreshIcon,
393410
tooltip: 'Refresh status actions log data',

0 commit comments

Comments
 (0)