From e78724266396cf4bbc28235a099fb45ac22af2d3 Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Mon, 30 Sep 2024 10:44:55 +0200 Subject: [PATCH] Add e2e tests for pno form sent message list --- ...dummy_prior_notification_sent_messages.sql | 53 +++++++++++++------ .../error_handling.spec.ts | 29 +++++++++- .../sent_message_list.spec.ts | 41 ++++++++++++++ 3 files changed, 106 insertions(+), 17 deletions(-) create mode 100644 frontend/cypress/e2e/side_window/logbook_prior_notification_form/sent_message_list.spec.ts diff --git a/backend/src/main/resources/db/testdata/V666.29__Insert_dummy_prior_notification_sent_messages.sql b/backend/src/main/resources/db/testdata/V666.29__Insert_dummy_prior_notification_sent_messages.sql index 9ee37fbbcb..aa19f07e2f 100644 --- a/backend/src/main/resources/db/testdata/V666.29__Insert_dummy_prior_notification_sent_messages.sql +++ b/backend/src/main/resources/db/testdata/V666.29__Insert_dummy_prior_notification_sent_messages.sql @@ -1,18 +1,39 @@ INSERT INTO public.prior_notification_sent_messages ( - prior_notification_report_id, prior_notification_source, date_time_utc, communication_means, recipient_address_or_number, success, error_message, recipient_name, recipient_organization + prior_notification_report_id, prior_notification_source, date_time_utc, communication_means, recipient_address_or_number, success, error_message, recipient_name, recipient_organization ) VALUES - ( 'FAKE_OPERATION_103', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '2 minutes', 'EMAIL', 'bgc-lorient@douane.finances.gouv.fr', TRUE, NULL, 'Unité 1', 'Douane'), - ( 'FAKE_OPERATION_106', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '2 minutes', 'EMAIL', 'sgcd-nantes-codm@douane.finances.gouv.fr', TRUE, NULL, 'Unité 1', 'Douane'), - ( 'FAKE_OPERATION_106', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '2 minutes', 'EMAIL', 'bsl.lorient@gendarmerie.defense.gouv.fr', TRUE, NULL, 'Unité 3', 'Gendarmerie'), - ( 'FAKE_OPERATION_108', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '2 minutes', 'EMAIL', 'ggmaratlan@gendarmerie.defense.gouv.fr', FALSE, NULL, 'Unité 4', 'Gendarmerie'), - ( 'FAKE_OPERATION_108', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '2 minutes', 'EMAIL', 'pgmarc720.lorient@gendarmerie.defense.gouv.fr', FALSE, NULL, 'Unité 3', 'Gendarmerie'), - ( 'FAKE_OPERATION_110', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '2 minutes', 'EMAIL', 'ddtm-samel@morbihan.gouv.fr', TRUE, NULL, 'Unité 6', 'DDTM'), - ( 'FAKE_OPERATION_110', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '2 minutes', 'EMAIL', 'sd56@ofb.gouv.fr', FALSE, NULL, 'Unité 7', 'Office Français de la Biodiversité'), - ( 'FAKE_OPERATION_110', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '2 minutes', 'SMS', '+33123456789', FALSE, NULL, 'Unité 7', 'Office Français de la Biodiversité'), - ('00000000-0000-4000-0000-000000000003', 'MANUAL', NOW() AT TIME ZONE 'UTC' - INTERVAL '2 minutes', 'EMAIL', 'ddtm-pre@morbihan.gouv.fr', TRUE, NULL, 'Unité 9', 'DDTM'), - ('00000000-0000-4000-0000-000000000003', 'MANUAL', NOW() AT TIME ZONE 'UTC' - INTERVAL '2 minutes', 'EMAIL', 'namo@example.gouv.fr', FALSE, NULL, 'Unité 10', 'DIRM / DM'), - ('00000000-0000-4000-0000-000000000004', 'MANUAL', NOW() AT TIME ZONE 'UTC' - INTERVAL '2 minutes', 'EMAIL', 'dreal@example.gouv.fr', FALSE, NULL, 'Unité 11', 'DDTM'), - ('00000000-0000-4000-0000-000000000006', 'MANUAL', NOW() AT TIME ZONE 'UTC' - INTERVAL '2 minutes', 'EMAIL', 'ddtm-ulam@morbihan.gouv.fr', TRUE, NULL, 'Unité 11', 'DDTM'), - ('00000000-0000-4000-0000-000000000008', 'MANUAL', NOW() AT TIME ZONE 'UTC' - INTERVAL '2 minutes', 'EMAIL', 'dirm@example.gouv.fr', FALSE, NULL, 'Unité 12', 'DIRM / DM'), - ('00000000-0000-4000-0000-000000000010', 'MANUAL', NOW() AT TIME ZONE 'UTC' - INTERVAL '2 minutes', 'EMAIL', 'pam-jeanne-barret.dirm-memn@developpement-durable.gouv.fr', TRUE, NULL, 'Unité 12', 'DIRM / DM'); - \ No newline at end of file + ( 'FAKE_OPERATION_103', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '2.0 minutes', 'EMAIL', 'bgc-lorient@douane.finances.gouv.fr', TRUE, NULL, 'Unité 1', 'Douane'), + + ( 'FAKE_OPERATION_106', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '2.0 minutes', 'EMAIL', 'sgcd-nantes-codm@douane.finances.gouv.fr', TRUE, NULL, 'Unité 1', 'Douane'), + ( 'FAKE_OPERATION_106', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '2.0 minutes', 'EMAIL', 'bsl.lorient@gendarmerie.defense.gouv.fr', TRUE, NULL, 'Unité 3', 'Gendarmerie'), + + ( 'FAKE_OPERATION_108', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '2.3 minutes', 'EMAIL', 'pgmarc720.lorient@gendarmerie.defense.gouv.fr', FALSE, NULL, 'Unité 3', 'Gendarmerie'), + ( 'FAKE_OPERATION_108', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '2.0 minutes', 'EMAIL', 'ggmaratlan@gendarmerie.defense.gouv.fr', FALSE, NULL, 'Unité 4', 'Gendarmerie'), + ( 'FAKE_OPERATION_108', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '2.1 minutes', 'SMS', '+33123456789', FALSE, NULL, 'Unité 3', 'Gendarmerie'), + ( 'FAKE_OPERATION_108', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '2.2 minutes', 'SMS', '+33987654321', FALSE, NULL, 'Unité 4', 'Gendarmerie'), + + ( 'FAKE_OPERATION_108', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '4.0 minutes', 'EMAIL', 'pgmarc720.lorient@gendarmerie.defense.gouv.fr', FALSE, NULL, 'Unité 3', 'Gendarmerie'), + ( 'FAKE_OPERATION_108', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '4.1 minutes', 'EMAIL', 'ggmaratlan@gendarmerie.defense.gouv.fr', TRUE, NULL, 'Unité 4', 'Gendarmerie'), + ( 'FAKE_OPERATION_108', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '4.2 minutes', 'EMAIL', 'unite5@ddtm-40.gouv.fr', FALSE, NULL, 'Unité 5', 'DDTM 40'), + ( 'FAKE_OPERATION_108', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '4.3 minutes', 'SMS', '+33123456789', TRUE, NULL, 'Unité 3', 'Gendarmerie'), + ( 'FAKE_OPERATION_108', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '4.4 minutes', 'SMS', '+33987654321', FALSE, NULL, 'Unité 4', 'Gendarmerie'), + ( 'FAKE_OPERATION_108', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '4.5 minutes', 'SMS', '+33000000000', FALSE, NULL, 'Unité 5', 'DDTM 40'), + + ( 'FAKE_OPERATION_108', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '9.3 minutes', 'EMAIL', 'pgmarc720.lorient@gendarmerie.defense.gouv.fr', TRUE, NULL, 'Unité 3', 'Gendarmerie'), + ( 'FAKE_OPERATION_108', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '9.2 minutes', 'EMAIL', 'ggmaratlan@gendarmerie.defense.gouv.fr', TRUE, NULL, 'Unité 4', 'Gendarmerie'), + ( 'FAKE_OPERATION_108', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '9.1 minutes', 'SMS', '+33123456789', TRUE, NULL, 'Unité 3', 'Gendarmerie'), + ( 'FAKE_OPERATION_108', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '9.0 minutes', 'SMS', '+33987654321', TRUE, NULL, 'Unité 4', 'Gendarmerie'), + + ( 'FAKE_OPERATION_110', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '2.0 minutes', 'EMAIL', 'ddtm-samel@morbihan.gouv.fr', TRUE, NULL, 'Unité 6', 'DDTM'), + ( 'FAKE_OPERATION_110', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '2.0 minutes', 'EMAIL', 'sd56@ofb.gouv.fr', FALSE, NULL, 'Unité 7', 'Office Français de la Biodiversité'), + ( 'FAKE_OPERATION_110', 'LOGBOOK', NOW() AT TIME ZONE 'UTC' - INTERVAL '2.0 minutes', 'SMS', '+33111111111', FALSE, NULL, 'Unité 7', 'Office Français de la Biodiversité'), + + ('00000000-0000-4000-0000-000000000003', 'MANUAL', NOW() AT TIME ZONE 'UTC' - INTERVAL '2.0 minutes', 'EMAIL', 'ddtm-pre@morbihan.gouv.fr', TRUE, NULL, 'Unité 9', 'DDTM'), + ('00000000-0000-4000-0000-000000000003', 'MANUAL', NOW() AT TIME ZONE 'UTC' - INTERVAL '2.0 minutes', 'EMAIL', 'namo@example.gouv.fr', FALSE, NULL, 'Unité 10', 'DIRM / DM'), + + ('00000000-0000-4000-0000-000000000004', 'MANUAL', NOW() AT TIME ZONE 'UTC' - INTERVAL '2.0 minutes', 'EMAIL', 'dreal@example.gouv.fr', FALSE, NULL, 'Unité 11', 'DDTM'), + + ('00000000-0000-4000-0000-000000000006', 'MANUAL', NOW() AT TIME ZONE 'UTC' - INTERVAL '2.0 minutes', 'EMAIL', 'ddtm-ulam@morbihan.gouv.fr', TRUE, NULL, 'Unité 11', 'DDTM'), + + ('00000000-0000-4000-0000-000000000008', 'MANUAL', NOW() AT TIME ZONE 'UTC' - INTERVAL '2.0 minutes', 'EMAIL', 'dirm@example.gouv.fr', FALSE, NULL, 'Unité 12', 'DIRM / DM'), + + ('00000000-0000-4000-0000-000000000010', 'MANUAL', NOW() AT TIME ZONE 'UTC' - INTERVAL '2.0 minutes', 'EMAIL', 'pam-jeanne-barret.dirm-memn@developpement-durable.gouv.fr', TRUE, NULL, 'Unité 12', 'DIRM / DM'); diff --git a/frontend/cypress/e2e/side_window/logbook_prior_notification_form/error_handling.spec.ts b/frontend/cypress/e2e/side_window/logbook_prior_notification_form/error_handling.spec.ts index e676e4fd88..34b7b53d38 100644 --- a/frontend/cypress/e2e/side_window/logbook_prior_notification_form/error_handling.spec.ts +++ b/frontend/cypress/e2e/side_window/logbook_prior_notification_form/error_handling.spec.ts @@ -4,9 +4,10 @@ import { editSideWindowPriorNotification } from './utils' context('Side Window > Logbook Prior Notification Form > Error Handling', () => { const failedQueryCount = RTK_MAX_RETRIES + 1 - const url = '/bff/v1/prior_notifications/FAKE_OPERATION_109_COR?isManuallyCreated=false&operationDate=*' it('Should handle fetching error as expected', () => { + const url = '/bff/v1/prior_notifications/FAKE_OPERATION_109_COR?isManuallyCreated=false&operationDate=*' + cy.intercept( { method: 'GET', @@ -32,4 +33,30 @@ context('Side Window > Logbook Prior Notification Form > Error Handling', () => cy.contains(`L'ANCRE SÈCHE (CFR106)`).should('be.visible') }) + + it('Should handle sent message list fetching error as expected', () => { + const url = '/bff/v1/prior_notifications/FAKE_OPERATION_108/sent_messages' + + cy.intercept( + { + method: 'GET', + times: failedQueryCount, + url + }, + { + statusCode: 400 + } + ).as('getPriorNotificationSentMessagesWithError') + + editSideWindowPriorNotification(`CALAMARO`, 'FAKE_OPERATION_108') + + cy.clickButton('Voir les détails de la diffusion du préavis') + + for (let i = 1; i <= failedQueryCount; i += 1) { + cy.wait('@getPriorNotificationSentMessagesWithError') + } + + cy.contains(`Impossible de récupérer la liste.`).should('be.visible') + cy.contains(`Impossible de récupérer l’historique.`).should('be.visible') + }) }) diff --git a/frontend/cypress/e2e/side_window/logbook_prior_notification_form/sent_message_list.spec.ts b/frontend/cypress/e2e/side_window/logbook_prior_notification_form/sent_message_list.spec.ts new file mode 100644 index 0000000000..3dd401c3c0 --- /dev/null +++ b/frontend/cypress/e2e/side_window/logbook_prior_notification_form/sent_message_list.spec.ts @@ -0,0 +1,41 @@ +import { editSideWindowPriorNotification } from './utils' + +context('Side Window > Logbook Prior Notification Form > Sent Message List', () => { + it('Should display the expected list of subscribers and sent messages history', () => { + editSideWindowPriorNotification(`CALAMARO`, 'FAKE_OPERATION_108') + + cy.intercept('GET', `/bff/v1/prior_notifications/FAKE_OPERATION_108/sent_messages`).as( + 'getPriorNotificationSentMessages' + ) + + cy.clickButton('Voir les détails de la diffusion du préavis') + + cy.wait('@getPriorNotificationSentMessages') + + cy.get('address').eq(0).contains('Unité 3 (Gendarmerie)') + cy.get('address').eq(0).contains('pgmarc720.lorient@gendarmerie.defense.gouv.fr') + cy.get('address').eq(0).contains('+33123456789') + + cy.get('address').eq(1).contains('Unité 4 (Gendarmerie)') + cy.get('address').eq(1).contains('ggmaratlan@gendarmerie.defense.gouv.fr') + cy.get('address').eq(1).contains('+33987654321') + + cy.get('address').eq(2).contains('Unité 5 (DDTM 40)') + cy.get('address').eq(2).contains('unite5@ddtm-40.gouv.fr') + cy.get('address').eq(2).contains('+33000000000') + + cy.getDataCy('SentMessageList-historyItem') + .eq(0) + .contains( + 'Échec de la diffusion pour tous les contacts: pgmarc720.lorient@gendarmerie.defense.gouv.fr, +33987654321, +33123456789, ggmaratlan@gendarmerie.defense.gouv.fr.' + ) + + cy.getDataCy('SentMessageList-historyItem') + .eq(1) + .contains( + 'Échec de la diffusion pour le(s) contact(s): +33000000000, +33987654321, unite5@ddtm-40.gouv.fr, pgmarc720.lorient@gendarmerie.defense.gouv.fr.' + ) + + cy.getDataCy('SentMessageList-historyItem').eq(2).contains('Préavis diffusé avec succès à tous les contacts.') + }) +})