Skip to content

Commit

Permalink
V14 QA Fixed/Cleaned up the api acceptance tests (#15964)
Browse files Browse the repository at this point in the history
* Removed api tests for RelationType since it is impossible to create/update/delete relation type

* Fixed api tests for UserGroup

* Fixed api tests for UserAvatar

* Fixed api tests for User

* Fixed api tests for Temporary File

* Fixed api tests for Dictionary

* Fixed api tests for DataType

* Fixed api tests for DataTypeFolder

* Cleaned up

* Bumped version of test helper

* Update tests/Umbraco.Tests.AcceptanceTest/tests/ApiTesting/Dictionary/Dictionary.spec.ts

Co-authored-by: Andreas Zerbst <73799582+andr317c@users.noreply.github.com>

* Reversed the api tests for Relation Type

---------

Co-authored-by: Andreas Zerbst <73799582+andr317c@users.noreply.github.com>
  • Loading branch information
nhudinh0309 and andr317c committed Apr 3, 2024
1 parent 1437483 commit be58f31
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 111 deletions.
8 changes: 4 additions & 4 deletions tests/Umbraco.Tests.AcceptanceTest/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/Umbraco.Tests.AcceptanceTest/package.json
Expand Up @@ -21,7 +21,7 @@
},
"dependencies": {
"@umbraco/json-models-builders": "^2.0.4",
"@umbraco/playwright-testhelpers": "^2.0.0-beta.25",
"@umbraco/playwright-testhelpers": "^2.0.0-beta.26",
"camelize": "^1.0.0",
"dotenv": "^16.3.1",
"faker": "^4.1.0",
Expand Down
Expand Up @@ -97,5 +97,8 @@ test.describe('DataType tests', () => {
// Checks if both dataTypes exists
expect(await umbracoApi.dataType.doesExist(dataTypeId)).toBeTruthy();
expect(await umbracoApi.dataType.doesExist(copiedDataTypeId)).toBeTruthy();

// Clean
await umbracoApi.dataType.delete(copiedDataTypeId);
});
});
Expand Up @@ -21,16 +21,13 @@ test.describe('DataTypeFolder tests', () => {
expect(umbracoApi.dataType.doesFolderExist(dataTypeFolderId)).toBeTruthy();
});

