void expectTemplateAndAttributesAreUpdatedIfNewAttributeValue()

in ddm-notification-service/src/it/java/com/epam/digital/data/platform/notification/service/SaveDiiaNotificationTemplateServiceTest.java [176:244]


  void expectTemplateAndAttributesAreUpdatedIfNewAttributeValue() {
    var prepopulatedEntity =
        notificationTemplateRepository.save(createTemplate(NAME_3, CONTENT,
            "b873ee130819ed542ec8ce28ea74a5830ad17756c55557e5f21e30efbcf57785"));

    notificationTemplateAttributeRepository.saveAll(
        List.of(
            NotificationTemplateAttribute.builder()
                .templateId(prepopulatedEntity.getId())
                .name("templateType")
                .value("DiiaTemplateType")
                .build(),
            NotificationTemplateAttribute.builder()
                .templateId(prepopulatedEntity.getId())
                .name("actionType")
                .value("DiiaActionType")
                .build(),
            NotificationTemplateAttribute.builder()
                .templateId(prepopulatedEntity.getId())
                .name("shortText")
                .value("DiiaShortText")
                .build()
        ));

    var inputDto =
        SaveNotificationTemplateInputDto.builder()
            .title(TITLE)
            .content(CONTENT)
            .attributes(
                List.of(
                    new NotificationTemplateAttributeDto("templateType", "DiiaTemplateType"),
                    new NotificationTemplateAttributeDto("actionType", "UpdatedActionType")
                )
            ).build();

    diiaWireMock.
        stubFor(post(urlEqualTo("/api/v1/notification/template"))
            .willReturn(aResponse()
                .withStatus(200)
                .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE)
                .withBody("{\"templateId\":\"31337\"}")
            ));

    service.save(CHANNEL, NAME_3, inputDto);

    var templateTableContent = notificationTemplateRepository
        .findByNameAndChannel(NAME_3, CHANNEL).get();
    assertThat(templateTableContent).isNotNull();
    assertThat(templateTableContent.getId()).isEqualTo(prepopulatedEntity.getId());
    assertThat(templateTableContent.getChannel()).isEqualTo(CHANNEL);
    assertThat(templateTableContent.getName()).isEqualTo(NAME_3);
    assertThat(templateTableContent.getTitle()).isEqualTo(TITLE);
    assertThat(templateTableContent.getContent()).isEqualTo(CONTENT);
    assertThat(templateTableContent.getChecksum())
        .isEqualTo("692fa32344032c2e23a5d72433edca1be4c9e18c4064f3cc794d1f802e4daa39");
    assertThat(templateTableContent.getCreatedAt()).isNotNull();
    assertThat(templateTableContent.getUpdatedAt()).isNotNull();
    assertThat(templateTableContent.getExtTemplateId()).isEqualTo("31337");
    assertThat(templateTableContent.getExtPublishedAt()).isNotNull();

    var attributesTableContent =
        notificationTemplateAttributeRepository.findByTemplateId(templateTableContent.getId());
    assertThat(attributesTableContent.stream()
        .collect(
            toMap(NotificationTemplateAttribute::getName, NotificationTemplateAttribute::getValue)))
        .containsExactly(
            Map.entry("templateType", "DiiaTemplateType"),
            Map.entry("actionType", "UpdatedActionType"));
  }