diff --git a/lib/commands/device/index.ts b/lib/commands/device/index.ts index 0c156112..b83abbfa 100644 --- a/lib/commands/device/index.ts +++ b/lib/commands/device/index.ts @@ -27,7 +27,7 @@ import type { Application, Release } from 'balena-sdk'; interface ExtendedDevice extends DeviceWithDeviceType { dashboard_url?: string; - application_name?: string; + fleet: string; // 'org/name' slug device_type?: string; commit?: string; last_seen?: string; @@ -114,8 +114,8 @@ export default class DeviceCmd extends Command { const belongsToApplication = device.belongs_to__application as Application[]; - device.application_name = belongsToApplication?.[0] - ? belongsToApplication[0].app_name + device.fleet = belongsToApplication?.[0] + ? belongsToApplication[0].slug : 'N/a'; device.device_type = device.is_of__device_type[0].slug; @@ -173,7 +173,7 @@ export default class DeviceCmd extends Command { 'ip_address', 'public_address', 'mac_address', - 'application_name => FLEET', + 'fleet', 'last_seen', 'uuid', 'commit', diff --git a/lib/commands/devices/index.ts b/lib/commands/devices/index.ts index 912bdf6c..48ba81cb 100644 --- a/lib/commands/devices/index.ts +++ b/lib/commands/devices/index.ts @@ -26,7 +26,7 @@ import type { Application } from 'balena-sdk'; interface ExtendedDevice extends DeviceWithDeviceType { dashboard_url?: string; - application_name?: string | null; + fleet?: string | null; // 'org/name' slug device_type?: string | null; } @@ -91,7 +91,7 @@ export default class DevicesCmd extends Command { const belongsToApplication = device.belongs_to__application as Application[]; - device.application_name = belongsToApplication?.[0]?.app_name || null; + device.fleet = belongsToApplication?.[0]?.slug || null; device.uuid = options.json ? device.uuid : device.uuid.slice(0, 7); @@ -104,9 +104,7 @@ export default class DevicesCmd extends Command { 'uuid', 'device_name', 'device_type', - options.json - ? `application_name => fleet_name` - : `application_name => FLEET`, + 'fleet', 'status', 'is_online', 'supervisor_version', diff --git a/lib/utils/helpers.ts b/lib/utils/helpers.ts index 9a459214..8cf35e9b 100644 --- a/lib/utils/helpers.ts +++ b/lib/utils/helpers.ts @@ -428,7 +428,7 @@ export function getProxyConfig(): ProxyConfig | undefined { export const expandForAppName = { $expand: { - belongs_to__application: { $select: 'app_name' }, + belongs_to__application: { $select: ['app_name', 'slug'] as any }, is_of__device_type: { $select: 'slug' }, is_running__release: { $select: 'commit' }, }, diff --git a/tests/commands/device/device.spec.ts b/tests/commands/device/device.spec.ts index 715d22e1..752a7437 100644 --- a/tests/commands/device/device.spec.ts +++ b/tests/commands/device/device.spec.ts @@ -47,7 +47,7 @@ describe('balena device', function () { it('should list device details for provided uuid', async () => { api.scope .get( - /^\/v6\/device\?.+&\$expand=belongs_to__application\(\$select=app_name\)/, + /^\/v6\/device\?.+&\$expand=belongs_to__application\(\$select=app_name,slug\)/, ) .replyWithFile(200, path.join(apiResponsePath, 'device.json'), { 'Content-Type': 'application/json', @@ -59,13 +59,13 @@ describe('balena device', function () { expect(lines).to.have.lengthOf(25); expect(lines[0]).to.equal('== SPARKLING WOOD'); - expect(lines[6].split(':')[1].trim()).to.equal('test app'); + expect(lines[6].split(':')[1].trim()).to.equal('org/test app'); }); it.skip('correctly handles devices with missing fields', async () => { api.scope .get( - /^\/v6\/device\?.+&\$expand=belongs_to__application\(\$select=app_name\)/, + /^\/v6\/device\?.+&\$expand=belongs_to__application\(\$select=app_name,slug\)/, ) .replyWithFile( 200, @@ -81,7 +81,7 @@ describe('balena device', function () { expect(lines).to.have.lengthOf(14); expect(lines[0]).to.equal('== SPARKLING WOOD'); - expect(lines[6].split(':')[1].trim()).to.equal('test app'); + expect(lines[6].split(':')[1].trim()).to.equal('org/test app'); }); it('correctly handles devices with missing application', async () => { @@ -89,7 +89,7 @@ describe('balena device', function () { // e.g. When user has a device associated with app that user is no longer a collaborator of. api.scope .get( - /^\/v6\/device\?.+&\$expand=belongs_to__application\(\$select=app_name\)/, + /^\/v6\/device\?.+&\$expand=belongs_to__application\(\$select=app_name,slug\)/, ) .replyWithFile( 200, diff --git a/tests/commands/device/devices.spec.ts b/tests/commands/device/devices.spec.ts index 6d4b1929..39d57946 100644 --- a/tests/commands/device/devices.spec.ts +++ b/tests/commands/device/devices.spec.ts @@ -38,7 +38,7 @@ describe('balena devices', function () { it('should list devices from own and collaborator apps', async () => { api.scope .get( - '/v6/device?$orderby=device_name%20asc&$expand=belongs_to__application($select=app_name),is_of__device_type($select=slug),is_running__release($select=commit)', + '/v6/device?$orderby=device_name%20asc&$expand=belongs_to__application($select=app_name,slug),is_of__device_type($select=slug),is_running__release($select=commit)', ) .replyWithFile(200, path.join(apiResponsePath, 'devices.json'), { 'Content-Type': 'application/json', @@ -53,7 +53,7 @@ describe('balena devices', function () { ); expect(lines).to.have.lengthOf.at.least(2); - expect(lines.some((l) => l.includes('test app'))).to.be.true; + expect(lines.some((l) => l.includes('org/test app'))).to.be.true; // Devices with missing applications will have application name set to `N/a`. // e.g. When user has a device associated with app that user is no longer a collaborator of. diff --git a/tests/test-data/api-response/device-missing-fields.json b/tests/test-data/api-response/device-missing-fields.json index 3a854491..db57d1a3 100644 --- a/tests/test-data/api-response/device-missing-fields.json +++ b/tests/test-data/api-response/device-missing-fields.json @@ -4,6 +4,7 @@ "belongs_to__application": [ { "app_name": "test app", + "slug": "org/test app", "__metadata": {} } ], diff --git a/tests/test-data/api-response/device.json b/tests/test-data/api-response/device.json index ca53aa1a..4a3deee4 100644 --- a/tests/test-data/api-response/device.json +++ b/tests/test-data/api-response/device.json @@ -4,6 +4,7 @@ "belongs_to__application": [ { "app_name": "test app", + "slug": "org/test app", "__metadata": {} } ], diff --git a/tests/test-data/api-response/devices.json b/tests/test-data/api-response/devices.json index 67605457..628b3afb 100644 --- a/tests/test-data/api-response/devices.json +++ b/tests/test-data/api-response/devices.json @@ -4,6 +4,7 @@ "belongs_to__application": [ { "app_name": "test app", + "slug": "org/test app", "__metadata": {} } ],