From 7a892f61d28f1c10ad198f3626bc12e5b0211958 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Wed, 3 Mar 2021 19:52:29 -0400 Subject: [PATCH] update shared objects among models - add optional defaultKey, defaultValue to meta data - move REST _links object to model shared - add _links collection to coupons --- tests/e2e/api/src/models/coupons/coupon.ts | 11 +++ .../src/models/products/abstract/common.ts | 8 +-- .../api/src/models/products/abstract/data.ts | 8 +-- .../api/src/models/products/shared/classes.ts | 56 --------------- .../e2e/api/src/models/products/variation.ts | 8 +-- tests/e2e/api/src/models/shared-types.ts | 70 +++++++++++++++++++ .../repositories/rest/coupons/transformer.ts | 1 + tests/e2e/api/src/repositories/rest/shared.ts | 7 ++ 8 files changed, 101 insertions(+), 68 deletions(-) diff --git a/tests/e2e/api/src/models/coupons/coupon.ts b/tests/e2e/api/src/models/coupons/coupon.ts index a0ee904de29..20e3f42ee9b 100644 --- a/tests/e2e/api/src/models/coupons/coupon.ts +++ b/tests/e2e/api/src/models/coupons/coupon.ts @@ -12,6 +12,7 @@ import { import { CouponUpdateParams, } from './shared'; +import { ObjectLinks } from '../shared-types'; /** * The parameters embedded in this generic can be used in the ModelRepository in order to give @@ -222,6 +223,16 @@ export class Coupon extends Model { */ public readonly usedBy: Array = []; + /** + * The coupon's links. + * + * @type {ReadonlyArray.} + */ + public readonly links: ObjectLinks = { + collection: [ { href: '' } ], + self: [ { href: '' } ], + }; + /** * Creates a new coupon instance with the given properties * diff --git a/tests/e2e/api/src/models/products/abstract/common.ts b/tests/e2e/api/src/models/products/abstract/common.ts index 88601fa6ad0..4f9833f8eab 100644 --- a/tests/e2e/api/src/models/products/abstract/common.ts +++ b/tests/e2e/api/src/models/products/abstract/common.ts @@ -3,9 +3,9 @@ import { ModelID } from '../../model'; import { CatalogVisibility, ProductTerm, - ProductLinks, ProductAttribute, } from '../shared'; +import { ObjectLinks } from '../../shared-types'; /** * The common parameters that all products can use in search. @@ -137,11 +137,11 @@ export abstract class AbstractProduct extends AbstractProductData { public readonly attributes: readonly ProductAttribute[] = []; /** - * The products links. + * The product's links. * - * @type {ReadonlyArray.} + * @type {ReadonlyArray.} */ - public readonly links: ProductLinks = { + public readonly links: ObjectLinks = { collection: [ { href: '' } ], self: [ { href: '' } ], }; diff --git a/tests/e2e/api/src/models/products/abstract/data.ts b/tests/e2e/api/src/models/products/abstract/data.ts index 0d1b83cb37e..e76c1c7d9d8 100644 --- a/tests/e2e/api/src/models/products/abstract/data.ts +++ b/tests/e2e/api/src/models/products/abstract/data.ts @@ -1,6 +1,6 @@ import { Model } from '../../model'; -import { MetaData, PostStatus } from '../../shared-types'; -import { ProductImage, ProductLinks } from '../shared'; +import { MetaData, PostStatus, ObjectLinks } from '../../shared-types'; +import { ProductImage } from '../shared'; /** * Base product data. @@ -93,9 +93,9 @@ export abstract class AbstractProductData extends Model { /** * The product data links. * - * @type {ReadonlyArray.} + * @type {ReadonlyArray.} */ - public readonly links: ProductLinks = { + public readonly links: ObjectLinks = { collection: [ { href: '' } ], self: [ { href: '' } ], }; diff --git a/tests/e2e/api/src/models/products/shared/classes.ts b/tests/e2e/api/src/models/products/shared/classes.ts index 7343c594352..c08e0a20b70 100644 --- a/tests/e2e/api/src/models/products/shared/classes.ts +++ b/tests/e2e/api/src/models/products/shared/classes.ts @@ -208,59 +208,3 @@ export class ProductImage { Object.assign( this, properties ); } } - -/** - * A product link item. - */ -class ProductLinkItem { - /** - * The options which are available for the attribute. - * - * @type {ReadonlyArray.} - */ - public readonly href: string = ''; - - /** - * Creates a new product link item. - * - * @param {Partial.} properties The properties to set. - */ - public constructor( properties?: Partial< ProductLinkItem > ) { - Object.assign( this, properties ); - } -} - -/** - * A product's links. - */ -export class ProductLinks { - /** - * The collection containing the product. - * - * @type {ReadonlyArray.} - */ - public readonly collection: readonly ProductLinkItem[] = []; - - /** - * Self referential link to the product. - * - * @type {ReadonlyArray.} - */ - public readonly self: readonly ProductLinkItem[] = []; - - /** - * The link to the parent. - * - * @type {ReadonlyArray.} - */ - public readonly up?: readonly ProductLinkItem[] = []; - - /** - * Creates a new product link list. - * - * @param {Partial.} properties The properties to set. - */ - public constructor( properties?: Partial< ProductLinks > ) { - Object.assign( this, properties ); - } -} diff --git a/tests/e2e/api/src/models/products/variation.ts b/tests/e2e/api/src/models/products/variation.ts index 78e8580c2fa..beb1bad8071 100644 --- a/tests/e2e/api/src/models/products/variation.ts +++ b/tests/e2e/api/src/models/products/variation.ts @@ -15,13 +15,13 @@ import { ProductPriceUpdateParams, ProductSalesTaxUpdateParams, ProductShippingUpdateParams, - ProductLinks, Taxability, ProductDownload, StockStatus, BackorderStatus, ProductDefaultAttribute, } from './shared'; +import { ObjectLinks } from '../shared-types'; import { CreatesChildModels, DeletesChildModels, @@ -149,11 +149,11 @@ export class ProductVariation extends AbstractProductData implements public readonly shippingClassId: number = 0; /** - * The variation links. + * The variation's links. * - * @type {ReadonlyArray.} + * @type {ReadonlyArray.} */ - public readonly links: ProductLinks = { + public readonly links: ObjectLinks = { collection: [ { href: '' } ], self: [ { href: '' } ], up: [ { href: '' } ], diff --git a/tests/e2e/api/src/models/shared-types.ts b/tests/e2e/api/src/models/shared-types.ts index 5f64fff0b72..d041f3c48c8 100644 --- a/tests/e2e/api/src/models/shared-types.ts +++ b/tests/e2e/api/src/models/shared-types.ts @@ -35,6 +35,20 @@ export class MetaData extends Model { */ public readonly value: any = ''; + /** + * The key of the metadata. + * + * @type {string} + */ + public readonly displayKey?: string = ''; + + /** + * The value of the metadata. + * + * @type {*} + */ + public readonly displayValue?: string = ''; + /** * Creates a new metadata. * @@ -45,3 +59,59 @@ export class MetaData extends Model { Object.assign( this, properties ); } } + +/** + * An object link item. + */ +class LinkItem { + /** + * The href of the link. + * + * @type {ReadonlyArray.} + */ + public readonly href: string = ''; + + /** + * Creates a new product link item. + * + * @param {Partial.} properties The properties to set. + */ + public constructor( properties?: Partial< LinkItem > ) { + Object.assign( this, properties ); + } +} + +/** + * An object's links. + */ +export class ObjectLinks { + /** + * The collection containing the object. + * + * @type {ReadonlyArray.} + */ + public readonly collection: readonly LinkItem[] = []; + + /** + * Self referential link to the object. + * + * @type {ReadonlyArray.} + */ + public readonly self: readonly LinkItem[] = []; + + /** + * The link to the parent object. + * + * @type {ReadonlyArray.} + */ + public readonly up?: readonly LinkItem[] = []; + + /** + * Creates a new product link list. + * + * @param {Partial.} properties The properties to set. + */ + public constructor( properties?: Partial< ObjectLinks > ) { + Object.assign( this, properties ); + } +} diff --git a/tests/e2e/api/src/repositories/rest/coupons/transformer.ts b/tests/e2e/api/src/repositories/rest/coupons/transformer.ts index b3827471242..8e0c7d85eb9 100644 --- a/tests/e2e/api/src/repositories/rest/coupons/transformer.ts +++ b/tests/e2e/api/src/repositories/rest/coupons/transformer.ts @@ -57,6 +57,7 @@ export function createCouponTransformer(): ModelTransformer< Coupon > { maximumAmount: 'maximum_amount', emailRestrictions: 'email_restrictions', usedBy: 'used_by', + links: '_links', }, ), ], diff --git a/tests/e2e/api/src/repositories/rest/shared.ts b/tests/e2e/api/src/repositories/rest/shared.ts index 1d52d73ec3d..3c4e976d177 100644 --- a/tests/e2e/api/src/repositories/rest/shared.ts +++ b/tests/e2e/api/src/repositories/rest/shared.ts @@ -16,6 +16,7 @@ import { CreateChildFn, ModelTransformer, IgnorePropertyTransformation, + KeyChangeTransformation, // @ts-ignore ModelParentID, } from '../../framework'; @@ -34,6 +35,12 @@ export function createMetaDataTransformer(): ModelTransformer< MetaData > { return new ModelTransformer( [ new IgnorePropertyTransformation( [ 'id' ] ), + new KeyChangeTransformation< MetaData >( + { + displayKey: 'display_key', + displayValue: 'display_value', + }, + ), ], ); }