UNPKG

@umbraco/playwright-testhelpers

Version:

Test helpers for making playwright tests for Umbraco solutions

87 lines 3.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RelationTypeApiHelper = void 0; class RelationTypeApiHelper { api; constructor(api) { this.api = api; } async get(id) { const response = await this.api.get(this.api.baseUrl + '/umbraco/management/api/v1/relation-type/' + id); return await response.json(); } async doesExist(id) { const response = await this.api.get(this.api.baseUrl + '/umbraco/management/api/v1/relation-type/' + id); return response.status() === 200; } async create(name, isBidirectional, isDependency, parentObjectTypeId, childObjectTypeId, id) { const relationTypeData = { "name": name, "isBidirectional": isBidirectional, "parentObjectType": parentObjectTypeId, "childObjectType": childObjectTypeId, "isDependency": isDependency, "id": id }; const response = await this.api.post(this.api.baseUrl + '/umbraco/management/api/v1/relation-type', relationTypeData); // Returns the id of the created relationType return response.headers().location.split("/").pop(); } async update(id, relationType) { return await this.api.put(this.api.baseUrl + '/umbraco/management/api/v1/relation-type/' + id, relationType); } async delete(id) { return await this.api.delete(this.api.baseUrl + '/umbraco/management/api/v1/relation-type/' + id); } async getAllAtRoot() { return await this.api.get(this.api.baseUrl + '/umbraco/management/api/v1/tree/relation-type/root?skip=0&take=10000'); } async getItems(ids) { let idArray = 'id=' + ids[0]; let i; for (i = 1; i < ids.length; ++i) { idArray += '&id=' + ids[i]; } const response = await this.api.get(this.api.baseUrl + '/umbraco/management/api/v1/relation-type/item?' + idArray); const json = await response.json(); if (json !== null) { return json; } return null; } async ensureNameNotExists(name) { const rootRelationType = await this.getAllAtRoot(); const jsonRelationType = await rootRelationType.json(); for (const relationType of jsonRelationType.items) { if (relationType.name === name && relationType.id !== null) { return await this.api.delete(this.api.baseUrl + '/umbraco/management/api/v1/relation-type/' + relationType.id); } } return null; } async getByName(name) { const rootRelationType = await this.getAllAtRoot(); const jsonRelationType = await rootRelationType.json(); for (const relationType of jsonRelationType.items) { if (relationType.name === name && relationType.id !== null) { const response = await this.api.get(this.api.baseUrl + '/umbraco/management/api/v1/relation-type/' + relationType.id); return await response.json(); } } return null; } async doesNameExist(name) { const rootRelationType = await this.getAllAtRoot(); const jsonRelationType = await rootRelationType.json(); if (name !== null) { for (const relationType of jsonRelationType.items) { if (relationType.name === name) { return true; } } } return false; } } exports.RelationTypeApiHelper = RelationTypeApiHelper; //# sourceMappingURL=RelationTypeApiHelper.js.map