@@ -17,7 +17,7 @@ import type {
1717 Space ,
1818} from '../../lib/export-types'
1919
20- type InstallTemplate = ( ) => Promise < EnvironmentTemplateInstallationProps >
20+ type InstallTemplate = ( versionsCount ?: number ) => Promise < EnvironmentTemplateInstallationProps >
2121
2222describe ( 'Environment template API' , ( ) => {
2323 const client = defaultClient
@@ -213,14 +213,26 @@ describe('Environment template API', () => {
213213 expect ( installation . sys . id ) . toBe ( installations [ 0 ] . sys . id )
214214 } )
215215
216- it ( 'gets all installations of an environment template for an environment' , async ( ) => {
217- const installation = await installTemplate ( )
216+ it ( 'gets all installations of an environment template for a given environment' , async ( ) => {
217+ const installation = await installTemplate ( 2 )
218218 const template = await client . getEnvironmentTemplate ( {
219219 organizationId : orgId ,
220220 environmentTemplateId : installation . sys . template . sys . id ,
221221 } )
222222
223223 const { items : installations } = await template . getInstallations ( )
224+ expect ( installations ) . toHaveLength ( 2 )
225+ expect ( installation . sys . id ) . toBe ( installations [ 0 ] . sys . id )
226+ } )
227+
228+ it ( 'gets only the latest installation of an environment template for a given environment' , async ( ) => {
229+ const installation = await installTemplate ( 2 )
230+ const template = await client . getEnvironmentTemplate ( {
231+ organizationId : orgId ,
232+ environmentTemplateId : installation . sys . template . sys . id ,
233+ } )
234+
235+ const { items : installations } = await template . getInstallations ( { latestOnly : true } )
224236 expect ( installations ) . toHaveLength ( 1 )
225237 expect ( installation . sys . id ) . toBe ( installations [ 0 ] . sys . id )
226238 } )
@@ -292,23 +304,41 @@ function createInstallTemplate({
292304 environment : Environment
293305 createDraftTemplate : ( ) => CreateEnvironmentTemplateProps
294306} ) : InstallTemplate {
295- return async ( ) => {
296- const template = await client . createEnvironmentTemplate ( orgId , createDraftTemplate ( ) )
297- const installation = await template . install ( {
298- spaceId : space . sys . id ,
299- environmentId : environment . sys . id ,
300- installation : {
301- version : template . sys . version ,
302- } ,
303- } )
304-
305- expect ( installation . sys . template . sys . id ) . toBe ( template . sys . id )
307+ return async ( versionsCount : number = 1 ) => {
308+ let template = await client . createEnvironmentTemplate ( orgId , createDraftTemplate ( ) )
309+ let installation = await installNewTemplateVersion ( client , space , environment , template )
310+
311+ for ( let version = 2 ; version <= versionsCount ; version ++ ) {
312+ template . name = `Updated name for version ${ version } `
313+ template = await template . update ( )
314+ installation = await installNewTemplateVersion ( client , space , environment , template )
315+ }
306316
307- await waitForPendingInstallation ( client , environment , template . sys . id )
308317 return installation
309318 }
310319}
311320
321+ async function installNewTemplateVersion (
322+ client : ClientAPI ,
323+ space : Space ,
324+ environment : Environment ,
325+ template : EnvironmentTemplate ,
326+ ) : Promise < EnvironmentTemplateInstallationProps > {
327+ const installation = await template . install ( {
328+ spaceId : space . sys . id ,
329+ environmentId : environment . sys . id ,
330+ installation : {
331+ version : template . sys . version ,
332+ } ,
333+ } )
334+
335+ expect ( installation . sys . template . sys . id ) . toBe ( template . sys . id )
336+
337+ await waitForPendingInstallation ( client , environment , template . sys . id )
338+
339+ return installation
340+ }
341+
312342async function enableSpace ( client : ClientAPI , space : Space ) : Promise < void > {
313343 const previousEnablements = await client . rawRequest ( {
314344 method : 'get' ,
0 commit comments