Skip to content

Commit 4f52ff4

Browse files
authored
Merge pull request #4280 from FlowFuse/locked-template-tests
Add locked field test
2 parents 628c562 + 9fa2f5a commit 4f52ff4

1 file changed

Lines changed: 94 additions & 0 deletions

File tree

test/unit/forge/ee/routes/api/pipeline_spec.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2754,4 +2754,98 @@ describe('Pipelines API', function () {
27542754
response.statusCode.should.equal(200)
27552755
})
27562756
})
2757+
2758+
describe('Locked template fields', function () {
2759+
async function isDeployComplete (instance) {
2760+
const instanceStatusResponse = (await app.inject({
2761+
method: 'GET',
2762+
url: `/api/v1/projects/${instance.id}`,
2763+
cookies: { sid: TestObjects.tokens.alice }
2764+
})).json()
2765+
2766+
return instanceStatusResponse?.meta?.isDeploying === false
2767+
}
2768+
function waitForDeployToComplete (instance) {
2769+
return new Promise((resolve, reject) => {
2770+
const refreshIntervalId = setInterval(async () => {
2771+
if (await isDeployComplete(instance)) {
2772+
clearInterval(refreshIntervalId)
2773+
resolve()
2774+
}
2775+
}, 250)
2776+
})
2777+
}
2778+
it('locked fields should not be overridden', async function () {
2779+
const startTemplate = await app.factory.createProjectTemplate(
2780+
{
2781+
name: 'startTemplate',
2782+
settings: {
2783+
palette: {
2784+
catalogue: ['https://www.first.com'],
2785+
npmrc: 'from start'
2786+
}
2787+
},
2788+
policy: {
2789+
palette: {
2790+
catalogue: true
2791+
}
2792+
}
2793+
},
2794+
app.user
2795+
)
2796+
2797+
const endTemplate = await app.factory.createProjectTemplate(
2798+
{
2799+
name: 'endTemplate',
2800+
settings: {
2801+
palette: {
2802+
catalogue: ['https://www.second.com', 'https://third.com'],
2803+
npmrc: 'from end'
2804+
}
2805+
},
2806+
policy: {
2807+
palette: {
2808+
catalogue: false
2809+
}
2810+
}
2811+
},
2812+
app.user
2813+
)
2814+
2815+
const instanceStart = await app.factory.createInstance(
2816+
{ name: 'startProject' },
2817+
TestObjects.application,
2818+
TestObjects.stack,
2819+
startTemplate,
2820+
TestObjects.projectType,
2821+
{ start: false }
2822+
)
2823+
const instanceEnd = await app.factory.createInstance(
2824+
{ name: 'endProject' },
2825+
TestObjects.application,
2826+
TestObjects.stack,
2827+
endTemplate,
2828+
TestObjects.projectType,
2829+
{ start: false }
2830+
)
2831+
2832+
const pipeline = await app.factory.createPipeline({ name: 'locked-fields-pipeine' }, app.application)
2833+
const startStage = await app.factory.createPipelineStage({ name: 'start', instanceId: instanceStart.id }, pipeline)
2834+
await app.factory.createPipelineStage({ name: 'end', source: startStage.hashid, instanceId: instanceEnd.id }, pipeline)
2835+
2836+
const response = await app.inject({
2837+
method: 'PUT',
2838+
url: `/api/v1/pipelines/${pipeline.hashid}/stages/${startStage.hashid}/deploy`,
2839+
cookies: { sid: TestObjects.tokens.alice }
2840+
})
2841+
2842+
response.statusCode.should.equal(200)
2843+
await waitForDeployToComplete(instanceEnd)
2844+
await instanceEnd.reload()
2845+
const endSettings = await app.db.controllers.Project.getRuntimeSettings(instanceEnd)
2846+
endSettings.palette.catalogue.should.have.lengthOf(2)
2847+
endSettings.palette.catalogue.should.containEql('https://www.second.com')
2848+
endSettings.palette.npmrc.should.equal('from start')
2849+
})
2850+
})
27572851
})

0 commit comments

Comments
 (0)