Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
de15437
Cherry-pick V15 QA added delivery api helpers
andr317c Jun 11, 2025
bb71dcf
Removed this as it was split into two other files
nhudinh0309 Aug 29, 2025
b0aa6b4
Added api helper for media delivery API
nhudinh0309 Aug 29, 2025
b93447a
Added api helper for content delivery api
nhudinh0309 Aug 29, 2025
a02e593
Updated api helper for creating other kind of temporary files
nhudinh0309 Aug 29, 2025
0b5d240
Added isAllowAsRoot into the function
nhudinh0309 Aug 29, 2025
33d3eaa
Refactor api helper for media
nhudinh0309 Aug 29, 2025
0902887
Fixed api helper for document
nhudinh0309 Aug 29, 2025
e55979d
Imported api helpers
nhudinh0309 Aug 29, 2025
b51f0a4
Merge branch 'v16/dev' into v16/update/content-delivery-api-helper
nhudinh0309 Sep 3, 2025
218ff6a
Added api helper for content delivery api
nhudinh0309 Sep 5, 2025
50899d0
Merge branch 'v16/dev' into v16/update/content-delivery-api-helper
nhudinh0309 Sep 5, 2025
e017883
Merge branch 'v16/dev' into v16/update/content-delivery-api-helper
nhudinh0309 Sep 9, 2025
6c7d55b
Cleaned up
nhudinh0309 Sep 9, 2025
001bde2
Bumped version
nhudinh0309 Sep 9, 2025
3a09f59
Merge branch 'v16/dev' into v16/update/content-delivery-api-helper
nhudinh0309 Sep 9, 2025
b8dbd5e
Bumped version
nhudinh0309 Sep 9, 2025
4a31520
Updated api helper to add header to get request
nhudinh0309 Sep 10, 2025
be89c5b
Added api helper for content delivery api
nhudinh0309 Sep 10, 2025
4f6401f
Updated createDocumentWithTwoCulturesAndTextContent
nhudinh0309 Sep 10, 2025
86c465e
Merge branch 'v16/dev' into v16/update/content-delivery-api-with-loca…
nhudinh0309 Sep 10, 2025
dd086d2
Updated api helper for document to create variant document with varia…
nhudinh0309 Sep 17, 2025
13de153
Merge branch 'v16/dev' into v16/update/content-delivery-api-with-loca…
nhudinh0309 Sep 24, 2025
8418ba3
Added api helper for document to add textstring value to invariant d…
nhudinh0309 Sep 29, 2025
31ecde6
Updated api helper for content delivery api with property expansion
nhudinh0309 Sep 30, 2025
b1eb332
Merge branch 'v16/dev' into v16/update/content-delivery-api-with-loca…
nhudinh0309 Oct 2, 2025
0594bb4
Updated verifyEditorialPropertiesForInvariantContentItem
nhudinh0309 Oct 3, 2025
1919eec
Bumped version
nhudinh0309 Oct 3, 2025
03a05ed
Merge branch 'v16/dev' into v16/update/content-delivery-api-helper-2
nhudinh0309 Oct 7, 2025
da79b99
Bumped version
nhudinh0309 Oct 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/helpers/ApiHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@ export class ApiHelpers {
}
}

