Added acceptance tests for testing the API for the Users section. (#14445)
* 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!
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"@umbraco/json-models-builders": "^1.0.5",
|
||||
"@umbraco/playwright-testhelpers": "2.0.0-beta",
|
||||
"@umbraco/playwright-testhelpers": "2.0.0-beta.1",
|
||||
"camelize": "^1.0.0",
|
||||
"dotenv": "^16.3.1",
|
||||
"faker": "^4.1.0",
|
||||
@@ -141,9 +141,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@umbraco/playwright-testhelpers": {
|
||||
"version": "2.0.0-beta",
|
||||
"resolved": "https://registry.npmjs.org/@umbraco/playwright-testhelpers/-/playwright-testhelpers-2.0.0-beta.tgz",
|
||||
"integrity": "sha512-S0E0ds1VCsYrnpKSmGkbgZFrnRW1WudVkFuUSfwbi/Qb794iZCO7dKbT0Wg1ZjR3ryYeSsM21fd64DTLZmY5iA==",
|
||||
"version": "2.0.0-beta.1",
|
||||
"resolved": "https://registry.npmjs.org/@umbraco/playwright-testhelpers/-/playwright-testhelpers-2.0.0-beta.1.tgz",
|
||||
"integrity": "sha512-tuuTqLgVrjXvj0VrYkH2H8Gp5wZAOyGPTYev6vtYxF6AOoegIUmQtMx3zMuadEgD1eRz0Qbd3yM78LGqmPi/jw==",
|
||||
"dependencies": {
|
||||
"@umbraco/json-models-builders": "^1.0.5",
|
||||
"camelize": "^1.0.0",
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@umbraco/json-models-builders": "^1.0.5",
|
||||
"@umbraco/playwright-testhelpers": "2.0.0-beta",
|
||||
"@umbraco/playwright-testhelpers": "2.0.0-beta.1",
|
||||
"camelize": "^1.0.0",
|
||||
"dotenv": "^16.3.1",
|
||||
"faker": "^4.1.0",
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import {test} from '@umbraco/playwright-testhelpers';
|
||||
import {expect} from "@playwright/test";
|
||||
|
||||
test.describe('User Tests', () => {
|
||||
const userEmail = "user@email.com";
|
||||
const userName = "UserTests";
|
||||
|
||||
test.beforeEach(async ({page, umbracoApi}) => {
|
||||
await umbracoApi.user.ensureUserNameNotExists(userName);
|
||||
});
|
||||
|
||||
test.afterEach(async ({page, umbracoApi}) => {
|
||||
await umbracoApi.user.ensureUserNameNotExists(userName);
|
||||
});
|
||||
|
||||
test('can create a user', async ({page, umbracoApi, umbracoUi}) => {
|
||||
// Gets the id for the writers userGroup
|
||||
const userGroup = await umbracoApi.userGroup.getUserGroupByName("Writers");
|
||||
const userGroupId = [userGroup.id];
|
||||
|
||||
await umbracoApi.user.createUser(userEmail, userName, userGroupId);
|
||||
|
||||
// Assert
|
||||
await expect(await umbracoApi.user.doesUserWithNameExist(userName)).toBeTruthy();
|
||||
});
|
||||
|
||||
test('can update a user', async ({page, umbracoApi, umbracoUi}) => {
|
||||
// Gets userGroup data for Writers and Translators
|
||||
const userGroup = await umbracoApi.userGroup.getUserGroupByName("Writers");
|
||||
const anotherUserGroup = await umbracoApi.userGroup.getUserGroupByName("Translators");
|
||||
|
||||
const userGroupId = [userGroup.id];
|
||||
|
||||
await umbracoApi.user.createUser(userEmail, userName, userGroupId);
|
||||
|
||||
const userData = await umbracoApi.user.getUserByName(userName);
|
||||
|
||||
const newUserGroupData = [
|
||||
userGroup.id,
|
||||
anotherUserGroup.id
|
||||
];
|
||||
|
||||
userData.userGroupIds = newUserGroupData;
|
||||
|
||||
await umbracoApi.user.updateUserById(userData.id, userData);
|
||||
|
||||
// Assert
|
||||
await umbracoApi.user.doesUserWithNameExist(userName);
|
||||
// Checks if the user was updated with another userGroupID
|
||||
const updatedUser = await umbracoApi.user.getUserByName(userName);
|
||||
await expect(updatedUser.userGroupIds.toString() == newUserGroupData.toString()).toBeTruthy();
|
||||
});
|
||||
|
||||
test('can delete a user', async ({page, umbracoApi, umbracoUi}) => {
|
||||
const userGroupData = await umbracoApi.userGroup.getUserGroupByName("Writers");
|
||||
|
||||
const userData = [
|
||||
userGroupData.id
|
||||
];
|
||||
|
||||
await umbracoApi.user.createUser(userEmail, userName, userData);
|
||||
|
||||
await expect(await umbracoApi.user.doesUserWithNameExist(userName)).toBeTruthy();
|
||||
|
||||
await umbracoApi.user.deleteUserByName(userName);
|
||||
|
||||
// Assert
|
||||
await expect(await umbracoApi.user.doesUserWithNameExist(userName)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,68 @@
|
||||
import {test} from '@umbraco/playwright-testhelpers';
|
||||
import {expect} from "@playwright/test";
|
||||
|
||||
test.describe('User Avatar Tests', () => {
|
||||
// User
|
||||
const userEmail = "userAvatar@email.com";
|
||||
const userName = "UserAvatarTests";
|
||||
// Avatar
|
||||
// Creates a random GUID
|
||||
const avatarFileId = crypto.randomUUID();
|
||||
const avatarName = 'Umbraco.png';
|
||||
const mimeType = 'image/png';
|
||||
const avatarFilePath = './fixtures/mediaLibrary/Umbraco.png';
|
||||
|
||||
test.beforeEach(async ({page, umbracoApi}) => {
|
||||
await umbracoApi.user.ensureUserNameNotExists(userName);
|
||||
await umbracoApi.temporaryFile.ensureTemporaryFileWithIdNotExists(avatarFileId);
|
||||
});
|
||||
|
||||
test.afterEach(async ({page, umbracoApi}) => {
|
||||
await umbracoApi.user.ensureUserNameNotExists(userName);
|
||||
await umbracoApi.temporaryFile.ensureTemporaryFileWithIdNotExists(avatarFileId);
|
||||
});
|
||||
|
||||
test('can add an avatar to a user', async ({page, umbracoApi, umbracoUi}) => {
|
||||
const userGroup = await umbracoApi.userGroup.getUserGroupByName("Writers");
|
||||
|
||||
const userGroupData = [userGroup.id];
|
||||
|
||||
await umbracoApi.user.createUser(userEmail, userName, userGroupData);
|
||||
|
||||
const userData = await umbracoApi.user.getUserByName(userName);
|
||||
|
||||
await umbracoApi.temporaryFile.createTemporaryFile(avatarFileId, avatarName, mimeType, avatarFilePath);
|
||||
|
||||
await umbracoApi.user.addAvatarToUserWithId(userData.id, avatarFileId);
|
||||
|
||||
// Assert
|
||||
// Checks if the avatar was added to the user
|
||||
const userDataWithAvatar = await umbracoApi.user.getUserByName(userName);
|
||||
await expect(userDataWithAvatar.avatarUrls.length !== 0).toBeTruthy();
|
||||
});
|
||||
|
||||
test('can remove an avatar from a user', async ({page, umbracoApi, umbracoUi}) => {
|
||||
const userGroup = await umbracoApi.userGroup.getUserGroupByName("Writers");
|
||||
|
||||
const userGroupData = [userGroup.id];
|
||||
|
||||
await umbracoApi.user.createUser(userEmail, userName, userGroupData);
|
||||
|
||||
const userData = await umbracoApi.user.getUserByName(userName);
|
||||
|
||||
await umbracoApi.temporaryFile.createTemporaryFile(avatarFileId, avatarName, mimeType, avatarFilePath);
|
||||
|
||||
await umbracoApi.user.addAvatarToUserWithId(userData.id, avatarFileId);
|
||||
|
||||
// Checks if the avatar was added to the user
|
||||
const userDataWithAvatar = await umbracoApi.user.getUserByName(userName);
|
||||
await expect(userDataWithAvatar.avatarUrls.length !== 0).toBeTruthy();
|
||||
|
||||
await umbracoApi.user.removeAvatarFromUserWithId(userData.id);
|
||||
|
||||
// Assert
|
||||
// Checks if the avatar was removed from the user
|
||||
const userDataWithoutAvatar = await umbracoApi.user.getUserByName(userName);
|
||||
await expect(userDataWithoutAvatar.avatarUrls.length == 0).toBeTruthy();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user