Skip to content

Commit

Permalink
Add int test for create template TC FF (#1925)
Browse files Browse the repository at this point in the history
* Add int test for create template TC FF

* Add step to clean up DB after tests

* Implement delete template api call

* test: add scenario to FF off

* Various fixes to create-template suite

* fix: update `UpdateTemplate()` method to fix up params

* test: add the rest of the test suite

* fix: update FF-OFF tests for edit-tempalte

* fix: skip FF-off for now - will run manually

* Add test for non-admin changing template category

- Moved seeding logic into TemplatesPage.js

* Wrap up edit test suite

* Fix tests

* Fix tests

* formatting

* chore: add new test suites to CI

* fix: skip suite for now to get the release out the door

* fix: dont skip it cause its fixed 🎉

* fix: remove async/await keywords

---------

Co-authored-by: Andrew Leith <[email protected]>
  • Loading branch information
whabanks and andrewleith authored Aug 8, 2024
1 parent a6f3abb commit 1785fb7
Show file tree
Hide file tree
Showing 9 changed files with 526 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/main/views/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ def edit_service_template(service_id, template_id): # noqa: C901 TODO: remove t
template["subject"] = new_template_data["subject"]
template["template_content"] = template["content"]

if template.get("process_type") is None:
if template.get("process_type_column") is None:
if current_app.config["FF_TEMPLATE_CATEGORY"]: # TODO: remove when FF_TEMPLATE_CATEGORY removed
template["process_type"] = TC_PRIORITY_VALUE
else: # TODO: remove when FF_TEMPLATE_CATEGORY removed
Expand Down
2 changes: 2 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ def template_json(
version=1,
archived=False,
process_type=TemplateProcessTypes.BULK.value,
process_type_column=TemplateProcessTypes.BULK.value,
redact_personalisation=None,
service_letter_contact=None,
reply_to=None,
Expand All @@ -342,6 +343,7 @@ def template_json(
"updated_at": datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S.%f"),
"archived": archived,
"process_type": process_type,
"process_type_column": process_type_column,
"service_letter_contact": service_letter_contact,
"reply_to": reply_to,
"reply_to_text": reply_to_text,
Expand Down
21 changes: 16 additions & 5 deletions tests/app/main/views/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,17 @@ def test_create_email_template_cat_other_to_freshdesk(

def test_edit_email_template_cat_other_to_freshdesk(
self,
mocker,
client_request,
mock_get_template_categories,
mock_get_service_template,
mock_update_service_template,
mock_send_other_category_to_freshdesk,
active_user_with_permissions,
fake_uuid,
app_,
):
with set_config(app_, "FF_TEMPLATE_CATEGORY", True):
mock_get_service_template_with_process_type(mocker, "bulk", None)
name = "new name"
content = "template <em>content</em> with & entity"
client_request.post(
Expand Down Expand Up @@ -1348,13 +1349,14 @@ def test_should_redirect_to_one_off_if_template_type_is_letter(
def test_should_redirect_when_saving_a_template(
client_request,
mock_get_template_categories,
mock_get_service_template,
mock_update_service_template,
fake_uuid,
app_,
mocker,
ff_enabled,
):
with set_config(app_, "FF_TEMPLATE_CATEGORY", ff_enabled):
mock_get_service_template_with_process_type(mocker, DEFAULT_PROCESS_TYPE, None)
name = "new name"
content = "template <em>content</em> with & entity"

Expand Down Expand Up @@ -1393,7 +1395,7 @@ def test_should_redirect_when_saving_a_template(
def test_should_edit_content_when_process_type_is_set_not_platform_admin(
client_request, mocker, mock_update_service_template, mock_get_template_categories, fake_uuid, process_type, app_
):
mock_get_service_template_with_process_type(mocker, process_type)
mock_get_service_template_with_process_type(mocker, process_type, process_type)
client_request.post(
".edit_service_template",
service_id=SERVICE_ONE_ID,
Expand All @@ -1406,6 +1408,7 @@ def test_should_edit_content_when_process_type_is_set_not_platform_admin(
"template_category_id": TESTING_TEMPLATE_CATEGORY,
"service": SERVICE_ONE_ID,
"process_type": process_type,
"process_type_column": process_type,
"button_pressed": "save",
},
_expected_status=302,
Expand Down Expand Up @@ -1635,8 +1638,15 @@ def test_removing_placeholders_is_not_a_breaking_change(

@pytest.mark.parametrize("template_type", ["sms", "email"])
def test_should_not_update_if_template_name_too_long(
client_request, template_type, fake_uuid, mock_get_service_template, mock_update_service_template_400_name_too_long, app_
client_request,
template_type,
fake_uuid,
mocker,
mock_update_service_template_400_name_too_long,
mock_get_template_categories,
app_,
):
mock_get_service_template_with_process_type(mocker, DEFAULT_PROCESS_TYPE, None)
template_data = {
"id": fake_uuid,
"service": SERVICE_ONE_ID,
Expand Down Expand Up @@ -1710,8 +1720,9 @@ def test_should_not_create_too_big_template(


def test_should_not_update_too_big_template(
client_request, mock_get_service_template, mock_update_service_template_400_content_too_big, fake_uuid, app_
mocker, client_request, mock_get_service_template, mock_update_service_template_400_content_too_big, fake_uuid, app_
):
mock_get_service_template_with_process_type(mocker, DEFAULT_PROCESS_TYPE, None)
page = client_request.post(
".edit_service_template",
service_id=SERVICE_ONE_ID,
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ def _get_tc():
return mocker.patch("app.service_api_client.get_service_template", side_effect=_get)


def mock_get_service_template_with_process_type(mocker, process_type):
def mock_get_service_template_with_process_type(mocker, process_type, process_type_column):
def _get(service_id, template_id, version=None):
template = template_json(
service_id,
Expand All @@ -808,6 +808,7 @@ def _get(service_id, template_id, version=None):
"sms",
"Template <em>content</em> with & entity",
process_type=process_type,
process_type_column=process_type_column,
)
if version:
template.update({"version": version})
Expand Down
37 changes: 34 additions & 3 deletions tests_cypress/cypress/Notify/Admin/Pages/TemplatesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let Components = {
// edit template page
TemplateName: () => cy.getByTestId('template-name'),
TemplateContent: () => cy.getByTestId('template-content'),
TemplateSubject: () => cy.getByTestId('template-subject'),
TemplateSubject: () => cy.get('textarea[name=subject]'),
FlashMessage: () => cy.get('.banner-default-with-tick'),
TemplateCategoryButtonContainer: () => cy.getByTestId('tc_button_container'),
TemplateCategoryRadiosContainer: () => cy.getByTestId('tc_radios'),
Expand All @@ -21,6 +21,7 @@ let Components = {
SelectedTemplateCategory: () => Components.TemplateCategories().find('input:checked').parent(),
SelectedTemplateCategoryCollapsed: () => Components.TemplateCategoryButtonContainer().find('p'),
TCExpandBytton: () => cy.getByTestId('tc_expand_button'),
TemplatePriority: () => cy.getByTestId('process_type'),
};

// Actions users can take on the page
Expand All @@ -40,7 +41,7 @@ let Actions = {
ExpandTemplateCategories: () => {
Components.TCExpandBytton().click();
},
SaveTemplate: (expectFailure=false) => {
SaveTemplate: (expectFailure = false) => {
Components.SaveTemplateButton().click();
if (!expectFailure) {
Components.FlashMessage().should('contain', 'template saved');
Expand All @@ -67,7 +68,37 @@ let Actions = {
SelectTemplateCategory: (category) => {
Components.TemplateCategories().contains('label', category).click();
},
};
SetTemplatePriority: (priority) => {
cy.getByTestId(priority).click();
},
FillTemplateForm: (name, subject, content, category = null, priority = null) => {
Components.TemplateName().type(name);
Components.TemplateSubject().type(subject);
Components.TemplateContent().type(content);
if (category) {
Actions.SelectTemplateCategory(category);
}
if (priority) {
Actions.SetTemplatePriority(priority);
}
},
SeedTemplate: (name, subject, content, category = null, priority = null) => {
Actions.CreateTemplate();
Actions.SelectTemplateType("email");
Actions.Continue();
Actions.FillTemplateForm(
name,
subject,
content,
category,
priority,
);
Actions.SaveTemplate();
return cy.url().then((url) => {
return url.split("/templates/")[1]
})
}
}

let TemplatesPage = {
Components,
Expand Down
64 changes: 64 additions & 0 deletions tests_cypress/cypress/Notify/NotifyAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,70 @@ const Admin = {
}
})
},
CreateTemplate: ({ name, type, content, service_id, subject = null, process_type, parent_folder_id = null, template_category_id = null }) => {
var token = Utilities.CreateJWT();
return cy.request({
url: `${BASE_URL}/service/${service_id}/template`,
method: 'GET',
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": 'application/json'
},
body: {
"name": name,
"template_type": type,
"content": content,
"service": service_id,
"process_type": process_type,
"template_category_id": template_category_id,
}
});
},
DeleteTemplate: ({ serviceId, templateId }) => {
var token = Utilities.CreateJWT();
return cy.request({
url: `${BASE_URL}/service/${serviceId}/template/${templateId}`,
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": 'application/json'
},
body: {
"archived": true
}
});
},
GetTemplate: ({ templateId, serviceId }) => {
var token = Utilities.CreateJWT();
return cy.request({
url: `${BASE_URL}/service/${serviceId}/template/${templateId}`,
method: 'GET',
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": 'application/json'
}
});
},
UpdateTemplate: ({ id, name, type, content, service_id, subject = null, process_type, parent_folder_id = null, template_category_id = null }) => {
var token = Utilities.CreateJWT();
return cy.request({
url: `${BASE_URL}/service/${service_id}/template/${id}`,
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": 'application/json'
},
body: {
"id": id,
"name": name,
"template_type": type,
"content": content,
"service": service_id,
"process_type": process_type,
"template_category_id": template_category_id
}
});
},
GetTemplateCategory: ({ templateCategoryId }) => {
var token = Utilities.CreateJWT();
return cy.request({
Expand Down
2 changes: 2 additions & 0 deletions tests_cypress/cypress/e2e/admin/ci.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ import "./branding/all.cy";
import "./tou_dialog.cy";
import "./template-filters.cy";
import "./template-categories.cy";
import "./template/create-template.cy";
import "./template/edit-template.cy";
Loading

0 comments on commit 1785fb7

Please sign in to comment.