Skip to content

Commit ea0d57b

Browse files
committed
test: add templateId create/update tests and update plain client JSDoc [DX-982]
1 parent f135872 commit ea0d57b

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

lib/plain/entities/experience.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export type ExperiencePlainClientAPI = {
6060
* @internal - Experimental endpoint, subject to breaking changes without notice
6161
* @example
6262
* ```javascript
63+
* // Component-type-backed experience
6364
* const experience = await client.experience.create({
6465
* spaceId: '<space_id>',
6566
* environmentId: '<environment_id>',
@@ -72,6 +73,20 @@ export type ExperiencePlainClientAPI = {
7273
* designProperties: {},
7374
* dimensionKeyMap: { designProperties: {} },
7475
* });
76+
*
77+
* // Template-backed experience
78+
* const experience = await client.experience.create({
79+
* spaceId: '<space_id>',
80+
* environmentId: '<environment_id>',
81+
* }, {
82+
* name: 'My Template Experience',
83+
* description: 'A template-backed experience',
84+
* templateId: '<template_id>',
85+
* viewports: [],
86+
* contentProperties: {},
87+
* designProperties: {},
88+
* dimensionKeyMap: { designProperties: {} },
89+
* });
7590
* ```
7691
*/
7792
create(

test/unit/adapters/REST/endpoints/experience.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,55 @@ describe('Rest Experience', { concurrent: true }, () => {
251251
})
252252
})
253253

254+
test('create sends templateId when creating a template-backed experience', async () => {
255+
const mockResponse = {
256+
sys: { id: 'new-experience-456', type: 'Experience', version: 1 },
257+
name: 'Template Experience',
258+
description: 'A template-backed experience',
259+
viewports: [],
260+
contentProperties: {},
261+
designProperties: {},
262+
dimensionKeyMap: { designProperties: {} },
263+
}
264+
265+
const { httpMock, adapterMock } = setupRestAdapter(Promise.resolve({ data: mockResponse }))
266+
267+
return adapterMock
268+
.makeRequest({
269+
entityType: 'Experience',
270+
action: 'create',
271+
userAgent: 'mocked',
272+
params: {
273+
spaceId: 'space123',
274+
environmentId: 'master',
275+
},
276+
payload: {
277+
name: 'Template Experience',
278+
description: 'A template-backed experience',
279+
templateId: 'tmpl-789',
280+
viewports: [],
281+
contentProperties: {},
282+
designProperties: {},
283+
dimensionKeyMap: { designProperties: {} },
284+
},
285+
})
286+
.then((r) => {
287+
expect(r).to.eql(mockResponse)
288+
expect(httpMock.post.mock.calls[0][0]).to.eql(
289+
'/spaces/space123/environments/master/experiences',
290+
)
291+
expect(httpMock.post.mock.calls[0][1]).to.eql({
292+
name: 'Template Experience',
293+
description: 'A template-backed experience',
294+
templateId: 'tmpl-789',
295+
viewports: [],
296+
contentProperties: {},
297+
designProperties: {},
298+
dimensionKeyMap: { designProperties: {} },
299+
})
300+
})
301+
})
302+
254303
test('update calls correct URL with version header', async () => {
255304
const mockResponse = {
256305
sys: { id: 'experience123', type: 'Experience', version: 2 },

0 commit comments

Comments
 (0)