From aa5eff915d0eb3d1c63d47d8ecce129595d3b314 Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Sun, 16 May 2021 15:26:38 +0530 Subject: [PATCH] Fix incorre check on template deletion. --- cmd/templates.go | 11 +---------- frontend/cypress.json | 2 +- frontend/cypress/integration/templates.js | 7 ++++--- frontend/src/assets/style.scss | 2 +- frontend/src/views/TemplateForm.vue | 2 +- 5 files changed, 8 insertions(+), 16 deletions(-) diff --git a/cmd/templates.go b/cmd/templates.go index 637989f..fb62520 100644 --- a/cmd/templates.go +++ b/cmd/templates.go @@ -1,7 +1,6 @@ package main import ( - "database/sql" "errors" "fmt" "net/http" @@ -222,23 +221,15 @@ func handleDeleteTemplate(c echo.Context) error { if id < 1 { return echo.NewHTTPError(http.StatusBadRequest, app.i18n.T("globals.messages.invalidID")) - } else if id == 1 { - return echo.NewHTTPError(http.StatusBadRequest, - app.i18n.T("templates.cantDeleteDefault")) } var delID int err := app.queries.DeleteTemplate.Get(&delID, id) if err != nil { - if err == sql.ErrNoRows { - return c.JSON(http.StatusOK, okResp{true}) - } - return echo.NewHTTPError(http.StatusInternalServerError, - app.i18n.Ts("globals.messages.errorCreating", + app.i18n.Ts("globals.messages.errorDeleting", "name", "{globals.terms.template}", "error", pqErrMsg(err))) } - if delID == 0 { return echo.NewHTTPError(http.StatusBadRequest, app.i18n.T("templates.cantDeleteDefault")) diff --git a/frontend/cypress.json b/frontend/cypress.json index f8db83a..ec9d4bc 100644 --- a/frontend/cypress.json +++ b/frontend/cypress.json @@ -1,5 +1,5 @@ { - "baseUrl": "http://localhost:9000", + "baseUrl": "http://localhost:8080", "env": { "server_init_command": "pkill -9 listmonk | cd ../ && ./listmonk --install --yes && ./listmonk > /dev/null 2>/dev/null &", "username": "listmonk", diff --git a/frontend/cypress/integration/templates.js b/frontend/cypress/integration/templates.js index 48cc5af..7e64e02 100644 --- a/frontend/cypress/integration/templates.js +++ b/frontend/cypress/integration/templates.js @@ -26,7 +26,7 @@ describe('Templates', () => { cy.get('input[name=name]').clear().type('edited'); cy.get('textarea[name=body]').clear().type('test {{ template "content" . }}', { parseSpecialCharSequences: false, delay: 0 }); - cy.get('footer.modal-card-foot button.is-primary').click(); + cy.get('.modal-card-foot button.is-primary').click(); cy.wait(250); cy.get('tbody td[data-label="Name"] a').contains('edited'); }); @@ -40,7 +40,7 @@ describe('Templates', () => { cy.get('span').first().contains('test'); cy.get('p').first().contains('Hi there'); }); - cy.get('footer.modal-card-foot button').click(); + cy.get('.modal-card-foot button').click(); // Cloned one should have the full template. cy.get('tbody [data-cy=btn-preview').eq(1).click(); @@ -49,7 +49,7 @@ describe('Templates', () => { cy.get('.wrap p').first().contains('Hi there'); cy.get('.footer a').first().contains('Unsubscribe'); }); - cy.get('footer.modal-card-foot button').click(); + cy.get('.modal-card-foot button').click(); }); it('Sets default', () => { @@ -69,6 +69,7 @@ describe('Templates', () => { it('Deletes template', () => { + cy.wait(250); cy.get('tbody td.actions [data-cy=btn-delete]').first().click(); cy.get('.modal button.is-primary').click(); cy.wait(250); diff --git a/frontend/src/assets/style.scss b/frontend/src/assets/style.scss index 25ed8fb..64c3537 100644 --- a/frontend/src/assets/style.scss +++ b/frontend/src/assets/style.scss @@ -244,7 +244,7 @@ section { padding: 15px 10px; border-color: $grey-lightest; } - .actions a { + .actions a, .actions .a { margin: 0 10px; display: inline-block; } diff --git a/frontend/src/views/TemplateForm.vue b/frontend/src/views/TemplateForm.vue index 745098c..944be76 100644 --- a/frontend/src/views/TemplateForm.vue +++ b/frontend/src/views/TemplateForm.vue @@ -17,7 +17,7 @@ - +