Skip to content

Commit

Permalink
fix(meta fragment): include optional name (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
easen-amp authored Oct 27, 2023

Verified

This commit was signed with the committer’s verified signature.
stmcginnis Sean McGinnis
1 parent 84fef32 commit 2056d2d
Showing 6 changed files with 61 additions and 14 deletions.
7 changes: 5 additions & 2 deletions src/lib/content/mapper/ContentMapper.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { expect } from 'chai';
import { ContentMapper } from './ContentMapper';
import { ContentMeta, ContentReferenceMeta } from '../model/ContentMeta';
import { ContentMeta } from '../model/ContentMeta';
import { Image } from '../../media/Image';
import { Video } from '../../media/Video';
import { ContentReference } from '../model/ContentReference';
import {
ContentReference,
ContentReferenceMeta,
} from '../model/ContentReference';
import { CommonContentClientConfig } from '../../config/CommonContentClientConfig';

const config: CommonContentClientConfig = {};
9 changes: 0 additions & 9 deletions src/lib/content/model/ContentMeta.ts
Original file line number Diff line number Diff line change
@@ -3,15 +3,6 @@ import { ContentLifecycle } from './ContentLifecycle';
import { FragmentMeta } from './FragmentMeta';
import { Hierarchy } from './Hierarchy';

/**
* Class providing meta data about an Content Reference resource.
*/
export class ContentReferenceMeta extends FragmentMeta {
constructor(data?: any) {
super(data);
}
}

export interface IContentMeta {
/**
* Metadata related to the edition that published this content item. If the content was not published using
15 changes: 15 additions & 0 deletions src/lib/content/model/ContentReference.spec.ts
Original file line number Diff line number Diff line change
@@ -29,5 +29,20 @@ describe('Content Reference', () => {
const content = new ContentReference(json);
expect(content.toJSON()).to.deep.eq(json);
});

it('should attach _meta.name if present', () => {
const json = {
_meta: {
name: 'Optional',
schema:
'http://bigcontent.io/cms/schema/v1/core#/definitions/content-reference',
},
id: 'ddf4eac9-7822-401c-97d6-b1be985e421c',
contentType: 'http://some-content-type.com/type.json',
};

const content = new ContentReference(json);
expect(content.toJSON()).to.deep.eq(json);
});
});
});
12 changes: 10 additions & 2 deletions src/lib/content/model/ContentReference.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { FragmentMeta } from './FragmentMeta';
import { ContentReferenceMeta } from './ContentMeta';

/**
* Required params for creating an content reference
*/
@@ -14,6 +12,16 @@ export type RequiredContentReference<
};
};

/**
* Class providing meta data about an Content Reference resource.
* @deprecated use FragmentMeta
*/
export class ContentReferenceMeta extends FragmentMeta {
constructor(data?: any) {
super(data);
}
}

/**
* Class representing an Content Reference.
*/
14 changes: 14 additions & 0 deletions src/lib/content/model/FragmentMeta.spec.ts
Original file line number Diff line number Diff line change
@@ -25,6 +25,20 @@ describe('FragmentMeta', () => {
'http://bigcontent.io/cms/schema/v1/core#/definitions/image-link',
});
});

it('should attach name if present', () => {
const meta = new FragmentMeta({
name: 'Optional',
schema:
'http://bigcontent.io/cms/schema/v1/core#/definitions/image-link',
});

expect(JSON.parse(JSON.stringify(meta))).to.deep.eq({
name: 'Optional',
schema:
'http://bigcontent.io/cms/schema/v1/core#/definitions/image-link',
});
});
});

context('isFragment', () => {
18 changes: 17 additions & 1 deletion src/lib/content/model/FragmentMeta.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
interface IFragmentMeta {
schema: string;
name?: string;
}

/**
* @hidden
* Class providing meta data about a fragment of content with helper functions.
@@ -8,6 +13,11 @@ export class FragmentMeta {
*/
schema: string;

/**
* Name
*/
name?: string;

/**
* Creates a new FragmentMeta instance.
* @param data JSON representation of the FragmentMeta model
@@ -22,9 +32,15 @@ export class FragmentMeta {
* Export to JSON
*/
toJSON(): any {
return {
const result: IFragmentMeta = {
schema: this.schema,
};

if (this.name) {
result.name = this.name;
}

return result;
}

/**

0 comments on commit 2056d2d

Please sign in to comment.