Skip to content

Commit 4f514ac

Browse files
committed
Fix PATCH /state/v3 not clearing the device's is_running__release
Change-type: patch
1 parent 4d20a01 commit 4f514ac

File tree

2 files changed

+109
-2
lines changed

2 files changed

+109
-2
lines changed

src/features/device-state/routes/state-patch-v3.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,14 @@ export const statePatchV3: RequestHandler = async (req, res) => {
327327

328328
if (apps != null) {
329329
const userAppUuid = device.belongs_to__application[0].uuid;
330-
if (releasesByAppUuid[userAppUuid] != null) {
330+
const userAppPayload = apps[userAppUuid];
331+
if (userAppPayload?.release_uuid == null) {
332+
// `apps: {}`: The device is not currently running any app.
333+
// absent `release_uuid`: The device is not currently running any release of the app.
334+
deviceBody.is_running__release = null;
335+
} else if (releasesByAppUuid[userAppUuid] != null) {
331336
const release = releasesByAppUuid[userAppUuid].find(
332-
(r) => r.commit === apps[userAppUuid].release_uuid,
337+
(r) => r.commit === userAppPayload.release_uuid,
333338
);
334339
if (release) {
335340
deviceBody.is_running__release = release.id;

test/03_device-state.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,108 @@ export default () => {
17991799
});
18001800
});
18011801
}
1802+
1803+
describe('Reporting no running release', () => {
1804+
beforeEach(async function () {
1805+
await fakeDevice.patchState(
1806+
device,
1807+
device.uuid,
1808+
{
1809+
[stateKey]:
1810+
stateVersion === 'v2'
1811+
? {
1812+
is_on__commit: release2.commit,
1813+
}
1814+
: {
1815+
apps: {
1816+
[applicationUuid]: {
1817+
release_uuid: release2.commit,
1818+
},
1819+
},
1820+
},
1821+
},
1822+
stateVersion,
1823+
);
1824+
1825+
await expectResourceToMatch(pineUser, 'device', device.id, {
1826+
is_running__release: { __id: release2.id },
1827+
});
1828+
});
1829+
});
1830+
1831+
it('should clear the current release when the device reports a null commit', async () => {
1832+
await fakeDevice.patchState(
1833+
device,
1834+
device.uuid,
1835+
{
1836+
[stateKey]:
1837+
stateVersion === 'v2'
1838+
? {
1839+
is_on__commit: null,
1840+
}
1841+
: {
1842+
apps: {
1843+
[applicationUuid]: {
1844+
release_uuid: null,
1845+
},
1846+
},
1847+
},
1848+
},
1849+
stateVersion,
1850+
);
1851+
1852+
await expectResourceToMatch(pineUser, 'device', device.id, {
1853+
is_running__release: null,
1854+
});
1855+
});
1856+
1857+
if (stateVersion === 'v3') {
1858+
it('should clear the current release when the device reports the currnet app w/o a release_uuid', async () => {
1859+
await fakeDevice.patchState(
1860+
device,
1861+
device.uuid,
1862+
{
1863+
[stateKey]: {
1864+
apps: {
1865+
[applicationUuid]: {
1866+
// This will be the case when first installing a release of an app until
1867+
// the release is fully installed. Eg device move or if the SV database is deleted
1868+
// *** release_uuid not included ***,
1869+
releases: {
1870+
[release2.commit]: {
1871+
update_status: 'downloading',
1872+
},
1873+
},
1874+
},
1875+
},
1876+
},
1877+
},
1878+
stateVersion,
1879+
);
1880+
1881+
await expectResourceToMatch(pineUser, 'device', device.id, {
1882+
is_running__release: null,
1883+
});
1884+
});
1885+
1886+
it('should clear the current release when the device reports an empty current apps state', async () => {
1887+
await fakeDevice.patchState(
1888+
device,
1889+
device.uuid,
1890+
// running no release
1891+
{
1892+
[stateKey]: {
1893+
apps: {},
1894+
},
1895+
},
1896+
stateVersion,
1897+
);
1898+
1899+
await expectResourceToMatch(pineUser, 'device', device.id, {
1900+
is_running__release: null,
1901+
});
1902+
});
1903+
}
18021904
});
18031905
});
18041906
});

0 commit comments

Comments
 (0)