From acf8f575a80fe4df0bfb431b04baf18b9cfe28a8 Mon Sep 17 00:00:00 2001 From: Andreas Zerbst <73799582+andr317c@users.noreply.github.com> Date: Mon, 26 Jun 2023 13:09:41 +0200 Subject: [PATCH] Added acceptance tests for testing the API for the UserGroups section. (#14448) * Added auth to gitignore * Added a setup for logging in which allows us to save the token for the user * Added simple acceptance test for testing our api for the DataTypes * Added simple acceptance tests for testing the API for the PartialView section * Added simple acceptance tests for testing the API for the Script section * Added acceptance tests for testing the API for the Stylesheet section. * Added acceptance tests for testing the API for the User section * Bumped the version of our testhelpers! * Added acceptance tests for testing the API for the Dictionary section. * Added acceptance tests for testing the API for the Language section. * Added acceptance tests for testing the API for the UserGroups section. * Added acceptance tests for testing the API for the Template section (#14450) * Added acceptance tests for testing the API for the Template section * Added acceptance tests for testing the API for the TemporaryFiles section (#14451) --- .../ApiTesting/Template/Template.spec.ts | 51 +++++++++++++++++++ .../TemporaryFile/TemporaryFile.spec.ts | 35 +++++++++++++ .../ApiTesting/UserGroup/UserGroup.spec.ts | 51 +++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Template/Template.spec.ts create mode 100644 tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/TemporaryFile/TemporaryFile.spec.ts create mode 100644 tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/UserGroup/UserGroup.spec.ts diff --git a/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Template/Template.spec.ts b/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Template/Template.spec.ts new file mode 100644 index 0000000000..ca0239eec2 --- /dev/null +++ b/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Template/Template.spec.ts @@ -0,0 +1,51 @@ +import {AliasHelper, test} from '@umbraco/playwright-testhelpers'; +import {expect} from "@playwright/test"; + +test.describe('Template tests', () => { + const templateName = 'TemplateTester'; + const templateAlias = AliasHelper.toAlias(templateName); + + test.beforeEach(async ({page, umbracoApi}) => { + await umbracoApi.template.ensureTemplateNameNotExistsAtRoot(templateName); + }); + + test.afterEach(async ({page, umbracoApi}) => { + await umbracoApi.template.ensureTemplateNameNotExistsAtRoot(templateName); + }) + + test('can create a template', async ({page, umbracoApi, umbracoUi}) => { + await umbracoApi.template.createTemplate(templateName, templateAlias, 'Template Stuff'); + + // Assert + await expect(umbracoApi.template.doesTemplateWithNameExistAtRoot(templateName)).toBeTruthy(); + }); + + test('can update a template', async ({page, umbracoApi, umbracoUi}) => { + const newTemplateAlias = 'betterAlias'; + + await umbracoApi.template.createTemplate(templateName, templateAlias, 'Template Stuff'); + + const templateData = await umbracoApi.template.getTemplateByNameAtRoot(templateName); + + // Updates the template + templateData.alias = newTemplateAlias; + await umbracoApi.template.updateTemplateById(templateData.id, templateData); + + // Assert + await expect(umbracoApi.template.doesTemplateWithNameExistAtRoot(templateName)).toBeTruthy(); + // Checks if the template alias was updated + const updatedTemplate = await umbracoApi.template.getTemplateByNameAtRoot(templateName); + await expect(updatedTemplate.alias == newTemplateAlias).toBeTruthy(); + }); + + test('can delete template', async ({page, umbracoApi, umbracoUi}) => { + await umbracoApi.template.createTemplate(templateName, templateAlias, 'More Template Stuff'); + + await expect(umbracoApi.template.doesTemplateWithNameExistAtRoot(templateName)).toBeTruthy(); + + await umbracoApi.template.deleteTemplateByNameAtRoot(templateName); + + // Assert + await expect(await umbracoApi.template.doesTemplateWithNameExistAtRoot(templateName)).toBeFalsy(); + }); +}); diff --git a/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/TemporaryFile/TemporaryFile.spec.ts b/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/TemporaryFile/TemporaryFile.spec.ts new file mode 100644 index 0000000000..deb68e4059 --- /dev/null +++ b/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/TemporaryFile/TemporaryFile.spec.ts @@ -0,0 +1,35 @@ +import {test} from "@umbraco/playwright-testhelpers"; +import {expect} from "@playwright/test"; + +test.describe('Temporary File tests', () => { + const temporaryFileId = crypto.randomUUID(); + const fileName = 'Umbraco.png'; + const mimeType = 'image/png'; + const filePath = './fixtures/mediaLibrary/Umbraco.png'; + + test.beforeEach(async ({page, umbracoApi}) => { + await umbracoApi.temporaryFile.ensureTemporaryFileWithIdNotExists(temporaryFileId); + }); + + test.afterEach(async ({page, umbracoApi}) => { + await umbracoApi.temporaryFile.ensureTemporaryFileWithIdNotExists(temporaryFileId); + }); + + test('can create temporary file', async ({page, umbracoApi, umbracoUi}) => { + await umbracoApi.temporaryFile.createTemporaryFile(temporaryFileId, fileName, mimeType, filePath); + + // Assert + await expect(await umbracoApi.temporaryFile.doesTemporaryFileWithIdExist(temporaryFileId)).toBeTruthy(); + }); + + test('can delete temporary file', async ({page, umbracoApi, umbracoUi}) => { + await umbracoApi.temporaryFile.createTemporaryFile(temporaryFileId, fileName, mimeType, filePath); + + await expect(await umbracoApi.temporaryFile.getTemporaryFileById(temporaryFileId)).toBeTruthy(); + + await umbracoApi.temporaryFile.deleteTemporaryFileById(temporaryFileId); + + // Assert + await expect(await umbracoApi.temporaryFile.doesTemporaryFileWithIdExist(temporaryFileId)).toBeFalsy(); + }); +}); diff --git a/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/UserGroup/UserGroup.spec.ts b/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/UserGroup/UserGroup.spec.ts new file mode 100644 index 0000000000..e34a922801 --- /dev/null +++ b/tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/UserGroup/UserGroup.spec.ts @@ -0,0 +1,51 @@ +import {test} from '@umbraco/playwright-testhelpers'; +import {expect} from "@playwright/test"; + +test.describe('User Group Tests', () => { + const userGroupName = "UserGroupTest"; + + test.beforeEach(async ({page, umbracoApi}) => { + await umbracoApi.userGroup.ensureUserGroupNameNotExists(userGroupName); + }); + + test.afterEach(async ({page, umbracoApi}) => { + await umbracoApi.userGroup.ensureUserGroupNameNotExists(userGroupName); + }); + + test('can create a user group', async ({page, umbracoApi, umbracoUi}) => { + const sections = ["Umb.Section.Content", + "Umb.Section.Forms", + "Umb.Section.Media"]; + + await umbracoApi.userGroup.createUserGroup(userGroupName, true, sections); + + // Assert + await expect(umbracoApi.userGroup.doesUserGroupWithNameExists(userGroupName)).toBeTruthy(); + }); + + test('can update a user group', async ({page, umbracoApi, umbracoUi}) => { + await umbracoApi.userGroup.createUserGroup('UserGroupNameTest', true); + + const userGroupData = await umbracoApi.userGroup.getUserGroupByName('UserGroupNameTest'); + + // Updates name of the user group + userGroupData.name = userGroupName; + await umbracoApi.userGroup.updateUserGroupById(userGroupData.id, userGroupData); + + + // Assert + const updatedUserGroupData = await umbracoApi.userGroup.getUserGroupById(userGroupData.id); + await expect(updatedUserGroupData.name == userGroupName).toBeTruthy(); + }); + + test('can delete a user group', async ({page, umbracoApi, umbracoUi}) => { + await umbracoApi.userGroup.createUserGroup(userGroupName, true); + + const userGroupData = await umbracoApi.userGroup.getUserGroupByName(userGroupName); + + await umbracoApi.userGroup.deleteUserGroupById(userGroupData.id); + + // Assert + await expect(await umbracoApi.userGroup.doesUserGroupWithNameExists(userGroupName)).toBeFalsy(); + }); +});