Skip to content

Commit 4a6cd96

Browse files
authored
Merge pull request #1431 from balena-io/application-create-uuid
application.create: Allow specifying the uuid of the new application
2 parents ea1f8a0 + 1b70afd commit 4a6cd96

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

DOCUMENTATION.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1828,7 +1828,8 @@ balena.models.application.hasAny().then(function(hasAny) {
18281828
| Param | Type | Description |
18291829
| --- | --- | --- |
18301830
| options | <code>Object</code> | application creation parameters |
1831-
| options.name | <code>String</code> | application names |
1831+
| options.name | <code>String</code> | application name |
1832+
| [options.uuid] | <code>String</code> | application uuid |
18321833
| [options.applicationType] | <code>String</code> | application type slug e.g. microservices |
18331834
| [options.applicationClass] | <code>String</code> | application class: 'app' | 'fleet' | 'block' |
18341835
| options.deviceType | <code>String</code> | device type slug |

src/models/application.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,8 @@ const getApplicationModel = function (
664664
* @memberof balena.models.application
665665
*
666666
* @param {Object} options - application creation parameters
667-
* @param {String} options.name - application names
667+
* @param {String} options.name - application name
668+
* @param {String} [options.uuid] - application uuid
668669
* @param {String} [options.applicationType] - application type slug e.g. microservices
669670
* @param {String} [options.applicationClass] - application class: 'app' | 'fleet' | 'block'
670671
* @param {String} options.deviceType - device type slug
@@ -691,13 +692,15 @@ const getApplicationModel = function (
691692
*/
692693
async create({
693694
name,
695+
uuid,
694696
applicationType,
695697
applicationClass,
696698
deviceType,
697699
parent,
698700
organization,
699701
}: {
700702
name: string;
703+
uuid?: string;
701704
/** @deprecated TODO: drop me in the next major */
702705
applicationType?: string;
703706
applicationClass?: 'app' | 'fleet' | 'block';
@@ -773,6 +776,7 @@ const getApplicationModel = function (
773776
]);
774777
const body: SubmitBody<Application> = {
775778
app_name: name,
779+
uuid,
776780
is_for__device_type: deviceTypeId,
777781
};
778782

tests/integration/models/application.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,22 @@ describe('Application Model', function () {
243243
});
244244
});
245245

246+
it('...should be able to create an application and specify a custom uuid', async function () {
247+
const uuid = balena.models.device.generateUniqueKey();
248+
const app = await balena.models.application.create({
249+
name: `${TEST_APPLICATION_NAME_PREFIX}_FooBarCustomUuid`,
250+
uuid,
251+
deviceType: 'raspberry-pi',
252+
organization: this.initialOrg.id,
253+
});
254+
expect(app).to.have.property('uuid', uuid);
255+
const apps = await balena.models.application.getAll(
256+
{},
257+
'directly_accessible',
258+
);
259+
expect(apps).to.have.length(appCount);
260+
});
261+
246262
it('...should be able to create an application with a specific application type', function () {
247263
return balena.models.application
248264
.create({

0 commit comments

Comments
 (0)