async get(url: string, params?: { [key: string]: string | number | boolean; }) {
async get(url: string, params?: { [key: string]: string | number | boolean; }, extraHeaders?: { [key: string]: string; }) {
const headers = await this.getHeaders();
const allHeaders = { ...headers, ...extraHeaders };
const options = {
headers: await this.getHeaders(),
headers: allHeaders,
params: params,
ignoreHTTPSErrors: true
}
Expand Down
55 changes: 52 additions & 3 deletions lib/helpers/DocumentApiHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,7 @@ export class DocumentApiHelper {
return false;
}

async createDocumentWithTwoCulturesAndTextContent(documentName: string, documentTypeId: string, textContent: string, dataTypeName: string, firstCulture: string, secondCulture: string) {
async createDocumentWithTwoCulturesAndTextContent(documentName: string, documentTypeId: string, textContent: string, dataTypeName: string, firstCulture: string, secondCulture: string, firstDomainName: string = '/testfirstdomain', secondDomainName: string = '/testseconddomain') {
await this.ensureNameNotExists(documentName);

const document = new DocumentBuilder()
Expand All @@ -1513,11 +1513,11 @@ export class DocumentApiHelper {

const domainData = new DocumentDomainBuilder()
.addDomain()
.withDomainName('/testfirstdomain')
.withDomainName(firstDomainName)
.withIsoCode(firstCulture)
.done()
.addDomain()
.withDomainName('/testseconddomain')
.withDomainName(secondDomainName)
.withIsoCode(secondCulture)
.done()
.build();
Expand Down Expand Up @@ -1589,4 +1589,53 @@ export class DocumentApiHelper {
// Create document
return await this.create(document);
}

async createVariantDocumentWithVariantProperty(documentName: string, documentTypeId: string, dataTypeName: string, propertyVariants: {culture: string, value}[]) {
await this.ensureNameNotExists(documentName);

const documentDataBuilder = new DocumentBuilder()
.withDocumentTypeId(documentTypeId);

for (const property of propertyVariants) {
documentDataBuilder
.addVariant()
.withName(property.culture === 'en-US' ? documentName : documentName + ' - ' + property.culture)
.withCulture(property.culture)
.done()
.addValue()
.withAlias(AliasHelper.toAlias(dataTypeName))
.withValue(property.value)
.withCulture(property.culture)
.done();
}
const document = documentDataBuilder.build();

return await this.create(document);
}

async updateDomainsForVariantDocument(documentId: string, domains: {domainName: string, isoCode: string}[]) {
const domainDataBuilder = new DocumentDomainBuilder();
for (const domain of domains) {
domainDataBuilder.addDomain()
.withDomainName(domain.domainName)
.withIsoCode(domain.isoCode)
.done();
}
const domainData = domainDataBuilder.build();
return await this.updateDomains(documentId, domainData);
}

async addTextstringValueToInvariantDocument(documentId: string, dataTypeName: string, textValue: string) {
const documentData = await this.get(documentId);
const textValueAlias = AliasHelper.toAlias(dataTypeName);
documentData.values.push({
alias: textValueAlias,
value: textValue,
culture: null,
segment: null,
editorAlias: 'Umbraco.Textbox',
entityType: 'document-property-value'
});
return await this.update(documentId, documentData);
}
}
65 changes: 48 additions & 17 deletions lib/helpers/differentAppSettingsHelpers/ContentDeliveryApiHelper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expect} from "@playwright/test";
import {expect} from "@playwright/test";
import {ApiHelpers} from "../ApiHelpers";

export class ContentDeliveryApiHelper {
Expand All @@ -13,23 +13,34 @@ export class ContentDeliveryApiHelper {
return await response.json();
}

async getContentItemWithId(id: string) {
return await this.api.get(this.api.baseUrl + '/umbraco/delivery/api/v2/content/item/' + id);
async getContentItemWithId(id: string, extraHeaders?: { [key: string]: string; }, expand?: string, fields?: string) {
if (expand || fields) {
let query = '?';
if (expand) {
query += 'expand=' + expand;
}
if (fields) {
query += (query.length > 1 ? '&' : '') + 'fields=' + fields;
}
return await this.api.get(this.api.baseUrl + '/umbraco/delivery/api/v2/content/item/' + id + query, undefined, extraHeaders);
} else {
return await this.api.get(this.api.baseUrl + '/umbraco/delivery/api/v2/content/item/' + id, undefined, extraHeaders);
}
}

async getContentItemWithRoute(route: string) {
return await this.api.get(this.api.baseUrl + '/umbraco/delivery/api/v2/content/item' + route);
async getContentItemWithRoute(route: string, extraHeaders?: { [key: string]: string; }) {
return await this.api.get(this.api.baseUrl + '/umbraco/delivery/api/v2/content/item' + route, undefined, extraHeaders);
}

async getContentItemsWithIds(ids: string[]) {
async getContentItemsWithIds(ids: string[], extraHeaders?: { [key: string]: string; }) {
let query = '?';
for (let i = 0; i < ids.length; i++) {
query += 'id=' + ids[i] + (i < ids.length - 1 ? '&' : '');
}
return await this.api.get(this.api.baseUrl + '/umbraco/delivery/api/v2/content/items' + query);
return await this.api.get(this.api.baseUrl + '/umbraco/delivery/api/v2/content/items' + query, undefined, extraHeaders);
}

async getContentItemsFromAQuery(fetch?: string, filter?: string, sort?: string, skip?: number, take?: number) {
async getContentItemsFromAQuery(extraHeaders?: { [key: string]: string; }, fetch?: string, filter?: string, sort?: string, skip?: number, take?: number) {
let query = '';
if (fetch) {
query += ' fetch=' + fetch;
Expand All @@ -50,7 +61,7 @@ export class ContentDeliveryApiHelper {
query = '?' + query.trim().replace(' ', '&');
}

return await this.api.get(this.api.baseUrl + '/umbraco/delivery/api/v2/content' + query);
return await this.api.get(this.api.baseUrl + '/umbraco/delivery/api/v2/content' + query, undefined, extraHeaders);
}

async verifyBasicPropertiesForContentItem(contentName: string, contentItemJson) {
Expand All @@ -63,22 +74,27 @@ export class ContentDeliveryApiHelper {
expect(contentItemJson.id).toBe(contentData.id);
const contentTypeData = await this.api.documentType.get(contentData.documentType.id);
expect(contentItemJson.contentType).toBe(contentTypeData.alias);
}

async verifyRoutePropertyForContentItem(contentName: string, contentItemJson, expectedRoutePath?: string) {
// Verify route property
const contentUrl = await this.api.document.getDocumentUrl(contentData.id);
expect(contentItemJson.route.path).toBe(contentUrl);
if (expectedRoutePath !== undefined) {
expect(contentItemJson.route.path).toBe(expectedRoutePath);
} else {
const contentData = await this.api.document.getByName(contentName);
const contentUrl = await this.api.document.getDocumentUrl(contentData.id);
expect(contentItemJson.route.path).toBe(contentUrl);
}
}

async verifyEditorialPropertiesForContentItem(contentName: string, contentItemJson, isVariesByCulture: boolean = false) {
async verifyEditorialPropertiesForInvariantContentItem(contentName: string, contentItemJson) {
const contentData = await this.api.document.getByName(contentName);
let expectedProperties = {};

if (!isVariesByCulture) {
for (const property of contentData.values) {
expectedProperties[property.alias] = property.value;
}
expect(contentItemJson.properties).toEqual(expectedProperties);
for (const property of contentData.values) {
expectedProperties[property.alias] = property.value;
}
expect(contentItemJson.properties).toEqual(expectedProperties);
}

async verifyCulturePropertyForContentItem(contentName: string, contentItemJson, isVariesByCulture: boolean = false) {
Expand All @@ -104,4 +120,19 @@ export class ContentDeliveryApiHelper {
expect(actualMultiUrlPickerValue[0].route.path).toBe(expectedMultiUrlPickerValue[0].url);
expect(actualMultiUrlPickerValue[0].linkType).toBe(pickerType);
}

async verifyPropertiesForMediaItem(mediaName: string, mediaItemJson) {
const mediaData = await this.api.media.getByName(mediaName);

expect(mediaItemJson.name).toBe(mediaName);
expect(mediaItemJson.focalPoint).toEqual(mediaData.values[0].value.focalPoint);
expect(mediaItemJson.crops).toEqual(mediaData.values[0].value.crops);
expect(mediaItemJson.id).toEqual(mediaData.id);
const expectedWidthValue = mediaData.values.find((p) => p.alias === 'umbracoWidth').value;
expect(mediaItemJson.width).toEqual(Number(expectedWidthValue));
const expectedHeightValue = mediaData.values.find((p) => p.alias === 'umbracoHeight').value;
expect(mediaItemJson.height).toEqual(Number(expectedHeightValue));
const expectedBytesValue = mediaData.values.find((p) => p.alias === 'umbracoBytes').value;
expect(mediaItemJson.bytes).toEqual(Number(expectedBytesValue));
}
}
4 changes: 2 additions & 2 deletions 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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@umbraco/playwright-testhelpers",
"version": "16.0.50",
"version": "16.0.51",
"description": "Test helpers for making playwright tests for Umbraco solutions",
"main": "dist/lib/index.js",
"files": [
Expand Down