test('can update a dataType folder', async ({umbracoApi}) => {
test('can rename a dataType folder', async ({umbracoApi}) => {
// Arrange
const oldDataTypeFolderName = 'Oldie';

dataTypeFolderId = await umbracoApi.dataType.createFolder(oldDataTypeFolderName);
const dataTypeFolder = await umbracoApi.dataType.getFolder(dataTypeFolderId);
dataTypeFolder.name = dataTypeFolderName;
const wrongDataTypeFolderName = 'WrongFolderName';
dataTypeFolderId = await umbracoApi.dataType.createFolder(wrongDataTypeFolderName);

// Act
await umbracoApi.dataType.updateFolder(dataTypeFolderId, dataTypeFolder);
await umbracoApi.dataType.renameFolder(dataTypeFolderId, dataTypeFolderName);

// Assert
expect(umbracoApi.dataType.doesFolderExist(dataTypeFolderId)).toBeTruthy();
Expand Down
Expand Up @@ -4,7 +4,7 @@ import * as crypto from 'crypto';

test.describe('Dictionary tests', () => {
let dictionaryId = '';
const dictionaryName = 'Word';
const dictionaryName = 'TestDictionary';

test.beforeEach(async ({umbracoApi}) => {
await umbracoApi.dictionary.ensureNameNotExists(dictionaryName);
Expand All @@ -15,25 +15,18 @@ test.describe('Dictionary tests', () => {
});

test('can create a dictionary', async ({umbracoApi}) => {
// Arrange
const translationData = [
{
'isoCode': 'en-US',
'translation': 'Word'
}
];

// Act
dictionaryId = await umbracoApi.dictionary.create(dictionaryName, translationData);
dictionaryId = await umbracoApi.dictionary.createDefaultDictionary(dictionaryName);

// Assert
await expect(umbracoApi.dictionary.doesExist(dictionaryId)).toBeTruthy();
expect(await umbracoApi.dictionary.doesExist(dictionaryId)).toBeTruthy();
});

test('can update a dictionary', async ({umbracoApi}) => {
// Arrange
const oldDictionaryName = 'OldWord';
dictionaryId = await umbracoApi.dictionary.create(oldDictionaryName);
const wrongDictionaryName = 'WrongTestDictionary';
dictionaryId = await umbracoApi.dictionary.createDefaultDictionary(wrongDictionaryName);
expect(await umbracoApi.dictionary.doesNameExist(wrongDictionaryName)).toBeTruthy();
const dictionary = await umbracoApi.dictionary.get(dictionaryId);

// Act
Expand All @@ -43,25 +36,25 @@ test.describe('Dictionary tests', () => {
// Assert
// Checks if the dictionary was updated
const newDictionary = await umbracoApi.dictionary.get(dictionaryId);
await expect(newDictionary.name).toEqual(dictionaryName);
await expect(umbracoApi.dictionary.doesExist(dictionaryId)).toBeTruthy();
expect(newDictionary.name).toEqual(dictionaryName);
expect(await umbracoApi.dictionary.doesExist(dictionaryId)).toBeTruthy();
});

test('can delete a dictionary', async ({umbracoApi}) => {
// Arrange
dictionaryId = await umbracoApi.dictionary.create(dictionaryName);
await expect(umbracoApi.dictionary.doesExist(dictionaryId)).toBeTruthy();
expect(await umbracoApi.dictionary.doesExist(dictionaryId)).toBeTruthy();

// Act
await umbracoApi.dictionary.delete(dictionaryId);

// Assert
await expect(await umbracoApi.dictionary.doesExist(dictionaryId)).toBeFalsy();
expect(await umbracoApi.dictionary.doesExist(dictionaryId)).toBeFalsy();
});

test('can create a dictionary item in a dictionary', async ({umbracoApi}) => {
// Arrange
const childDictionaryName = 'Book';
const childDictionaryName = 'ChildDictionary';
await umbracoApi.dictionary.ensureNameNotExists(dictionaryName);
dictionaryId = await umbracoApi.dictionary.create(dictionaryName);

Expand All @@ -71,20 +64,20 @@ test.describe('Dictionary tests', () => {
// Assert
// Checks if the parent dictionary contains the child dictionary
const dictionaryChildren = await umbracoApi.dictionary.getChildren(dictionaryId);
await expect(dictionaryChildren[0].name).toEqual(childDictionaryName);
expect(dictionaryChildren[0].name).toEqual(childDictionaryName);
});

test('can export a dictionary', async ({umbracoApi}) => {
// Arrange
dictionaryId = await umbracoApi.dictionary.create(dictionaryName);
await expect(umbracoApi.dictionary.doesExist(dictionaryId)).toBeTruthy();
expect(await umbracoApi.dictionary.doesExist(dictionaryId)).toBeTruthy();

// Act
const exportResponse = await umbracoApi.dictionary.export(dictionaryId, false);

// Assert
// Checks if the .udt file is exported
await expect(exportResponse.headers()['content-disposition']).toContain(".udt");
expect(exportResponse.headers()['content-disposition']).toContain(".udt");
});

test('can import a dictionary', async ({umbracoApi}) => {
Expand All @@ -96,22 +89,16 @@ test.describe('Dictionary tests', () => {
// This variable must not be changed as it is declared in the file TestDictionary.udt
const importDictionaryName = 'TestImportDictionary';

// Create a dictionary
dictionaryId = await umbracoApi.dictionary.create(dictionaryName);
await expect(umbracoApi.dictionary.doesExist(dictionaryId)).toBeTruthy();

// Create temporary file
await umbracoApi.temporaryFile.create(temporaryFileId, fileName, mimeType, filePath);
await expect(await umbracoApi.temporaryFile.exists(temporaryFileId)).toBeTruthy();
expect(await umbracoApi.temporaryFile.doesExist(temporaryFileId)).toBeTruthy();

// Act
const importResponse = await umbracoApi.dictionary.import(temporaryFileId, dictionaryId);
const importResponse = await umbracoApi.dictionary.import(temporaryFileId, null);

// Assert
await expect(importResponse.ok()).toBeTruthy();
// Checks if the parent dictionary contains the import dictionary
const dictionaryChildren = await umbracoApi.dictionary.getChildren(dictionaryId);
await expect(dictionaryChildren[0].name).toEqual(importDictionaryName);
expect(importResponse.status).toBeTruthy();
expect(await umbracoApi.dictionary.doesNameExist(importDictionaryName)).toBeTruthy();

// Clean
await umbracoApi.temporaryFile.delete(temporaryFileId);
Expand Down
Expand Up @@ -5,22 +5,22 @@ test.describe('Language tests', () => {
const languageNameDanish = 'Dansk';
const isoCodeDanish = 'da-DK';

test.beforeEach(async ({page, umbracoApi}) => {
test.beforeEach(async ({umbracoApi}) => {
await umbracoApi.language.delete(isoCodeDanish);
});

test.afterEach(async ({page, umbracoApi}) => {
test.afterEach(async ({umbracoApi}) => {
await umbracoApi.language.delete(isoCodeDanish);
});

test('can create a language', async ({page, umbracoApi, umbracoUi}) => {
test('can create a language', async ({umbracoApi}) => {
await umbracoApi.language.create(languageNameDanish, false, false, isoCodeDanish);

// Assert
await expect(await umbracoApi.language.doesExist(isoCodeDanish)).toBeTruthy();
expect(await umbracoApi.language.doesExist(isoCodeDanish)).toBeTruthy();
});

test('can update a language', async ({page, umbracoApi, umbracoUi}) => {
test('can update a language', async ({umbracoApi}) => {
const wrongLanguageName = 'densk';

await umbracoApi.language.create(wrongLanguageName, false, false, isoCodeDanish);
Expand All @@ -32,20 +32,20 @@ test.describe('Language tests', () => {
await umbracoApi.language.update(isoCodeDanish, language);

// Assert
await expect(await umbracoApi.language.doesExist(isoCodeDanish)).toBeTruthy();
expect(await umbracoApi.language.doesExist(isoCodeDanish)).toBeTruthy();
// Checks if the language name was updated
const updatedLanguage = await umbracoApi.language.get(isoCodeDanish);
await expect(updatedLanguage.name).toEqual(languageNameDanish);
expect(updatedLanguage.name).toEqual(languageNameDanish);
});

test('can delete a language', async ({page, umbracoApi, umbracoUi}) => {
test('can delete a language', async ({umbracoApi}) => {
await umbracoApi.language.create(languageNameDanish, false, false, isoCodeDanish);

await expect(await umbracoApi.language.doesExist(isoCodeDanish)).toBeTruthy();
expect(await umbracoApi.language.doesExist(isoCodeDanish)).toBeTruthy();

await umbracoApi.language.delete(isoCodeDanish);

// Assert
await expect(await umbracoApi.language.doesExist(isoCodeDanish)).toBeFalsy();
expect(await umbracoApi.language.doesExist(isoCodeDanish)).toBeFalsy();
});
});
Expand Up @@ -16,15 +16,17 @@ test.describe('Relation type tests', () => {
await umbracoApi.relationType.ensureNameNotExists(relationTypeName);
});

test('can create a relation type', async ({umbracoApi}) => {
// Skip this test because there is currently no endpoint available for creating a relation type anymore.
test.skip('can create a relation type', async ({umbracoApi}) => {
// Act
relationTypeId = await umbracoApi.relationType.create(relationTypeName, false, false, objectTypeId, objectTypeId);

// Assert
expect(await umbracoApi.relationType.doesExist(relationTypeId)).toBeTruthy();
});

test('can update a relation type', async ({umbracoApi}) => {
// Skip this test because there is currently no endpoint available for updating a relation type anymore.
test.skip('can update a relation type', async ({umbracoApi}) => {
// Arrange
const wrongRelationTypeName = 'Updated Relation Type';
relationTypeId = await umbracoApi.relationType.create(wrongRelationTypeName, false, false, objectTypeId, objectTypeId);
Expand All @@ -41,7 +43,8 @@ test.describe('Relation type tests', () => {
expect(updatedRelationType.name).toEqual(relationTypeName);
});

test('can delete a relation type', async ({umbracoApi}) => {
// Skip this test because there is currently no endpoint available for deleting a relation type anymore.
test.skip('can delete a relation type', async ({umbracoApi}) => {
// Arrange
relationTypeId = await umbracoApi.relationType.create(relationTypeName, false, false, objectTypeId, objectTypeId);
expect(await umbracoApi.relationType.doesExist(relationTypeId)).toBeTruthy();
Expand Down
Expand Up @@ -39,7 +39,7 @@ test.describe('Script tests', () => {

test('can update script content', async ({umbracoApi}) => {
// Arrange
const newContent = 'Howdy';
const newContent = 'BetterContent';
scriptPath = await umbracoApi.script.create(scriptName, 'test');
await umbracoApi.script.get(scriptPath);

Expand Down
Expand Up @@ -2,7 +2,7 @@
import {expect} from "@playwright/test";

test.describe('Template tests', () => {
let templateId;
let templateId = '';
const templateName = 'TemplateTester';
const templateAlias = AliasHelper.toAlias(templateName);

Expand All @@ -19,7 +19,7 @@ test.describe('Template tests', () => {
templateId = await umbracoApi.template.create(templateName, templateAlias, 'Template Stuff');

// Assert
expect(umbracoApi.template.doesExist(templateId)).toBeTruthy();
expect(await umbracoApi.template.doesExist(templateId)).toBeTruthy();
});

test('can update a template', async ({umbracoApi}) => {
Expand All @@ -34,7 +34,7 @@ test.describe('Template tests', () => {
await umbracoApi.template.update(templateId, templateData);

// Assert
expect(umbracoApi.template.doesExist(templateId)).toBeTruthy();
expect(await umbracoApi.template.doesExist(templateId)).toBeTruthy();
// Checks if the template alias was updated
const updatedTemplate = await umbracoApi.template.get(templateId);
expect(updatedTemplate.alias).toEqual(newTemplateAlias);
Expand All @@ -43,7 +43,7 @@ test.describe('Template tests', () => {
test('can delete template', async ({umbracoApi}) => {
// Arrange
templateId = await umbracoApi.template.create(templateName, templateAlias, 'More Template Stuff');
expect(umbracoApi.template.doesExist(templateId)).toBeTruthy();
expect(await umbracoApi.template.doesExist(templateId)).toBeTruthy();

// Act
await umbracoApi.template.delete(templateId);
Expand Down
Expand Up @@ -21,7 +21,7 @@ test.describe('Temporary File tests', () => {
await umbracoApi.temporaryFile.create(temporaryFileId, fileName, mimeType, filePath);

// Assert
expect(await umbracoApi.temporaryFile.exists(temporaryFileId)).toBeTruthy();
expect(await umbracoApi.temporaryFile.doesExist(temporaryFileId)).toBeTruthy();
});

test('can delete temporary file', async ({umbracoApi}) => {
Expand All @@ -33,6 +33,6 @@ test.describe('Temporary File tests', () => {
await umbracoApi.temporaryFile.delete(temporaryFileId);

// Assert
expect(await umbracoApi.temporaryFile.exists(temporaryFileId)).toBeFalsy();
expect(await umbracoApi.temporaryFile.doesExist(temporaryFileId)).toBeFalsy();
});
});

0 comments on commit be58f31

Please sign in to comment.