Skip to content

Commit a2198cd

Browse files
committed
feat(fota): allow ranges
1 parent 6da0131 commit a2198cd

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-6
lines changed

lambda/fota/getNextUpgrade.spec.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { FOTAJobTarget } from '@hello.nrfcloud.com/proto/hello'
2+
import assert from 'node:assert/strict'
3+
import { describe, it } from 'node:test'
4+
import { getNextUpgrade } from './getNextUpgrade.js'
5+
6+
void describe('getNextUpgrade()', () => {
7+
void it('should return the next upgrade based on a static version', () =>
8+
assert.deepEqual(
9+
getNextUpgrade(
10+
{
11+
'2.0.0': 'APP*1e29dfa3*v2.0.1',
12+
'2.0.1': 'APP*cd5412d9*v2.0.2',
13+
},
14+
{
15+
appVersion: '2.0.0',
16+
supportedFOTATypes: [FOTAJobTarget.application],
17+
mfwVersion: '1.3.6',
18+
},
19+
),
20+
{
21+
upgrade: {
22+
reportedVersion: '2.0.0',
23+
bundleId: 'APP*1e29dfa3*v2.0.1',
24+
target: FOTAJobTarget.application,
25+
},
26+
},
27+
))
28+
29+
void it('should return the next upgrade based on a range', () =>
30+
assert.deepEqual(
31+
getNextUpgrade(
32+
{
33+
'>=1.0.0': 'APP*1e29dfa3*v2.0.1',
34+
},
35+
{
36+
appVersion: '2.0.0',
37+
supportedFOTATypes: [FOTAJobTarget.application],
38+
mfwVersion: '1.3.6',
39+
},
40+
),
41+
{
42+
upgrade: {
43+
reportedVersion: '2.0.0',
44+
bundleId: 'APP*1e29dfa3*v2.0.1',
45+
target: FOTAJobTarget.application,
46+
},
47+
},
48+
))
49+
})

lambda/fota/getNextUpgrade.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { bundleIdToType, FOTAJobTarget } from '@hello.nrfcloud.com/proto/hello'
2+
import semver from 'semver'
23
import { type DeviceFirmwareDetails } from './getDeviceFirmwareDetails.js'
34
import { type PersistedJob } from './jobRepo.js'
45

@@ -75,7 +76,10 @@ export const getNextUpgrade = (
7576
upgrade: {
7677
reportedVersion,
7778
// There may no further upgrades defined
78-
bundleId: upgradePath[reportedVersion] ?? null,
79+
bundleId:
80+
Object.entries(upgradePath).find(([targetVersion]) =>
81+
semver.satisfies(reportedVersion, targetVersion),
82+
)?.[1] ?? null,
7983
target,
8084
},
8185
}

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
"@hello.nrfcloud.com/certificate-helpers": "1.0.0",
132132
"@hello.nrfcloud.com/lambda-helpers": "2.0.29",
133133
"@hello.nrfcloud.com/nrfcloud-api-helpers": "5.3.86",
134-
"@hello.nrfcloud.com/proto": "15.2.8",
134+
"@hello.nrfcloud.com/proto": "15.3.0",
135135
"@hello.nrfcloud.com/proto-map": "16.1.7",
136136
"@middy/core": "5.5.0",
137137
"@middy/input-output-logger": "5.5.0",

0 commit comments

Comments
 (0)