Skip to content

Commit cc5f7f1

Browse files
committed
feat: adds hub.related.contentItems.getByDeliveryKey() to lookup a content-item by its delivery key
1 parent 7660790 commit cc5f7f1

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

src/lib/DynamicContent.mocks.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ export const HUB = {
188188
href:
189189
'https://api.amplience.net/v2/content/hubs/5b32377e4cedfd01c45036d8/snapshots/batch',
190190
},
191+
'delivery-keys': {
192+
href:
193+
'https://api.amplience.net/v2/content/hubs/5b32377e4cedfd01c45036d8/delivery-keys?key={key}',
194+
templated: true,
195+
},
191196
},
192197
};
193198

@@ -303,6 +308,20 @@ export const CONTENT_ITEM = {
303308
export const CONTENT_ITEM_V2 = { ...CONTENT_ITEM };
304309
CONTENT_ITEM_V2.version++;
305310

311+
/**
312+
* @hidden
313+
*/
314+
export const CONTENT_ITEM_WITH_DELIVERY_KEY = {
315+
...CONTENT_ITEM,
316+
body: {
317+
_meta: {
318+
name: 'main-banner',
319+
schema: 'http://deliver.bigcontent.io/schema/nested/nested-type.json',
320+
deliveryKey: 'a-delivery-key',
321+
},
322+
},
323+
};
324+
306325
/**
307326
* @hidden
308327
*/
@@ -2655,12 +2674,18 @@ export class DynamicContentFixtures {
26552674
CONTENT_ITEMS_FACET
26562675
)
26572676
.nestedCreateResource('batch-create-snapshots', {}, SNAPSHOT_RESULTS);
2677+
26582678
hubMockResource.mocks.collection(
26592679
`${hubMockResource.resource._links['self'].href}/content-repositories/search/findByFeaturesContaining?feature=slots`,
26602680
'content-repositories',
26612681
[CONTENT_REPOSITORY_SLOTS]
26622682
);
26632683

2684+
hubMockResource.mocks.resource(
2685+
CONTENT_ITEM_WITH_DELIVERY_KEY,
2686+
`${hubMockResource.resource._links['self'].href}/delivery-keys/content-item?key=a-delivery-key`
2687+
);
2688+
26642689
// Content items
26652690
mocks
26662691
.resource(CONTENT_ITEM)

src/lib/model/Hub.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ test('facet the content items ', async (t) => {
115115
);
116116
});
117117

118+
test('get content item by its deliveryKey', async (t) => {
119+
const client = new MockDynamicContent();
120+
const hub = await client.hubs.get('5b32377e4cedfd01c45036d8');
121+
const result = await hub.related.contentItems.getByDeliveryKey(
122+
'a-delivery-key'
123+
);
124+
t.is(result.body._meta.deliveryKey, 'a-delivery-key');
125+
});
126+
118127
test('list events', async (t) => {
119128
const client = new MockDynamicContent();
120129
const hub = await client.hubs.get('5b32377e4cedfd01c45036d8');

src/lib/model/Hub.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { HalResource } from '../hal/models/HalResource';
2-
import { ContentItemsFacets, FacetedContentItem } from './ContentItem';
2+
import {
3+
ContentItem,
4+
ContentItemsFacets,
5+
FacetedContentItem,
6+
} from './ContentItem';
37
import {
48
ContentRepositoriesPage,
59
ContentRepository,
@@ -178,6 +182,12 @@ export class Hub extends HalResource {
178182
facetQuery,
179183
ContentItemsFacets
180184
),
185+
186+
getByDeliveryKey: (key: string): Promise<ContentItem> =>
187+
this.client.fetchResource(
188+
`hubs/${this.id}/delivery-keys/content-item?key=${key}`,
189+
ContentItem
190+
),
181191
},
182192

183193
editions: {

0 commit comments

Comments
 (0)