mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 21:57:51 +00:00
devices: add device_tag to JSON output
change-type: minor
This commit is contained in:
parent
801a25995c
commit
bd194e6b63
@ -71,7 +71,14 @@ export default class DevicesCmd extends Command {
|
||||
const balena = getBalenaSdk();
|
||||
const devicesOptions = {
|
||||
...devicesSelectFields,
|
||||
...expandForAppName,
|
||||
$expand: {
|
||||
...(options.json && {
|
||||
device_tag: {
|
||||
$select: ['tag_key', 'value'],
|
||||
},
|
||||
}),
|
||||
...expandForAppName.$expand,
|
||||
},
|
||||
$orderby: { device_name: 'asc' },
|
||||
} satisfies PineOptions<Device>;
|
||||
|
||||
@ -116,7 +123,9 @@ export default class DevicesCmd extends Command {
|
||||
|
||||
if (options.json) {
|
||||
const { pickAndRename } = await import('../../utils/helpers');
|
||||
const mapped = devices.map((device) => pickAndRename(device, fields));
|
||||
const mapped = devices.map((device) =>
|
||||
pickAndRename(device, [...fields, 'device_tag']),
|
||||
);
|
||||
console.log(JSON.stringify(mapped, null, 4));
|
||||
} else {
|
||||
const _ = await import('lodash');
|
||||
|
@ -59,4 +59,29 @@ describe('balena devices', function () {
|
||||
// e.g. When user has a device associated with app that user is no longer a collaborator of.
|
||||
expect(lines.some((l) => l.includes('N/a'))).to.be.true;
|
||||
});
|
||||
|
||||
it('should list devices from own and collaborator apps', async () => {
|
||||
api.scope
|
||||
.get(
|
||||
'/v6/device?$orderby=device_name%20asc&$select=id,uuid,device_name,status,is_online,supervisor_version,os_version&$expand=device_tag($select=tag_key,value),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',
|
||||
});
|
||||
|
||||
const { out, err } = await runCommand('devices --json');
|
||||
expect(err).to.be.empty;
|
||||
const json = JSON.parse(out.join(''));
|
||||
expect(json[0].device_name).to.equal('sparkling-wood');
|
||||
expect(json[0].device_tag[0]).to.deep.equal({
|
||||
tag_key: 'example',
|
||||
value: '0',
|
||||
});
|
||||
|
||||
expect(json[1].device_name).to.equal('dashing-spruce');
|
||||
expect(json[1].device_tag[0]).to.deep.equal({
|
||||
tag_key: 'example',
|
||||
value: '1',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -22,7 +22,13 @@
|
||||
"supervisor_version": "10.3.7",
|
||||
"__metadata": {
|
||||
"uri": "/resin/device(@id)?@id=1747415"
|
||||
}
|
||||
},
|
||||
"device_tag": [
|
||||
{
|
||||
"tag_key": "example",
|
||||
"value": "0"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"belongs_to__application": [],
|
||||
@ -41,7 +47,13 @@
|
||||
"supervisor_version": "10.3.7",
|
||||
"__metadata": {
|
||||
"uri": "/resin/device(@id)?@id=1747415"
|
||||
}
|
||||
},
|
||||
"device_tag": [
|
||||
{
|
||||
"tag_key": "example",
|
||||
"value": "1"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user