device, devices: Print the fleet's slug in 'org/fleetName' format

Change-type: major
This commit is contained in:
Paulo Castro 2021-12-20 01:13:50 +00:00
parent 1164388d78
commit 9145f2fb28
8 changed files with 18 additions and 17 deletions

View File

@ -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',

View File

@ -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',

View File

@ -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' },
},

View File

@ -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,

View File

@ -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.

View File

@ -4,6 +4,7 @@
"belongs_to__application": [
{
"app_name": "test app",
"slug": "org/test app",
"__metadata": {}
}
],

View File

@ -4,6 +4,7 @@
"belongs_to__application": [
{
"app_name": "test app",
"slug": "org/test app",
"__metadata": {}
}
],

View File

@ -4,6 +4,7 @@
"belongs_to__application": [
{
"app_name": "test app",
"slug": "org/test app",
"__metadata": {}
}
],